-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix canonical representations of
JSONPath
and JSONPathNode
- Loading branch information
Showing
11 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "test/cts"] | ||
path = test/cts | ||
url = [email protected]:jsonpath-standard/jsonpath-compliance-test-suite.git | ||
[submodule "test/nts"] | ||
path = test/nts | ||
url = [email protected]:jg-rp/jsonpath-compliance-normalized-paths.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
json_p3 (0.3.1) | ||
json_p3 (0.3.2) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ def singular? | |
end | ||
|
||
def to_s | ||
@name.inspect | ||
JSONP3.canonical_string(@name) | ||
end | ||
|
||
def ==(other) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module JSONP3 # rubocop:disable Style/Documentation | ||
TRANS = { "\\\"" => "\"", "'" => "\\'" }.freeze | ||
|
||
# Return _value_ formatted as a canonical string literal. | ||
# @param value [String] | ||
def self.canonical_string(value) | ||
"'#{(JSON.dump(value)[1..-2] || raise).gsub(/('|\\")/, TRANS)}'" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module JSONP3 | ||
VERSION = "0.3.1" | ||
VERSION = "0.3.2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
require "test_helper" | ||
|
||
class TestNormalizedPathTestSuite < Minitest::Spec | ||
make_my_diffs_pretty! | ||
|
||
nts = JSON.parse(File.read("test/nts/normalized_paths.json")) | ||
|
||
describe "normalized path test suite" do | ||
nts["tests"].each do |test_case| | ||
it test_case["name"] do | ||
nodes = JSONP3.find(test_case["query"], test_case["document"]) | ||
paths = nodes.map(&:path) | ||
_(paths).must_equal(test_case["paths"]) | ||
end | ||
end | ||
end | ||
end | ||
|
||
class TestCanonicalPathTestSuite < Minitest::Spec | ||
make_my_diffs_pretty! | ||
|
||
nts = JSON.parse(File.read("test/nts/canonical_paths.json")) | ||
|
||
describe "canonical path test suite" do | ||
nts["tests"].each do |test_case| | ||
it test_case["name"] do | ||
query = JSONP3.compile(test_case["query"]) | ||
path = query.to_s | ||
_(path).must_equal(test_case["canonical"]) | ||
end | ||
end | ||
end | ||
end |