From a0967af9ed2e0e5dfafb44d7d96542ee2f2a22f5 Mon Sep 17 00:00:00 2001 From: Scott McGowan Date: Sat, 22 Jan 2022 09:00:54 +0000 Subject: [PATCH 1/2] fix: set arch correctly during build --- .github/workflows/release-build.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release-build.yaml b/.github/workflows/release-build.yaml index 7c978f9..fd366e9 100644 --- a/.github/workflows/release-build.yaml +++ b/.github/workflows/release-build.yaml @@ -32,5 +32,4 @@ jobs: goversion: ${{ matrix.goversion }} project_path: "./cmd/" binary_name: "jsonpath" - ldflags: -X "main.Command=jsonpath" -X "main.Version=${{ env.RELEASE_TAG }}" -X "main.OS=${{ matrix.goos }}" -X "main.Arch=${{ matrix.goos }}" - + ldflags: -X "main.Command=jsonpath" -X "main.Version=${{ env.RELEASE_TAG }}" -X "main.OS=${{ matrix.goos }}" -X "main.Arch=${{ matrix.goarch }}" From 3b714dba717bb22825382b68651a8ff5a0c5d421 Mon Sep 17 00:00:00 2001 From: Scott McGowan Date: Sat, 22 Jan 2022 09:02:55 +0000 Subject: [PATCH 2/2] chore: auto generate consensus tests readme test readme is not generated when tests ran locally updatate consensus readme to show output in json format --- test/README.md | 369 ++++++------ test/array_test.go | 592 ++++++++++--------- test/bracket_test.go | 684 +++++++++++----------- test/dot_test.go | 733 ++++++++++++----------- test/filter_test.go | 1314 +++++++++++++++++++++--------------------- test/helper_test.go | 80 ++- test/misc_test.go | 148 +++-- test/union_test.go | 218 ++++--- 8 files changed, 2097 insertions(+), 2041 deletions(-) diff --git a/test/README.md b/test/README.md index c0fc643..8934774 100644 --- a/test/README.md +++ b/test/README.md @@ -1,21 +1,22 @@ # cburgmer tests This test package has tests detailed by https://cburgmer.github.io/json-path-comparison/ comparison matrix which details the community consensus on the expected response from multiple JSONPath queries - -This implementation would be closer to the `Scalar consensus` as it does not always return an array, but instead can return a single item when that is expected. + +This implementation would be closer to the 'Scalar consensus' as it does not always return an array, but instead can return a single item when that is expected. + ## Array Test |query|data|consensus|actual|match| |---|---|---|---|---| -|`$[1:3]`|`["first", "second", "third", "forth", "fifth"]`|`[second third]`|`[second third]`|:white_check_mark:| -|`$[0:5]`|`["first", "second", "third", "forth", "fifth"]`|`[first second third forth fifth]`|`[first second third forth fifth]`|:white_check_mark:| +|`$[1:3]`|`["first", "second", "third", "forth", "fifth"]`|`["second","third"]`|`["second","third"]`|:white_check_mark:| +|`$[0:5]`|`["first", "second", "third", "forth", "fifth"]`|`["first","second","third","forth","fifth"]`|`["first","second","third","forth","fifth"]`|:white_check_mark:| |`$[7:10]`|`["first", "second", "third"]`|`[]`|`[]`|:white_check_mark:| -|`$[1:3]`|`{":": 42, "more": "string", "a": 1, "b": 2, "c": 3, "1:3": "nice"}`|`nil`|`nil`|:white_check_mark:| -|`$[1:10]`|`["first", "second", "third"]`|`[second third]`|`[second third]`|:white_check_mark:| -|`$[2:113667776004]`|`["first", "second", "third", "forth", "fifth"]`|`[third forth fifth]`|`[third forth fifth]`|:white_check_mark:| +|`$[1:3]`|`{":": 42, "more": "string", "a": 1, "b": 2, "c": 3, "1:3": "nice"}`|`nil`|`null`|:white_check_mark:| +|`$[1:10]`|`["first", "second", "third"]`|`["second","third"]`|`["second","third"]`|:white_check_mark:| +|`$[2:113667776004]`|`["first", "second", "third", "forth", "fifth"]`|`["third","forth","fifth"]`|`["third","forth","fifth"]`|:white_check_mark:| |`$[2:-113667776004:-1]`|`["first", "second", "third", "forth", "fifth"]`|none|`[]`|:question:| -|`$[-113667776004:2]`|`["first", "second", "third", "forth", "fifth"]`|`[first second]`|`[first second]`|:white_check_mark:| +|`$[-113667776004:2]`|`["first", "second", "third", "forth", "fifth"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| |`$[113667776004:2:-1]`|`["first", "second", "third", "forth", "fifth"]`|`[]`|`[]`|:white_check_mark:| |`$[-4:-5]`|`[2, "a", 4, 5, 100, "nice"]`|`[]`|`[]`|:white_check_mark:| |`$[-4:-4]`|`[2, "a", 4, 5, 100, "nice"]`|`[]`|`[]`|:white_check_mark:| @@ -25,259 +26,257 @@ This implementation would be closer to the `Scalar consensus` as it does not alw |`$[-4:3]`|`[2, "a", 4, 5, 100, "nice"]`|`[4]`|`[4]`|:white_check_mark:| |`$[3:0:-2]`|`["first", "second", "third", "forth", "fifth"]`|`[]`|`[]`|:white_check_mark:| |`$[7:3:-1]`|`["first", "second", "third", "forth", "fifth"]`|`[]`|`[]`|:white_check_mark:| -|`$[0:3:-2]`|`["first", "second", "third", "forth", "fifth"]`|none|`[third first]`|:question:| -|`$[::-2]`|`["first", "second", "third", "forth", "fifth"]`|none|`[fifth third first]`|:question:| -|`$[1:]`|`["first", "second", "third", "forth", "fifth"]`|`[second third forth fifth]`|`[second third forth fifth]`|:white_check_mark:| -|`$[3::-1]`|`["first", "second", "third", "forth", "fifth"]`|none|`[fifth forth]`|:question:| -|`$[:2]`|`["first", "second", "third", "forth", "fifth"]`|`[first second]`|`[first second]`|:white_check_mark:| -|`$[:]`|`["first","second"]`|`[first second]`|`[first second]`|:white_check_mark:| -|`$[:]`|`{":": 42, "more": "string"}`|`nil`|`nil`|:white_check_mark:| -|`$[::]`|`["first","second"]`|`[first second]`|`[first second]`|:white_check_mark:| -|`$[:2:-1]`|`["first", "second", "third", "forth", "fifth"]`|none|`[second first]`|:question:| +|`$[0:3:-2]`|`["first", "second", "third", "forth", "fifth"]`|none|`["third","first"]`|:question:| +|`$[::-2]`|`["first", "second", "third", "forth", "fifth"]`|none|`["fifth","third","first"]`|:question:| +|`$[1:]`|`["first", "second", "third", "forth", "fifth"]`|`["second","third","forth","fifth"]`|`["second","third","forth","fifth"]`|:white_check_mark:| +|`$[3::-1]`|`["first", "second", "third", "forth", "fifth"]`|none|`["fifth","forth"]`|:question:| +|`$[:2]`|`["first", "second", "third", "forth", "fifth"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$[:]`|`["first","second"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$[:]`|`{":": 42, "more": "string"}`|`nil`|`null`|:white_check_mark:| +|`$[::]`|`["first","second"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$[:2:-1]`|`["first", "second", "third", "forth", "fifth"]`|none|`["second","first"]`|:question:| |`$[3:-4]`|`[2, "a", 4, 5, 100, "nice"]`|`[]`|`[]`|:white_check_mark:| |`$[3:-3]`|`[2, "a", 4, 5, 100, "nice"]`|`[]`|`[]`|:white_check_mark:| |`$[3:-2]`|`[2, "a", 4, 5, 100, "nice"]`|`[5]`|`[5]`|:white_check_mark:| |`$[2:1]`|`["first", "second", "third", "forth"]`|`[]`|`[]`|:white_check_mark:| |`$[0:0]`|`["first", "second"]`|`[]`|`[]`|:white_check_mark:| -|`$[0:1]`|`["first", "second"]`|`[first]`|`[first]`|:white_check_mark:| -|`$[-1:]`|`["first", "second", "third"]`|`[third]`|`[third]`|:white_check_mark:| -|`$[-2:]`|`["first", "second", "third"]`|`[second third]`|`[second third]`|:white_check_mark:| -|`$[-4:]`|`["first", "second", "third"]`|`[first second third]`|`[first second third]`|:white_check_mark:| -|`$[0:3:2]`|`["first", "second", "third", "forth", "fifth"]`|`[first third]`|`[first third]`|:white_check_mark:| -|`$[0:3:0]`|`["first", "second", "third", "forth", "fifth"]`|none|`nil`|:question:| -|`$[0:3:1]`|`["first", "second", "third", "forth", "fifth"]`|`[first second third]`|`[first second third]`|:white_check_mark:| -|`$[010:024:010]`|`[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]`|`[10 20]`|`[10 20]`|:white_check_mark:| -|`$[0:4:2]`|`["first", "second", "third", "forth", "fifth"]`|`[first third]`|`[first third]`|:white_check_mark:| -|`$[1:3:]`|`["first", "second", "third", "forth", "fifth"]`|`[second third]`|`[second third]`|:white_check_mark:| -|`$[::2]`|`["first", "second", "third", "forth", "fifth"]`|`[first third fifth]`|`[first third fifth]`|:white_check_mark:| +|`$[0:1]`|`["first", "second"]`|`["first"]`|`["first"]`|:white_check_mark:| +|`$[-1:]`|`["first", "second", "third"]`|`["third"]`|`["third"]`|:white_check_mark:| +|`$[-2:]`|`["first", "second", "third"]`|`["second","third"]`|`["second","third"]`|:white_check_mark:| +|`$[-4:]`|`["first", "second", "third"]`|`["first","second","third"]`|`["first","second","third"]`|:white_check_mark:| +|`$[0:3:2]`|`["first", "second", "third", "forth", "fifth"]`|`["first","third"]`|`["first","third"]`|:white_check_mark:| +|`$[0:3:0]`|`["first", "second", "third", "forth", "fifth"]`|none|`null`|:question:| +|`$[0:3:1]`|`["first", "second", "third", "forth", "fifth"]`|`["first","second","third"]`|`["first","second","third"]`|:white_check_mark:| +|`$[010:024:010]`|`[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]`|`[10,20]`|`[10,20]`|:white_check_mark:| +|`$[0:4:2]`|`["first", "second", "third", "forth", "fifth"]`|`["first","third"]`|`["first","third"]`|:white_check_mark:| +|`$[1:3:]`|`["first", "second", "third", "forth", "fifth"]`|`["second","third"]`|`["second","third"]`|:white_check_mark:| +|`$[::2]`|`["first", "second", "third", "forth", "fifth"]`|`["first","third","fifth"]`|`["first","third","fifth"]`|:white_check_mark:| -## Bracket Tests +## Bracket Test |query|data|consensus|actual|match| |---|---|---|---|---| -|`$['key']`|`{"key": "value"}`|`value`|`value`|:white_check_mark:| -|`$['missing']`|`{"key": "value"}`|`nil`|`nil`|:white_check_mark:| -|`$..[0]`|`[ "first", { "key": [ "first nested", { "more": [ { "nested": ["deepest", "second"] }, ["more", "values"] ] } ] } ]`|`[deepest first nested first more map[nested:[deepest second]]]`|`[deepest first nested first more map[nested:[deepest second]]]`|:white_check_mark:| -|`$['ü']`|`{"ü": 42}`|`nil`|`nil`|:white_check_mark:| -|`$['two.some']`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`|`42`|`42`|:white_check_mark:| -|`$["key"]`|`{"key": "value"}`|`value`|`nil`|:no_entry:| -|`$[]`|`{"": 42, "''": 123, "\"\"": 222}`|`nil`|`nil`|:white_check_mark:| +|`$['key']`|`{"key": "value"}`|`"value"`|`"value"`|:white_check_mark:| +|`$['missing']`|`{"key": "value"}`|`nil`|`null`|:white_check_mark:| +|`$..[0]`|`[ "first", { "key": [ "first nested", { "more": [ { "nested": ["deepest", "second"] }, ["more", "values"] ] } ] } ]`|`["deepest","first nested","first","more",{"nested":["deepest","second"]}]`|`["deepest","first nested","first","more",{"nested":["deepest","second"]}]`|:white_check_mark:| +|`$['ü']`|`{"ü": 42}`|`nil`|`null`|:white_check_mark:| +|`$['two.some']`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`|`"42"`|`"42"`|:white_check_mark:| +|`$["key"]`|`{"key": "value"}`|`"value"`|`null`|:no_entry:| +|`$[]`|`{"": 42, "''": 123, "\"\"": 222}`|`nil`|`null`|:white_check_mark:| |`$['']`|`{"": 42, "''": 123, "\"\"": 222}`|`42`|`42`|:white_check_mark:| -|`$[""]`|`{"": 42, "''": 123, "\"\"": 222}`|`42`|`nil`|:no_entry:| -|`$[-2]`|`["one element"]`|`nil`|`nil`|:white_check_mark:| -|`$[2]`|`["first", "second", "third", "forth", "fifth"]`|`third`|`third`|:white_check_mark:| -|`$[0]`|`{ "0": "value" }`|`nil`|`nil`|:white_check_mark:| -|`$[1]`|`["one element"]`|`nil`|`nil`|:white_check_mark:| -|`$[0]`|`Hello World`|`nil`|`nil`|:white_check_mark:| +|`$[""]`|`{"": 42, "''": 123, "\"\"": 222}`|`42`|`null`|:no_entry:| +|`$[-2]`|`["one element"]`|`nil`|`null`|:white_check_mark:| +|`$[2]`|`["first", "second", "third", "forth", "fifth"]`|`"third"`|`"third"`|:white_check_mark:| +|`$[0]`|`{ "0": "value" }`|`nil`|`null`|:white_check_mark:| +|`$[1]`|`["one element"]`|`nil`|`null`|:white_check_mark:| +|`$[0]`|`Hello World`|`nil`|`null`|:white_check_mark:| |`$.*[1]`|`[[1], [2,3]]`|`[3]`|`[3]`|:white_check_mark:| -|`$[-1]`|`["first", "second", "third"]`|`third`|`third`|:white_check_mark:| -|`$[-1]`|`[]`|`nil`|`nil`|:white_check_mark:| -|`$[0]`|`["first", "second", "third", "forth", "fifth"]`|`first`|`first`|:white_check_mark:| -|`$[':']`|`{ ":": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| +|`$[-1]`|`["first", "second", "third"]`|`"third"`|`"third"`|:white_check_mark:| +|`$[-1]`|`[]`|`nil`|`null`|:white_check_mark:| +|`$[0]`|`["first", "second", "third", "forth", "fifth"]`|`"first"`|`"first"`|:white_check_mark:| +|`$[':']`|`{ ":": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| |`$[']']`|`{"]": 42}`|`42`|`42`|:white_check_mark:| -|`$['@']`|`{ "@": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| -|`$['.']`|`{ ".": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| +|`$['@']`|`{ "@": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| +|`$['.']`|`{ ".": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| |`$['.*']`|`{"key": 42, ".*": 1, "": 10}`|`1`|`1`|:white_check_mark:| -|`$['"']`|`{ "\"": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| -|`$['\\']`|`{"\\":"value"}`|none|`value`|:question:| -|`$['\'']`|`{"'":"value"}`|`value`|`value`|:white_check_mark:| -|`$['0']`|`{ "0": "value" }`|`value`|`value`|:white_check_mark:| -|`$['$']`|`{ "$": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| +|`$['"']`|`{ "\"": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| +|`$['\\']`|`{"\\":"value"}`|none|`"value"`|:question:| +|`$['\'']`|`{"'":"value"}`|`"value"`|`"value"`|:white_check_mark:| +|`$['0']`|`{ "0": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$['$']`|`{ "$": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| |`$[':@."$,*\'\\']`|`{":@.\"$,*'\\": 42}`|none|`42`|:question:| -|`$['single'quote']`|`{"single'quote":"value"}`|`nil`|`nil`|:white_check_mark:| -|`$[',']`|`{ ",": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| -|`$['*']`|`{ "*": "value", "another": "entry" }`|`value`|`value`|:white_check_mark:| -|`$['*']`|`{ "another": "entry" }`|`nil`|`nil`|:white_check_mark:| +|`$['single'quote']`|`{"single'quote":"value"}`|`nil`|`null`|:white_check_mark:| +|`$[',']`|`{ ",": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| +|`$['*']`|`{ "*": "value", "another": "entry" }`|`"value"`|`"value"`|:white_check_mark:| +|`$['*']`|`{ "another": "entry" }`|`nil`|`null`|:white_check_mark:| |`$[ 'a' ]`|`{" a": 1, "a": 2, " a ": 3, "a ": 4, " 'a' ": 5, " 'a": 6, "a' ": 7, " \"a\" ": 8, "\"a\"": 9}`|`2`|`2`|:white_check_mark:| |`$['ni.*']`|`{"nice": 42, "ni.*": 1, "mice": 100}`|`1`|`1`|:white_check_mark:| -|`$['two'.'some']`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42", "two'.'some": "43" }`|`nil`|`nil`|:white_check_mark:| -|`$[two.some]`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`|`nil`|`nil`|:white_check_mark:| -|`$[*]`|`[ "string", 42, { "key": "value" }, [0, 1] ]`|`[string 42 map[key:value] [0 1]]`|`[string 42 map[key:value] [0 1]]`|:white_check_mark:| +|`$['two'.'some']`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42", "two'.'some": "43" }`|`nil`|`null`|:white_check_mark:| +|`$[two.some]`|`{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`|`nil`|`null`|:white_check_mark:| +|`$[*]`|`[ "string", 42, { "key": "value" }, [0, 1] ]`|`["string",42,{"key":"value"},[0,1]]`|`["string",42,{"key":"value"},[0,1]]`|:white_check_mark:| |`$[*]`|`[]`|`[]`|`[]`|:white_check_mark:| |`$[*]`|`{}`|`[]`|`[]`|:white_check_mark:| -|`$[*]`|`[ 40, null, 42 ]`|`[40 42]`|`[40 42]`|:white_check_mark:| -|`$[*]`|`{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`|`[string 42 map[key:value] [0 1]]`|`[string 42 map[key:value] [0 1]]`|:white_check_mark:| -|`$[0:2][*]`|`[[1, 2], ["a", "b"], [0, 0]]`|`[1 2 a b]`|`[[1 2] [a b]]`|:no_entry:| +|`$[*]`|`[ 40, null, 42 ]`|`[40,null,42]`|`[40,null,42]`|:white_check_mark:| +|`$[*]`|`{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`|`["string",42,{"key":"value"},[0,1]]`|`["string",42,{"key":"value"},[0,1]]`|:white_check_mark:| +|`$[0:2][*]`|`[[1, 2], ["a", "b"], [0, 0]]`|`[1,2,"a","b"]`|`[[1,2],["a","b"]]`|:no_entry:| |`$[*].bar[*]`|`[{"bar": [42]}]`|`[42]`|`[[42]]`|:no_entry:| -|`$..[*]`|`{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`|`[value map[complex:string primitives:[0 1]] [0 1] string 0 1]`|`[value map[complex:string primitives:[0 1]] [0 1] string 0 1]`|:white_check_mark:| -|`$[key]`|`{ "key": "value" }`|`nil`|`nil`|:white_check_mark:| +|`$..[*]`|`{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`|`["value",{"complex":"string","primitives":[0,1]},[0,1],"string",0,1]`|`["value",{"complex":"string","primitives":[0,1]},[0,1],"string",0,1]`|:white_check_mark:| +|`$[key]`|`{ "key": "value" }`|`nil`|`null`|:white_check_mark:| -## Dot Tests +## Dot Test |query|data|consensus|actual|match| |---|---|---|---|---| |`@.a`|`{"a": 1}`|`nil`|`1`|:no_entry:| -|`$.['key']`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|`value`|`value`|:white_check_mark:| -|`$.["key"]`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|none|`nil`|:question:| -|`$.[key]`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|none|`nil`|:question:| -|`$.key`|`{ "key": "value" }`|`value`|`value`|:white_check_mark:| -|`$.key`|`[0, 1]`|`nil`|`nil`|:white_check_mark:| -|`$.key`|`{ "key": ["first", "second"] }`|`[first second]`|`[first second]`|:white_check_mark:| -|`$.id`|`[{"id": 2}]`|`nil`|`nil`|:white_check_mark:| -|`$.key`|`{ "key": {} }`|`map[]`|`map[]`|:white_check_mark:| -|`$.key`|`{ "key": null }`|`nil`|`nil`|:white_check_mark:| -|`$.missing`|`{"key": "value"}`|`nil`|`nil`|:white_check_mark:| -|`$[0:2].key`|`[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`|`[ey bee]`|`[ey bee]`|:white_check_mark:| -|`$..[1].key`|`{ "k": [{"key": "some value"}, {"key": 42}], "kk": [[{"key": 100}, {"key": 200}, {"key": 300}], [{"key": 400}, {"key": 500}, {"key": 600}]], "key": [0, 1] }`|`[200 42 500]`|`[200 42 500]`|:white_check_mark:| -|`$[*].a`|`[{"a": 1},{"a": 1}]`|`[1 1]`|`[1 1]`|:white_check_mark:| +|`$.['key']`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|`"value"`|`"value"`|:white_check_mark:| +|`$.["key"]`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|none|`null`|:question:| +|`$.[key]`|`{ "key": "value", "other": {"key": [{"key": 42}]} }`|none|`null`|:question:| +|`$.key`|`{ "key": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$.key`|`[0, 1]`|`nil`|`null`|:white_check_mark:| +|`$.key`|`{ "key": ["first", "second"] }`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$.id`|`[{"id": 2}]`|`nil`|`null`|:white_check_mark:| +|`$.key`|`{ "key": {} }`|`{}`|`{}`|:white_check_mark:| +|`$.key`|`{ "key": null }`|`nil`|`null`|:white_check_mark:| +|`$.missing`|`{"key": "value"}`|`nil`|`null`|:white_check_mark:| +|`$[0:2].key`|`[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`|`["ey","bee"]`|`["ey","bee"]`|:white_check_mark:| +|`$..[1].key`|`{ "k": [{"key": "some value"}, {"key": 42}], "kk": [[{"key": 100}, {"key": 200}, {"key": 300}], [{"key": 400}, {"key": 500}, {"key": 600}]], "key": [0, 1] }`|`[200,42,500]`|`[200,42,500]`|:white_check_mark:| +|`$[*].a`|`[{"a": 1},{"a": 1}]`|`[1,1]`|`[1,1]`|:white_check_mark:| |`$[*].a`|`[{"a": 1}]`|`[1]`|`[1]`|:white_check_mark:| |`$[*].a`|`[{"a": 1},{"b": 1}]`|`[1]`|`[1]`|:white_check_mark:| -|`$[?(@.id==42)].name`|`[{"id": 42, "name": "forty-two"}, {"id": 1, "name": "one"}]`|`[forty-two]`|`[forty-two]`|:white_check_mark:| -|`$..key`|`{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`|`[russian dolls something top value map[key:russian dolls]]`|`[russian dolls something top value map[key:russian dolls]]`|:white_check_mark:| -|`$.store..price`|`{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }`|`[12.99 19.95 22.99 8.95 8.99]`|`[12.99 19.95 22.99 8.95 8.99]`|:white_check_mark:| -|`$...key`|`{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`|`[russian dolls something top value]`|`[russian dolls something top value map[key:russian dolls]]`|:no_entry:| -|`$[0,2].key`|`[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`|`[ey see]`|`[ey see]`|:white_check_mark:| -|`$['one','three'].key`|`{ "one": {"key": "value"}, "two": {"k": "v"}, "three": {"some": "more", "key": "other value"} }`|`[value other value]`|`[value other value]`|:white_check_mark:| -|`$.key-dash`|`{ "key": 42, "key-": 43, "-": 44, "dash": 45, "-dash": 46, "": 47, "key-dash": "value", "something": "else" }`|`value`|`value`|:white_check_mark:| +|`$[?(@.id==42)].name`|`[{"id": 42, "name": "forty-two"}, {"id": 1, "name": "one"}]`|`["forty-two"]`|`["forty-two"]`|:white_check_mark:| +|`$..key`|`{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`|`["russian dolls","something","top","value",{"key":"russian dolls"}]`|`["russian dolls","something","top","value",{"key":"russian dolls"}]`|:white_check_mark:| +|`$.store..price`|`{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }`|`[12.99,19.95,22.99,8.95,8.99]`|`[12.99,19.95,22.99,8.95,8.99]`|:white_check_mark:| +|`$...key`|`{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`|`["russian dolls","something","top","value"]`|`["russian dolls","something","top","value",{"key":"russian dolls"}]`|:no_entry:| +|`$[0,2].key`|`[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`|`["ey","see"]`|`["ey","see"]`|:white_check_mark:| +|`$['one','three'].key`|`{ "one": {"key": "value"}, "two": {"k": "v"}, "three": {"some": "more", "key": "other value"} }`|`["value","other value"]`|`["value","other value"]`|:white_check_mark:| +|`$.key-dash`|`{ "key": 42, "key-": 43, "-": 44, "dash": 45, "-dash": 46, "": 47, "key-dash": "value", "something": "else" }`|`"value"`|`"value"`|:white_check_mark:| |`$."key"`|`{ "key": "value", "\"key\"": 42 }`|none|`42`|:question:| -|`$.."key"`|`{ "object": { "key": "value", "\"key\"": 100, "array": [ {"key": "something", "\"key\"": 0}, {"key": {"key": "russian dolls"}, "\"key\"": {"\"key\"": 99}} ] }, "key": "top", "\"key\"": 42 }`|none|`[0 42 99 100 map["key":99]]`|:question:| -|`$.`|`{"key": 42, "": 9001, "''": "nice"}`|none|`nil`|:question:| -|`$.in`|`{ "in": "value" }`|`value`|`value`|:white_check_mark:| -|`$.length`|`{ "length": "value" }`|`value`|`value`|:white_check_mark:| +|`$.."key"`|`{ "object": { "key": "value", "\"key\"": 100, "array": [ {"key": "something", "\"key\"": 0}, {"key": {"key": "russian dolls"}, "\"key\"": {"\"key\"": 99}} ] }, "key": "top", "\"key\"": 42 }`|none|`[0,42,99,100,{"\"key\"":99}]`|:question:| +|`$.`|`{"key": 42, "": 9001, "''": "nice"}`|none|`null`|:question:| +|`$.in`|`{ "in": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$.length`|`{ "length": "value" }`|`"value"`|`"value"`|:white_check_mark:| |`$.length`|`[4, 5, 6]`|`nil`|`3`|:no_entry:| -|`$.null`|`{ "null": "value" }`|`value`|`value`|:white_check_mark:| -|`$.true`|`{ "true": "value" }`|`value`|`value`|:white_check_mark:| -|`$.$`|`{ "$": "value" }`|none|`map[$:value]`|:question:| -|`$.屬性`|`{ "屬性": "value" }`|`value`|`value`|:white_check_mark:| -|`$.2`|`["first", "second", "third", "forth", "fifth"]`|none|`nil`|:question:| -|`$.2`|`{"a": "first", "2": "second", "b": "third"}`|`second`|`second`|:white_check_mark:| -|`$.-1`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`nil`|:white_check_mark:| +|`$.null`|`{ "null": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$.true`|`{ "true": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$.$`|`{ "$": "value" }`|none|`{"$":"value"}`|:question:| +|`$.屬性`|`{ "屬性": "value" }`|`"value"`|`"value"`|:white_check_mark:| +|`$.2`|`["first", "second", "third", "forth", "fifth"]`|none|`null`|:question:| +|`$.2`|`{"a": "first", "2": "second", "b": "third"}`|`"second"`|`"second"`|:white_check_mark:| +|`$.-1`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`null`|:white_check_mark:| |`$.'key'`|`{ "key": "value", "'key'": 42 }`|none|`42`|:question:| -|`$..'key'`|`{ "object": { "key": "value", "'key'": 100, "array": [ {"key": "something", "'key'": 0}, {"key": {"key": "russian dolls"}, "'key'": {"'key'": 99}} ] }, "key": "top", "'key'": 42 }`|none|`[42 100 0 map['key':99] 99]`|:question:| +|`$..'key'`|`{ "object": { "key": "value", "'key'": 100, "array": [ {"key": "something", "'key'": 0}, {"key": {"key": "russian dolls"}, "'key'": {"'key'": 99}} ] }, "key": "top", "'key'": 42 }`|none|`[42,100,0,{"'key'":99},99]`|:question:| |`$.'some.key'`|`{"some.key": 42, "some": {"key": "value"}, "'some.key'": 43}`|none|`43`|:question:| |`$. a`|`{" a": 1, "a": 2, " a ": 3, "": 4}`|none|`2`|:question:| -|`$.*`|`[ "string", 42, { "key": "value" }, [0, 1] ]`|`[string 42 map[key:value] [0 1]]`|`[string 42 map[key:value] [0 1]]`|:white_check_mark:| +|`$.*`|`[ "string", 42, { "key": "value" }, [0, 1] ]`|`["string",42,{"key":"value"},[0,1]]`|`["string",42,{"key":"value"},[0,1]]`|:white_check_mark:| |`$.*`|`[]`|`[]`|`[]`|:white_check_mark:| |`$.*`|`{}`|`[]`|`[]`|:white_check_mark:| -|`$.*`|`{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`|`[string 42 [0 1] map[key:value]]`|`[string 42 [0 1] map[key:value]]`|:white_check_mark:| +|`$.*`|`{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`|`["string",42,[0,1],{"key":"value"}]`|`["string",42,[0,1],{"key":"value"}]`|:white_check_mark:| |`$.*.bar.*`|`[{"bar": [42]}]`|`[42]`|`[[42]]`|:no_entry:| -|`$.*.*`|`[[1, 2, 3], [4, 5, 6]]`|`[1 2 3 4 5 6]`|`[[1 2 3] [4 5 6]]`|:no_entry:| -|`$..*`|`{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`|`[string value 0 1 [0 1] map[complex:string primitives:[0 1]]]`|`[string value 0 1 [0 1] map[complex:string primitives:[0 1]]]`|:white_check_mark:| -|`$..*`|`[ 40, null, 42 ]`|`[40 42 ]`|`[40 42 ]`|:white_check_mark:| +|`$.*.*`|`[[1, 2, 3], [4, 5, 6]]`|`[1,2,3,4,5,6]`|`[[1,2,3],[4,5,6]]`|:no_entry:| +|`$..*`|`{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`|`["string","value",0,1,[0,1],{"complex":"string","primitives":[0,1]}]`|`["string","value",0,1,[0,1],{"complex":"string","primitives":[0,1]}]`|:white_check_mark:| +|`$..*`|`[ 40, null, 42 ]`|`[40,42,null]`|`[40,42,null]`|:white_check_mark:| |`$..*`|`42`|`[]`|`[]`|:white_check_mark:| -|`$a`|`{"a": 1, "$a": 2}`|`nil`|`nil`|:white_check_mark:| -|`.key`|`{ "key": "value" }`|`nil`|`nil`|:white_check_mark:| -|`key`|`{ "key": "value" }`|`nil`|`nil`|:white_check_mark:| +|`$a`|`{"a": 1, "$a": 2}`|`nil`|`null`|:white_check_mark:| +|`.key`|`{ "key": "value" }`|`nil`|`null`|:white_check_mark:| +|`key`|`{ "key": "value" }`|`nil`|`null`|:white_check_mark:| -## Filter Tests +## Filter Test |query|data|consensus|actual|match| |---|---|---|---|---| -|`$[?(@.key)]`|`{"key": 42, "another": {"key": 1}}`|none|`[map[key:1]]`|:question:| -|`$..*[?(@.id>2)]`|`[ { "complext": { "one": [ { "name": "first", "id": 1 }, { "name": "next", "id": 2 }, { "name": "another", "id": 3 }, { "name": "more", "id": 4 } ], "more": { "name": "next to last", "id": 5 } } }, { "name": "last", "id": 6 } ]`|none|`[[] [] [map[id:5 name:next to last]] [map[id:3 name:another] map[id:4 name:more]] [] [] [] [] []]`|:question:| -|`$..[?(@.id==2)]`|`{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`|none|`[map[id:2] map[id:2] map[id:2] map[id:2]]`|:question:| -|`$[?(@.key+50==100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key+50": 100}]`|none|`[map[key:50]]`|:question:| -|`$[?(@.key>42 && @.key<44)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[map[key:43]]`|`[map[key:43]]`|:white_check_mark:| +|`$[?(@.key)]`|`{"key": 42, "another": {"key": 1}}`|none|`[{"key":1}]`|:question:| +|`$..*[?(@.id>2)]`|`[ { "complext": { "one": [ { "name": "first", "id": 1 }, { "name": "next", "id": 2 }, { "name": "another", "id": 3 }, { "name": "more", "id": 4 } ], "more": { "name": "next to last", "id": 5 } } }, { "name": "last", "id": 6 } ]`|none|`[[],[],[{"id":5,"name":"next to last"}],[{"id":3,"name":"another"},{"id":4,"name":"more"}],[],[],[],[],[]]`|:question:| +|`$..[?(@.id==2)]`|`{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`|none|`[{"id":2},{"id":2},{"id":2},{"id":2}]`|:question:| +|`$[?(@.key+50==100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key+50": 100}]`|none|`[{"key":50}]`|:question:| +|`$[?(@.key>42 && @.key<44)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[{"key":43}]`|`[{"key":43}]`|:white_check_mark:| |`$[?(@.key>0 && false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[]`|:question:| -|`$[?(@.key>0 && true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[map[key:1] map[key:3]]`|:question:| -|`$[?(@.key>43 || @.key<43)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[map[key:42] map[key:44]]`|`[map[key:42] map[key:44]]`|:white_check_mark:| -|`$[?(@.key>0 || false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[map[key:1] map[key:3]]`|:question:| -|`$[?(@.key>0 || true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[map[key:1] map[key:3] map[key:-1] map[key:0]]`|:question:| -|`$[?(@['key']==42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"} ]`|`[map[key:42]]`|`[map[key:42]]`|:white_check_mark:| -|`$[?(@['@key']==42)]`|`[ {"@key": 0}, {"@key": 42}, {"key": 42}, {"@key": 43}, {"some": "value"} ]`|`[map[@key:42]]`|`[map[@key:42]]`|:white_check_mark:| -|`$[?(@[-1]==2)]`|`[[2, 3], ["a"], [0, 2], [2]]`|none|`[[0 2] [2]]`|:question:| -|`$[?(@[1]=='b')]`|`[["a", "b"], ["x", "y"]]`|`[[a b]]`|`[[a b]]`|:white_check_mark:| -|`$[?(@[1]=='b')]`|`{"1": ["a", "b"], "2": ["x", "y"]}`|none|`[[a b]]`|:question:| -|`$[?(@)]`|`[ "some value", null, "value", 0, 1, -1, "", [], {}, false, true ]`|none|`[some value value 0 1 -1 true]`|:question:| +|`$[?(@.key>0 && true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3}]`|:question:| +|`$[?(@.key>43 || @.key<43)]`|`[ {"key": 42}, {"key": 43}, {"key": 44} ]`|`[{"key":42},{"key":44}]`|`[{"key":42},{"key":44}]`|:white_check_mark:| +|`$[?(@.key>0 || false)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3}]`|:question:| +|`$[?(@.key>0 || true)]`|`[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`|none|`[{"key":1},{"key":3},{"key":-1},{"key":0}]`|:question:| +|`$[?(@['key']==42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"} ]`|`[{"key":42}]`|`[{"key":42}]`|:white_check_mark:| +|`$[?(@['@key']==42)]`|`[ {"@key": 0}, {"@key": 42}, {"key": 42}, {"@key": 43}, {"some": "value"} ]`|`[{"@key":42}]`|`[{"@key":42}]`|:white_check_mark:| +|`$[?(@[-1]==2)]`|`[[2, 3], ["a"], [0, 2], [2]]`|none|`[[0,2],[2]]`|:question:| +|`$[?(@[1]=='b')]`|`[["a", "b"], ["x", "y"]]`|`[["a","b"]]`|`[["a","b"]]`|:white_check_mark:| +|`$[?(@[1]=='b')]`|`{"1": ["a", "b"], "2": ["x", "y"]}`|none|`[["a","b"]]`|:question:| +|`$[?(@)]`|`[ "some value", null, "value", 0, 1, -1, "", [], {}, false, true ]`|none|`["some value","value",0,1,-1,true]`|:question:| |`$[?(@.a && (@.b || @.c))]`|`[ { "a": true }, { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "c": true }, { "b": true } ]`|none|`[]`|:question:| -|`[?(@.a && @.b || @.c)]`|`[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`|none|`nil`|:question:| -|`$[?(@.key/10==5)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key/10": 5}]`|none|`[map[key:50]]`|:question:| +|`[?(@.a && @.b || @.c)]`|`[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`|none|`null`|:question:| +|`$[?(@.key/10==5)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key/10": 5}]`|none|`[{"key":50}]`|:question:| |`$[?(@.key-dash == 'value')]`|`[ { "key-dash": "value" } ]`|none|`[]`|:question:| -|`$[?(@.2 == 'second')]`|`[{"a": "first", "2": "second", "b": "third"}]`|none|`[map[2:second a:first b:third]]`|:question:| +|`$[?(@.2 == 'second')]`|`[{"a": "first", "2": "second", "b": "third"}]`|none|`[{"2":"second","a":"first","b":"third"}]`|:question:| |`$[?(@.2 == 'third')]`|`[["first", "second", "third", "forth", "fifth"]] `|none|`[]`|:question:| -|`$[?()]`|`[1, {"key": 42}, "value", null]`|`nil`|`nil`|:white_check_mark:| -|`$[?(@.key==42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`[map[key:42]]`|:question:| +|`$[?()]`|`[1, {"key": 42}, "value", null]`|`nil`|`null`|:white_check_mark:| +|`$[?(@.key==42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`[{"key":42}]`|:question:| |`$[?(@==42)]`|`[ 0, 42, -1, 41, 43, 42.0001, 41.9999, null, 100 ]`|`[42]`|`[]`|:no_entry:| |`$[?(@.key==43)]`|`[{"key": 42}]`|`[]`|`[]`|:white_check_mark:| -|`$[?(@.key==42)]`|`{ "a": {"key": 0}, "b": {"key": 42}, "c": {"key": -1}, "d": {"key": 41}, "e": {"key": 43}, "f": {"key": 42.0001}, "g": {"key": 41.9999}, "h": {"key": 100}, "i": {"some": "value"} }`|none|`[map[key:42]]`|:question:| +|`$[?(@.key==42)]`|`{ "a": {"key": 0}, "b": {"key": 42}, "c": {"key": -1}, "d": {"key": 41}, "e": {"key": 43}, "f": {"key": 42.0001}, "g": {"key": 41.9999}, "h": {"key": 100}, "i": {"some": "value"} }`|none|`[{"key":42}]`|:question:| |`$[?(@.id==2)]`|`{"id": 2}`|none|`[]`|:question:| |`$[?(@.d==["v1","v2"])]`|`[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`|none|`[]`|:question:| |`$[?(@[0:1]==[1])]`|`[[1, 2, 3], [1], [2, 3], 1, 2]`|none|`[]`|:question:| |`$[?(@.*==[1,2])]`|`[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`|none|`[]`|:question:| |`$[?(@.d==['v1','v2'])]`|`[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`|none|`[]`|:question:| -|`$[?((@.key<44)==false)]`|`[{"key": 42}, {"key": 43}, {"key": 44}]`|none|`[map[key:44]]`|:question:| -|`$[?(@.key==false)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[map[key:false]]`|:question:| +|`$[?((@.key<44)==false)]`|`[{"key": 42}, {"key": 43}, {"key": 44}]`|none|`[{"key":44}]`|:question:| +|`$[?(@.key==false)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[{"key":false}]`|:question:| |`$[?(@.key==null)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[]`|:question:| |`$[?(@[0:1]==1)]`|`[[1, 2, 3], [1], [2, 3], 1, 2]`|none|`[]`|:question:| |`$[?(@[*]==2)]`|`[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`|none|`[]`|:question:| |`$[?(@.*==2)]`|`[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`|none|`[]`|:question:| -|`$[?(@.key==-0.123e2)]`|`[{"key": -12.3}, {"key": -0.123}, {"key": -12}, {"key": 12.3}, {"key": 2}, {"key": "-0.123e2"}]`|none|`[map[key:-12.3]]`|:question:| -|`$[?(@.key==010)]`|`[{"key": "010"}, {"key": "10"}, {"key": 10}, {"key": 0}, {"key": 8}]`|none|`[map[key:8]]`|:question:| +|`$[?(@.key==-0.123e2)]`|`[{"key": -12.3}, {"key": -0.123}, {"key": -12}, {"key": 12.3}, {"key": 2}, {"key": "-0.123e2"}]`|none|`[{"key":-12.3}]`|:question:| +|`$[?(@.key==010)]`|`[{"key": "010"}, {"key": "10"}, {"key": 10}, {"key": 0}, {"key": 8}]`|none|`[{"key":8}]`|:question:| |`$[?(@.d=={"k":"v"})]`|`[ { "d": { "k": "v" } }, { "d": { "a": "b" } }, { "d": "k" }, { "d": "v" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "[object Object]" }, { "d": "{\"k\": \"v\"}" }, { "d": "{\"k\":\"v\"}" }, "v" ]`|none|`[]`|:question:| -|`$[?(@.key=="value")]`|`[ {"key": "some"}, {"key": "value"}, {"key": null}, {"key": 0}, {"key": 1}, {"key": -1}, {"key": ""}, {"key": {}}, {"key": []}, {"key": "valuemore"}, {"key": "morevalue"}, {"key": ["value"]}, {"key": {"some": "value"}}, {"key": {"key": "value"}}, {"some": "value"} ]`|`[map[key:value]]`|`[map[key:value]]`|:white_check_mark:| -|`$[?(@.key=="Motörhead")]`|`[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`|`[map[key:Motörhead]]`|`[map[key:Motörhead]]`|:white_check_mark:| -|`$[?(@.key=="hi@example.com")]`|`[ {"key": "some"}, {"key": "value"}, {"key": "hi@example.com"} ]`|`[map[key:hi@example.com]]`|`[]`|:no_entry:| -|`$[?(@.key=="some.value")]`|`[ {"key": "some"}, {"key": "value"}, {"key": "some.value"} ]`|`[map[key:some.value]]`|`[map[key:some.value]]`|:white_check_mark:| -|`$[?(@.key=='value')]`|`[ {"key": "some"}, {"key": "value"} ]`|`[map[key:value]]`|`[map[key:value]]`|:white_check_mark:| -|`$[?(@.key=="Mot\u00f6rhead")]`|`[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`|none|`[map[key:Motörhead]]`|:question:| -|`$[?(@.key==true)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[map[key:true]]`|:question:| -|`$[?(@.key1==@.key2)]`|`[ {"key1": 10, "key2": 10}, {"key1": 42, "key2": 50}, {"key1": 10}, {"key2": 10}, {}, {"key1": null, "key2": null}, {"key1": null}, {"key2": null}, {"key1": 0, "key2": 0}, {"key1": 0}, {"key2": 0}, {"key1": -1, "key2": -1}, {"key1": "", "key2": ""}, {"key1": false, "key2": false}, {"key1": false}, {"key2": false}, {"key1": true, "key2": true}, {"key1": [], "key2": []}, {"key1": {}, "key2": {}}, {"key1": {"a": 1, "b": 2}, "key2": {"b": 2, "a": 1}} ]`|none|`[map[key1:10 key2:10] map[key1:0 key2:0] map[key1:-1 key2:-1] map[key1: key2:] map[key1:false key2:false] map[key1:true key2:true]]`|:question:| -|`$.items[?(@.key==$.value)]`|`{"value": 42, "items": [{"key": 10}, {"key": 42}, {"key": 50}]}`|none|`[map[key:42]]`|:question:| -|`$[?(@.key>42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:43] map[key:42.0001] map[key:100]]`|:question:| -|`$[?(@.key>=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:42] map[key:43] map[key:42.0001] map[key:100]]`|:question:| +|`$[?(@.key=="value")]`|`[ {"key": "some"}, {"key": "value"}, {"key": null}, {"key": 0}, {"key": 1}, {"key": -1}, {"key": ""}, {"key": {}}, {"key": []}, {"key": "valuemore"}, {"key": "morevalue"}, {"key": ["value"]}, {"key": {"some": "value"}}, {"key": {"key": "value"}}, {"some": "value"} ]`|`[{"key":"value"}]`|`[{"key":"value"}]`|:white_check_mark:| +|`$[?(@.key=="Motörhead")]`|`[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`|`[{"key":"Motörhead"}]`|`[{"key":"Motörhead"}]`|:white_check_mark:| +|`$[?(@.key=="hi@example.com")]`|`[ {"key": "some"}, {"key": "value"}, {"key": "hi@example.com"} ]`|`[{"key":"hi@example.com"}]`|`[]`|:no_entry:| +|`$[?(@.key=="some.value")]`|`[ {"key": "some"}, {"key": "value"}, {"key": "some.value"} ]`|`[{"key":"some.value"}]`|`[{"key":"some.value"}]`|:white_check_mark:| +|`$[?(@.key=='value')]`|`[ {"key": "some"}, {"key": "value"} ]`|`[{"key":"value"}]`|`[{"key":"value"}]`|:white_check_mark:| +|`$[?(@.key=="Mot\u00f6rhead")]`|`[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`|none|`[{"key":"Motörhead"}]`|:question:| +|`$[?(@.key==true)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[{"key":true}]`|:question:| +|`$[?(@.key1==@.key2)]`|`[ {"key1": 10, "key2": 10}, {"key1": 42, "key2": 50}, {"key1": 10}, {"key2": 10}, {}, {"key1": null, "key2": null}, {"key1": null}, {"key2": null}, {"key1": 0, "key2": 0}, {"key1": 0}, {"key2": 0}, {"key1": -1, "key2": -1}, {"key1": "", "key2": ""}, {"key1": false, "key2": false}, {"key1": false}, {"key2": false}, {"key1": true, "key2": true}, {"key1": [], "key2": []}, {"key1": {}, "key2": {}}, {"key1": {"a": 1, "b": 2}, "key2": {"b": 2, "a": 1}} ]`|none|`[{"key1":10,"key2":10},{"key1":0,"key2":0},{"key1":-1,"key2":-1},{"key1":"","key2":""},{"key1":false,"key2":false},{"key1":true,"key2":true}]`|:question:| +|`$.items[?(@.key==$.value)]`|`{"value": 42, "items": [{"key": 10}, {"key": 42}, {"key": 50}]}`|none|`[{"key":42}]`|:question:| +|`$[?(@.key>42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":43},{"key":42.0001},{"key":100}]`|:question:| +|`$[?(@.key>=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":42},{"key":43},{"key":42.0001},{"key":100}]`|:question:| |`$[?(@.d in [2, 3])]`|`[{"d": 1}, {"d": 2}, {"d": 1}, {"d": 3}, {"d": 4}]`|`nil`|`[]`|:no_entry:| |`$[?(2 in @.d)]`|`[{"d": [1, 2, 3]}, {"d": [2]}, {"d": [1]}, {"d": [3, 4]}, {"d": [4, 2]}]`|`nil`|`[]`|:no_entry:| -|`$[?(@.key<42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:0] map[key:-1] map[key:41] map[key:41.9999]]`|:question:| -|`$[?(@.key<=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:0] map[key:42] map[key:-1] map[key:41] map[key:41.9999]]`|:question:| -|`$[?(@.key*2==100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key*2": 100}]`|none|`[map[key:50]]`|:question:| -|`$[?(!(@.key==42))]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:0] map[key:-1] map[key:41] map[key:43] map[key:42.0001] map[key:41.9999] map[key:100]]`|:question:| -|`$[?(!(@.key<42))]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[map[key:42] map[key:43] map[key:42.0001] map[key:100]]`|:question:| -|`$[?(!@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[map[key:false]]`|:question:| -|`$[?(@.key!=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`[map[key:0] map[key:-1] map[key:1] map[key:41] map[key:43] map[key:42.0001] map[key:41.9999] map[key:100] map[key:420]]`|:question:| -|`$[*].bookmarks[?(@.page == 45)]^^^`|`[ { "title": "Sayings of the Century", "bookmarks": [{ "page": 40 }] }, { "title": "Sword of Honour", "bookmarks": [ { "page": 35 }, { "page": 45 } ] }, { "title": "Moby Dick", "bookmarks": [ { "page": 3035 }, { "page": 45 } ] } ]`|`nil`|`[[] [] []]`|:no_entry:| +|`$[?(@.key<42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":0},{"key":-1},{"key":41},{"key":41.9999}]`|:question:| +|`$[?(@.key<=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":0},{"key":42},{"key":-1},{"key":41},{"key":41.9999}]`|:question:| +|`$[?(@.key*2==100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key*2": 100}]`|none|`[{"key":50}]`|:question:| +|`$[?(!(@.key==42))]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":0},{"key":-1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100}]`|:question:| +|`$[?(!(@.key<42))]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`|none|`[{"key":42},{"key":43},{"key":42.0001},{"key":100}]`|:question:| +|`$[?(!@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[{"key":false}]`|:question:| +|`$[?(@.key!=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`[{"key":0},{"key":-1},{"key":1},{"key":41},{"key":43},{"key":42.0001},{"key":41.9999},{"key":100},{"key":420}]`|:question:| +|`$[*].bookmarks[?(@.page == 45)]^^^`|`[ { "title": "Sayings of the Century", "bookmarks": [{ "page": 40 }] }, { "title": "Sword of Honour", "bookmarks": [ { "page": 35 }, { "page": 45 } ] }, { "title": "Moby Dick", "bookmarks": [ { "page": 3035 }, { "page": 45 } ] } ]`|`nil`|`[[],[],[]]`|:no_entry:| |`$[?(@.name=~/hello.*/)]`|`[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"} ]`|none|`[]`|:question:| |`$[?(@.name=~/@.pattern/)]`|`[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"}, {"pattern": "hello.*"} ]`|none|`[]`|:question:| |`$[?(@[*]>=4)]`|`[[1,2],[3,4],[5,6]]`|none|`[]`|:question:| |`$.x[?(@[*]>=$.y[*])]`|`{"x":[[1,2],[3,4],[5,6]],"y":[3,4,5]}`|none|`[]`|:question:| |`$[?(@.key=42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|`nil`|`[]`|:no_entry:| |`$[?(@.a[?(@.price>10)])]`|`[ { "a": [{"price": 1}, {"price": 3}] }, { "a": [{"price": 11}] }, { "a": [{"price": 8}, {"price": 12}, {"price": 3}] }, { "a": [] } ]`|none|`[]`|:question:| -|`$[?(@.address.city=='Berlin')]`|`[ { "address": { "city": "Berlin" } }, { "address": { "city": "London" } } ]`|`[map[address:map[city:Berlin]]]`|`[map[address:map[city:Berlin]]]`|:white_check_mark:| -|`$[?(@.key-50==-100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key-50": -100}]`|none|`[map[key:-50]]`|:question:| -|`$[?(1==1)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[1 3 nice true false map[] [] -1 0 ]`|:question:| +|`$[?(@.address.city=='Berlin')]`|`[ { "address": { "city": "Berlin" } }, { "address": { "city": "London" } } ]`|`[{"address":{"city":"Berlin"}}]`|`[{"address":{"city":"Berlin"}}]`|:white_check_mark:| +|`$[?(@.key-50==-100)]`|`[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key-50": -100}]`|none|`[{"key":-50}]`|:question:| +|`$[?(1==1)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[1,3,"nice",true,null,false,{},[],-1,0,""]`|:question:| |`$[?(@.key===42)]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`[]`|:question:| -|`$[?(@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[map[key:true] map[key:value] map[key:0] map[key:1] map[key:-1] map[key:42]]`|:question:| -|`$.*[?(@.key)]`|`[ { "some": "some value" }, { "key": "value" } ]`|none|`[[] []]`|:question:| -|`$..[?(@.id)]`|`{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`|none|`[map[id:2] map[id:2] map[id:2] map[id:2]]`|:question:| +|`$[?(@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[{"key":true},{"key":"value"},{"key":0},{"key":1},{"key":-1},{"key":42}]`|:question:| +|`$.*[?(@.key)]`|`[ { "some": "some value" }, { "key": "value" } ]`|none|`[[],[]]`|:question:| +|`$..[?(@.id)]`|`{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`|none|`[{"id":2},{"id":2},{"id":2},{"id":2}]`|:question:| |`$[?(false)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[]`|:question:| |`$[?(@..child)]`|`[{"key": [{"child": 1}, {"child": 2}]}, {"key": [{"child": 2}]}, {"key": [{}]}, {"key": [{"something": 42}]}, {}]`|none|`[]`|:question:| |`$[?(null)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[]`|:question:| -|`$[?(true)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[1 3 nice true false map[] [] -1 0 ]`|:question:| -|`$[?@.key==42]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`nil`|:question:| -|`$[?(@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[map[key:true] map[key:value] map[key:0] map[key:1] map[key:-1] map[key:42]]`|:question:| - +|`$[?(true)]`|`[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`|none|`[1,3,"nice",true,null,false,{},[],-1,0,""]`|:question:| +|`$[?@.key==42]`|`[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`|none|`null`|:question:| +|`$[?(@.key)]`|`[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`|none|`[{"key":true},{"key":"value"},{"key":0},{"key":1},{"key":-1},{"key":42}]`|:question:| -## Root Tests +## Misc Test |query|data|consensus|actual|match| |---|---|---|---|---| -|``|`{"a": 42, "": 21}`|`nil`|`nil`|:white_check_mark:| -|`$.data.sum()`|`{"data": [1,2,3,4]}`|none|`nil`|:question:| -|`$(key,more)`|`{"key": 1, "some": 2, "more": 3}`|`nil`|`nil`|:white_check_mark:| -|`$..`|`[{"a": {"b": "c"}}, [0, 1]]`|none|`[[map[a:map[b:c]] [0 1]] map[a:map[b:c]] map[b:c] c [0 1] 0 1]`|:question:| -|`$.key..`|`{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}`|none|`[map[complex:string primitives:[0 1]] [0 1] 0 1 string]`|:question:| -|`$`|`{ "key": "value", "another key": { "complex": [ "a", 1 ] } }`|`map[another key:map[complex:[a 1]] key:value]`|`map[another key:map[complex:[a 1]] key:value]`|:white_check_mark:| +|``|`{"a": 42, "": 21}`|`nil`|`null`|:white_check_mark:| +|`$.data.sum()`|`{"data": [1,2,3,4]}`|none|`null`|:question:| +|`$(key,more)`|`{"key": 1, "some": 2, "more": 3}`|`nil`|`null`|:white_check_mark:| +|`$..`|`[{"a": {"b": "c"}}, [0, 1]]`|none|`[[{"a":{"b":"c"}},[0,1]],{"a":{"b":"c"}},{"b":"c"},"c",[0,1],0,1]`|:question:| +|`$.key..`|`{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}`|none|`[{"complex":"string","primitives":[0,1]},[0,1],0,1,"string"]`|:question:| +|`$`|`{ "key": "value", "another key": { "complex": [ "a", 1 ] } }`|`{"another key":{"complex":["a",1]},"key":"value"}`|`{"another key":{"complex":["a",1]},"key":"value"}`|:white_check_mark:| |`$`|`42`|`42`|`42`|:white_check_mark:| |`$`|`false`|`false`|`false`|:white_check_mark:| |`$`|`true`|`true`|`true`|:white_check_mark:| -|`$[(@.length-1)]`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`fifth`|:no_entry:| - +|`$[(@.length-1)]`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`"fifth"`|:no_entry:| -## Union Tests +## Union Test |query|data|consensus|actual|match| |---|---|---|---|---| -|`$[0,1]`|`["first", "second", "third"]`|`[first second]`|`[first second]`|:white_check_mark:| -|`$[0,0]`|`["a"]`|`[a a]`|`[a a]`|:white_check_mark:| -|`$['a','a']`|`{"a":1}`|`[1 1]`|`[1 1]`|:white_check_mark:| +|`$[0,1]`|`["first", "second", "third"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$[0,0]`|`["a"]`|`["a","a"]`|`["a","a"]`|:white_check_mark:| +|`$['a','a']`|`{"a":1}`|`[1,1]`|`[1,1]`|:white_check_mark:| |`$[?(@.key<3),?(@.key>6)]`|`[{"key": 1}, {"key": 8}, {"key": 3}, {"key": 10}, {"key": 7}, {"key": 2}, {"key": 6}, {"key": 4}]`|none|`[]`|:question:| -|`$['key','another']`|`{ "key": "value", "another": "entry" }`|`[value entry]`|`[value entry]`|:white_check_mark:| -|`$['missing','key']`|`{ "key": "value", "another": "entry" }`|`[value]`|`[value]`|:white_check_mark:| -|`$[:]['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`[cc1 dd1 cc2 dd2]`|`[[cc1 dd1] [cc2 dd2]]`|:no_entry:| -|`$[0]['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`[cc1 dd1]`|`[cc1 dd1]`|:white_check_mark:| -|`$.*['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`[cc1 dd1 cc2 dd2]`|`[[cc1 dd1] [cc2 dd2]]`|:no_entry:| -|`$..['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"}, {"c": "cc2", "child": {"d": "dd2"}}, {"c": "cc3"}, {"d": "dd4"}, {"child": {"c": "cc5"}}]`|none|`[cc1 dd1 cc2 dd2 cc3 dd4 cc5]`|:question:| -|`$[4,1]`|`[1,2,3,4,5]`|`[5 2]`|`[5 2]`|:white_check_mark:| -|`$.*[0,:5]`|`{ "a": [ "string", null, true ], "b": [ false, "string", 5.4 ] }`|none|`nil`|:question:| -|`$[1:3,4]`|`[1,2,3,4,5]`|none|`nil`|:question:| -|`$[ 0 , 1 ]`|`["first", "second", "third"]`|`[first second]`|`[first second]`|:white_check_mark:| -|`$[*,1]`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`nil`|:white_check_mark:| +|`$['key','another']`|`{ "key": "value", "another": "entry" }`|`["value","entry"]`|`["value","entry"]`|:white_check_mark:| +|`$['missing','key']`|`{ "key": "value", "another": "entry" }`|`["value"]`|`["value"]`|:white_check_mark:| +|`$[:]['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`["cc1","dd1","cc2","dd2"]`|`[["cc1","dd1"],["cc2","dd2"]]`|:no_entry:| +|`$[0]['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`["cc1","dd1"]`|`["cc1","dd1"]`|:white_check_mark:| +|`$.*['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`|`["cc1","dd1","cc2","dd2"]`|`[["cc1","dd1"],["cc2","dd2"]]`|:no_entry:| +|`$..['c','d']`|`[{"c":"cc1","d":"dd1","e":"ee1"}, {"c": "cc2", "child": {"d": "dd2"}}, {"c": "cc3"}, {"d": "dd4"}, {"child": {"c": "cc5"}}]`|none|`["cc1","dd1","cc2","dd2","cc3","dd4","cc5"]`|:question:| +|`$[4,1]`|`[1,2,3,4,5]`|`[5,2]`|`[5,2]`|:white_check_mark:| +|`$.*[0,:5]`|`{ "a": [ "string", null, true ], "b": [ false, "string", 5.4 ] }`|none|`null`|:question:| +|`$[1:3,4]`|`[1,2,3,4,5]`|none|`null`|:question:| +|`$[ 0 , 1 ]`|`["first", "second", "third"]`|`["first","second"]`|`["first","second"]`|:white_check_mark:| +|`$[*,1]`|`["first", "second", "third", "forth", "fifth"]`|`nil`|`null`|:white_check_mark:| diff --git a/test/array_test.go b/test/array_test.go index 763bd6a..74cd087 100644 --- a/test/array_test.go +++ b/test/array_test.go @@ -5,302 +5,300 @@ import ( ) func Test_Array(t *testing.T) { + batchTest(t, arrayTests) +} - tests := []testData{ - { - query: "$[1:3]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"second", "third"}, - consensus: []interface{}{"second", "third"}, - }, - { - query: "$[0:5]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "second", "third", "forth", "fifth"}, - consensus: []interface{}{"first", "second", "third", "forth", "fifth"}, - }, - { - query: "$[7:10]", - data: `["first", "second", "third"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[1:3]", - data: `{":": 42, "more": "string", "a": 1, "b": 2, "c": 3, "1:3": "nice"}`, - expected: nil, - expectedError: "range: invalid token target. expected [array slice] got [map]", - consensus: nil, - }, - { - query: "$[1:10]", - data: `["first", "second", "third"]`, - expected: []interface{}{"second", "third"}, - expectedError: "", - consensus: []interface{}{"second", "third"}, - }, - { - query: "$[2:113667776004]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"third", "forth", "fifth"}, - expectedError: "", - consensus: []interface{}{"third", "forth", "fifth"}, - }, - { - query: "$[2:-113667776004:-1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{}, - expectedError: "", - consensus: consensusNone, - }, - { - query: "$[-113667776004:2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "second"}, - expectedError: "", - consensus: []interface{}{"first", "second"}, - }, - { - query: "$[113667776004:2:-1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[-4:-5]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[-4:-4]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[-4:-3]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{float64(4)}, - expectedError: "", - consensus: []interface{}{float64(4)}, - }, - { - query: "$[-4:1]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[-4:2]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[-4:3]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{float64(4)}, - expectedError: "", - consensus: []interface{}{float64(4)}, - }, - { - query: "$[3:0:-2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[7:3:-1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[0:3:-2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"third", "first"}, - expectedError: "", - consensus: consensusNone, - }, - { - query: "$[::-2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"fifth", "third", "first"}, - expectedError: "", - consensus: consensusNone, - }, - { - query: "$[1:]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"second", "third", "forth", "fifth"}, - expectedError: "", - consensus: []interface{}{"second", "third", "forth", "fifth"}, - }, - { - query: "$[3::-1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"fifth", "forth"}, - expectedError: "", - consensus: consensusNone, - }, - { - query: "$[:2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "second"}, - expectedError: "", - consensus: []interface{}{"first", "second"}, - }, - { - query: "$[:]", - data: `["first","second"]`, - expected: []interface{}{"first", "second"}, - expectedError: "", - consensus: []interface{}{"first", "second"}, - }, - { - query: "$[:]", - data: `{":": 42, "more": "string"}`, - expected: nil, - expectedError: "range: invalid token target. expected [array slice] got [map]", - consensus: nil, - }, - { - query: "$[::]", - data: `["first","second"]`, - expected: []interface{}{"first", "second"}, - expectedError: "", - consensus: []interface{}{"first", "second"}, - }, - { - query: "$[:2:-1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"second", "first"}, - expectedError: "", - consensus: consensusNone, - }, - { - query: "$[3:-4]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[3:-3]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[3:-2]", - data: `[2, "a", 4, 5, 100, "nice"]`, - expected: []interface{}{float64(5)}, - expectedError: "", - consensus: []interface{}{float64(5)}, - }, - { - query: "$[2:1]", - data: `["first", "second", "third", "forth"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[0:0]", - data: `["first", "second"]`, - expected: []interface{}{}, - expectedError: "", - consensus: []interface{}{}, - }, - { - query: "$[0:1]", - data: `["first", "second"]`, - expected: []interface{}{"first"}, - expectedError: "", - consensus: []interface{}{"first"}, - }, - { - query: "$[-1:]", - data: `["first", "second", "third"]`, - expected: []interface{}{"third"}, - expectedError: "", - consensus: []interface{}{"third"}, - }, - { - query: "$[-2:]", - data: `["first", "second", "third"]`, - expected: []interface{}{"second", "third"}, - expectedError: "", - consensus: []interface{}{"second", "third"}, - }, - { - query: "$[-4:]", - data: `["first", "second", "third"]`, - expected: []interface{}{"first", "second", "third"}, - expectedError: "", - consensus: []interface{}{"first", "second", "third"}, - }, - { - query: "$[0:3:2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "third"}, - expectedError: "", - consensus: []interface{}{"first", "third"}, - }, - { - query: "$[0:3:0]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: nil, - expectedError: "range: invalid token out of range", - consensus: consensusNone, - }, - { - query: "$[0:3:1]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "second", "third"}, - expectedError: "", - consensus: []interface{}{"first", "second", "third"}, - }, - { - query: "$[010:024:010]", - data: `[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]`, - expected: []interface{}{float64(10), float64(20)}, - expectedError: "", - consensus: []interface{}{float64(10), float64(20)}, - }, - { - query: "$[0:4:2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "third"}, - expectedError: "", - consensus: []interface{}{"first", "third"}, - }, - { - query: "$[1:3:]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"second", "third"}, - expectedError: "", - consensus: []interface{}{"second", "third"}, - }, - { - query: "$[::2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: []interface{}{"first", "third", "fifth"}, - expectedError: "", - consensus: []interface{}{"first", "third", "fifth"}, - }, - } - - batchTest(t, tests) - // printConsensusMatrix(tests) +var arrayTests []testData = []testData{ + { + query: "$[1:3]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"second", "third"}, + consensus: []interface{}{"second", "third"}, + }, + { + query: "$[0:5]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "second", "third", "forth", "fifth"}, + consensus: []interface{}{"first", "second", "third", "forth", "fifth"}, + }, + { + query: "$[7:10]", + data: `["first", "second", "third"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[1:3]", + data: `{":": 42, "more": "string", "a": 1, "b": 2, "c": 3, "1:3": "nice"}`, + expected: nil, + expectedError: "range: invalid token target. expected [array slice] got [map]", + consensus: nil, + }, + { + query: "$[1:10]", + data: `["first", "second", "third"]`, + expected: []interface{}{"second", "third"}, + expectedError: "", + consensus: []interface{}{"second", "third"}, + }, + { + query: "$[2:113667776004]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"third", "forth", "fifth"}, + expectedError: "", + consensus: []interface{}{"third", "forth", "fifth"}, + }, + { + query: "$[2:-113667776004:-1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{}, + expectedError: "", + consensus: consensusNone, + }, + { + query: "$[-113667776004:2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "second"}, + expectedError: "", + consensus: []interface{}{"first", "second"}, + }, + { + query: "$[113667776004:2:-1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[-4:-5]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[-4:-4]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[-4:-3]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{float64(4)}, + expectedError: "", + consensus: []interface{}{float64(4)}, + }, + { + query: "$[-4:1]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[-4:2]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[-4:3]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{float64(4)}, + expectedError: "", + consensus: []interface{}{float64(4)}, + }, + { + query: "$[3:0:-2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[7:3:-1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[0:3:-2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"third", "first"}, + expectedError: "", + consensus: consensusNone, + }, + { + query: "$[::-2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"fifth", "third", "first"}, + expectedError: "", + consensus: consensusNone, + }, + { + query: "$[1:]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"second", "third", "forth", "fifth"}, + expectedError: "", + consensus: []interface{}{"second", "third", "forth", "fifth"}, + }, + { + query: "$[3::-1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"fifth", "forth"}, + expectedError: "", + consensus: consensusNone, + }, + { + query: "$[:2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "second"}, + expectedError: "", + consensus: []interface{}{"first", "second"}, + }, + { + query: "$[:]", + data: `["first","second"]`, + expected: []interface{}{"first", "second"}, + expectedError: "", + consensus: []interface{}{"first", "second"}, + }, + { + query: "$[:]", + data: `{":": 42, "more": "string"}`, + expected: nil, + expectedError: "range: invalid token target. expected [array slice] got [map]", + consensus: nil, + }, + { + query: "$[::]", + data: `["first","second"]`, + expected: []interface{}{"first", "second"}, + expectedError: "", + consensus: []interface{}{"first", "second"}, + }, + { + query: "$[:2:-1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"second", "first"}, + expectedError: "", + consensus: consensusNone, + }, + { + query: "$[3:-4]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[3:-3]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[3:-2]", + data: `[2, "a", 4, 5, 100, "nice"]`, + expected: []interface{}{float64(5)}, + expectedError: "", + consensus: []interface{}{float64(5)}, + }, + { + query: "$[2:1]", + data: `["first", "second", "third", "forth"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[0:0]", + data: `["first", "second"]`, + expected: []interface{}{}, + expectedError: "", + consensus: []interface{}{}, + }, + { + query: "$[0:1]", + data: `["first", "second"]`, + expected: []interface{}{"first"}, + expectedError: "", + consensus: []interface{}{"first"}, + }, + { + query: "$[-1:]", + data: `["first", "second", "third"]`, + expected: []interface{}{"third"}, + expectedError: "", + consensus: []interface{}{"third"}, + }, + { + query: "$[-2:]", + data: `["first", "second", "third"]`, + expected: []interface{}{"second", "third"}, + expectedError: "", + consensus: []interface{}{"second", "third"}, + }, + { + query: "$[-4:]", + data: `["first", "second", "third"]`, + expected: []interface{}{"first", "second", "third"}, + expectedError: "", + consensus: []interface{}{"first", "second", "third"}, + }, + { + query: "$[0:3:2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "third"}, + expectedError: "", + consensus: []interface{}{"first", "third"}, + }, + { + query: "$[0:3:0]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: nil, + expectedError: "range: invalid token out of range", + consensus: consensusNone, + }, + { + query: "$[0:3:1]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "second", "third"}, + expectedError: "", + consensus: []interface{}{"first", "second", "third"}, + }, + { + query: "$[010:024:010]", + data: `[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]`, + expected: []interface{}{float64(10), float64(20)}, + expectedError: "", + consensus: []interface{}{float64(10), float64(20)}, + }, + { + query: "$[0:4:2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "third"}, + expectedError: "", + consensus: []interface{}{"first", "third"}, + }, + { + query: "$[1:3:]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"second", "third"}, + expectedError: "", + consensus: []interface{}{"second", "third"}, + }, + { + query: "$[::2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: []interface{}{"first", "third", "fifth"}, + expectedError: "", + consensus: []interface{}{"first", "third", "fifth"}, + }, } diff --git a/test/bracket_test.go b/test/bracket_test.go index 20dc53c..44f9f4b 100644 --- a/test/bracket_test.go +++ b/test/bracket_test.go @@ -5,353 +5,351 @@ import ( ) func Test_Bracket(t *testing.T) { + batchTest(t, bracketTests) +} - tests := []testData{ - { - query: "$['key']", - data: `{"key": "value"}`, - consensus: "value", - expected: "value", - expectedError: "", - }, - { - query: "$['missing']", - data: `{"key": "value"}`, - consensus: nil, - expected: nil, - expectedError: "key: invalid token key 'missing' not found", - }, - { - query: "$..[0]", - data: `[ "first", { "key": [ "first nested", { "more": [ { "nested": ["deepest", "second"] }, ["more", "values"] ] } ] } ]`, - consensus: []interface{}{ - "deepest", - "first nested", - "first", - "more", - map[string]interface{}{ - "nested": []interface{}{ - "deepest", - "second", - }, +var bracketTests []testData = []testData{ + { + query: "$['key']", + data: `{"key": "value"}`, + consensus: "value", + expected: "value", + expectedError: "", + }, + { + query: "$['missing']", + data: `{"key": "value"}`, + consensus: nil, + expected: nil, + expectedError: "key: invalid token key 'missing' not found", + }, + { + query: "$..[0]", + data: `[ "first", { "key": [ "first nested", { "more": [ { "nested": ["deepest", "second"] }, ["more", "values"] ] } ] } ]`, + consensus: []interface{}{ + "deepest", + "first nested", + "first", + "more", + map[string]interface{}{ + "nested": []interface{}{ + "deepest", + "second", }, }, - expected: []interface{}{ - "deepest", - "first nested", - "first", - "more", - map[string]interface{}{ - "nested": []interface{}{ - "deepest", - "second", - }, + }, + expected: []interface{}{ + "deepest", + "first nested", + "first", + "more", + map[string]interface{}{ + "nested": []interface{}{ + "deepest", + "second", }, }, }, - { - query: "$['ü']", - data: `{"ü": 42}`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token key 'ü' not found", - }, - { - query: "$['two.some']", - data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`, - expected: "42", - consensus: "42", - expectedError: "", - }, - { - query: `$["key"]`, - data: `{"key": "value"}`, - expected: nil, - consensus: "value", - expectedError: "invalid JSONPath query '$[\"key\"]' invalid token. '[\"key\"]' does not match any token format", - }, - { - query: "$[]", - data: `{"": 42, "''": 123, "\"\"": 222}`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$[]' invalid token. '[]' does not match any token format", - }, - { - query: "$['']", - data: `{"": 42, "''": 123, "\"\"": 222}`, - expected: float64(42), - consensus: float64(42), - expectedError: "", - }, - { - query: `$[""]`, - data: `{"": 42, "''": 123, "\"\"": 222}`, - expected: nil, - consensus: float64(42), - expectedError: "invalid JSONPath query '$[\"\"]' invalid token. '[\"\"]' does not match any token format", - }, - { - query: "$[-2]", - data: `["one element"]`, - expected: nil, - consensus: nil, - expectedError: "index: invalid token out of range", - }, - { - query: "$[2]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: "third", - consensus: "third", - expectedError: "", - }, - { - query: "$[0]", - data: `{ "0": "value" }`, - expected: nil, - consensus: nil, - expectedError: "index: invalid token target. expected [array slice] got [map]", - }, - { - query: "$[1]", - data: `["one element"]`, - expected: nil, - consensus: nil, - expectedError: "index: invalid token out of range", - }, - { - query: "$[0]", - data: `Hello World`, - expected: nil, - consensus: nil, - expectedError: "invalid data. unexpected type or nil", - }, - { - query: "$.*[1]", - data: `[[1], [2,3]]`, - expected: []interface{}{float64(3)}, - consensus: []interface{}{float64(3)}, - expectedError: "", - }, - { - query: "$[-1]", - data: `["first", "second", "third"]`, - expected: "third", - consensus: "third", - expectedError: "", - }, - { - query: "$[-1]", - data: `[]`, - expected: nil, - consensus: nil, - expectedError: "index: invalid token out of range", - }, - { - query: "$[0]", - data: `["first", "second", "third", "forth", "fifth"]`, - expected: "first", - consensus: "first", - expectedError: "", - }, - { - query: "$[':']", - data: `{ ":": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: "$[']']", - data: `{"]": 42}`, - expected: float64(42), - consensus: float64(42), - expectedError: "", - }, - { - query: "$['@']", - data: `{ "@": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: "$['.']", - data: `{ ".": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: "$['.*']", - data: `{"key": 42, ".*": 1, "": 10}`, - expected: float64(1), - consensus: float64(1), - expectedError: "", - }, - { - query: `$['"']`, - data: `{ "\"": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$['\\']`, - data: `{"\\":"value"}`, - expected: "value", - consensus: consensusNone, - expectedError: "", - }, - { - query: `$['\'']`, - data: `{"'":"value"}`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: "$['0']", - data: `{ "0": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: "$['$']", - data: `{ "$": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$[':@."$,*\'\\']`, - data: `{":@.\"$,*'\\": 42}`, - expected: float64(42), - consensus: consensusNone, - expectedError: "", - }, - { - query: `$['single'quote']`, - data: `{"single'quote":"value"}`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$['single'quote']' invalid token. '['single'quote']' does not match any token format", - }, - { - query: `$[',']`, - data: `{ ",": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$['*']`, - data: `{ "*": "value", "another": "entry" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$['*']`, - data: `{ "another": "entry" }`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token key '*' not found", - }, - { - query: `$[ 'a' ]`, - data: `{" a": 1, "a": 2, " a ": 3, "a ": 4, " 'a' ": 5, " 'a": 6, "a' ": 7, " \"a\" ": 8, "\"a\"": 9}`, - expected: float64(2), - consensus: float64(2), - expectedError: "", - }, - { - query: `$['ni.*']`, - data: `{"nice": 42, "ni.*": 1, "mice": 100}`, - expected: float64(1), - consensus: float64(1), - expectedError: "", - }, - { - query: `$['two'.'some']`, - data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42", "two'.'some": "43" }`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$['two'.'some']' invalid token. '['two'.'some']' does not match any token format", - }, - { - query: `$[two.some]`, - data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$[two.some]' invalid token. '[two.some]' does not match any token format", - }, - { - query: `$[*]`, - data: `[ "string", 42, { "key": "value" }, [0, 1] ]`, - expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - expectedError: "", - }, - { - query: `$[*]`, - data: `[]`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$[*]`, - data: `{}`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$[*]`, - data: `[ 40, null, 42 ]`, - expected: []interface{}{float64(40), nil, float64(42)}, - consensus: []interface{}{float64(40), nil, float64(42)}, - expectedError: "", - }, - { - query: `$[*]`, - data: `{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`, - expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - expectedError: "", - }, - { - query: `$[0:2][*]`, - data: `[[1, 2], ["a", "b"], [0, 0]]`, - expected: []interface{}{[]interface{}{float64(1), float64(2)}, []interface{}{"a", "b"}}, - consensus: []interface{}{float64(1), float64(2), "a", "b"}, - expectedError: "", - }, - { - query: `$[*].bar[*]`, - data: `[{"bar": [42]}]`, - expected: []interface{}{[]interface{}{float64(42)}}, - consensus: []interface{}{float64(42)}, - expectedError: "", - }, - { - query: `$..[*]`, - data: `{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`, - expected: []interface{}{"value", map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, "string", float64(0), float64(1)}, - consensus: []interface{}{"value", map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, "string", float64(0), float64(1)}, - expectedError: "", - }, - { - query: `$[key]`, - data: `{ "key": "value" }`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$[key]' invalid token. '[key]' does not match any token format", - }, - } - - batchTest(t, tests) - // printConsensusMatrix(tests) + }, + { + query: "$['ü']", + data: `{"ü": 42}`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token key 'ü' not found", + }, + { + query: "$['two.some']", + data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`, + expected: "42", + consensus: "42", + expectedError: "", + }, + { + query: `$["key"]`, + data: `{"key": "value"}`, + expected: nil, + consensus: "value", + expectedError: "invalid JSONPath query '$[\"key\"]' invalid token. '[\"key\"]' does not match any token format", + }, + { + query: "$[]", + data: `{"": 42, "''": 123, "\"\"": 222}`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$[]' invalid token. '[]' does not match any token format", + }, + { + query: "$['']", + data: `{"": 42, "''": 123, "\"\"": 222}`, + expected: float64(42), + consensus: float64(42), + expectedError: "", + }, + { + query: `$[""]`, + data: `{"": 42, "''": 123, "\"\"": 222}`, + expected: nil, + consensus: float64(42), + expectedError: "invalid JSONPath query '$[\"\"]' invalid token. '[\"\"]' does not match any token format", + }, + { + query: "$[-2]", + data: `["one element"]`, + expected: nil, + consensus: nil, + expectedError: "index: invalid token out of range", + }, + { + query: "$[2]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: "third", + consensus: "third", + expectedError: "", + }, + { + query: "$[0]", + data: `{ "0": "value" }`, + expected: nil, + consensus: nil, + expectedError: "index: invalid token target. expected [array slice] got [map]", + }, + { + query: "$[1]", + data: `["one element"]`, + expected: nil, + consensus: nil, + expectedError: "index: invalid token out of range", + }, + { + query: "$[0]", + data: `Hello World`, + expected: nil, + consensus: nil, + expectedError: "invalid data. unexpected type or nil", + }, + { + query: "$.*[1]", + data: `[[1], [2,3]]`, + expected: []interface{}{float64(3)}, + consensus: []interface{}{float64(3)}, + expectedError: "", + }, + { + query: "$[-1]", + data: `["first", "second", "third"]`, + expected: "third", + consensus: "third", + expectedError: "", + }, + { + query: "$[-1]", + data: `[]`, + expected: nil, + consensus: nil, + expectedError: "index: invalid token out of range", + }, + { + query: "$[0]", + data: `["first", "second", "third", "forth", "fifth"]`, + expected: "first", + consensus: "first", + expectedError: "", + }, + { + query: "$[':']", + data: `{ ":": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: "$[']']", + data: `{"]": 42}`, + expected: float64(42), + consensus: float64(42), + expectedError: "", + }, + { + query: "$['@']", + data: `{ "@": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: "$['.']", + data: `{ ".": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: "$['.*']", + data: `{"key": 42, ".*": 1, "": 10}`, + expected: float64(1), + consensus: float64(1), + expectedError: "", + }, + { + query: `$['"']`, + data: `{ "\"": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$['\\']`, + data: `{"\\":"value"}`, + expected: "value", + consensus: consensusNone, + expectedError: "", + }, + { + query: `$['\'']`, + data: `{"'":"value"}`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: "$['0']", + data: `{ "0": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: "$['$']", + data: `{ "$": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$[':@."$,*\'\\']`, + data: `{":@.\"$,*'\\": 42}`, + expected: float64(42), + consensus: consensusNone, + expectedError: "", + }, + { + query: `$['single'quote']`, + data: `{"single'quote":"value"}`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$['single'quote']' invalid token. '['single'quote']' does not match any token format", + }, + { + query: `$[',']`, + data: `{ ",": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$['*']`, + data: `{ "*": "value", "another": "entry" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$['*']`, + data: `{ "another": "entry" }`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token key '*' not found", + }, + { + query: `$[ 'a' ]`, + data: `{" a": 1, "a": 2, " a ": 3, "a ": 4, " 'a' ": 5, " 'a": 6, "a' ": 7, " \"a\" ": 8, "\"a\"": 9}`, + expected: float64(2), + consensus: float64(2), + expectedError: "", + }, + { + query: `$['ni.*']`, + data: `{"nice": 42, "ni.*": 1, "mice": 100}`, + expected: float64(1), + consensus: float64(1), + expectedError: "", + }, + { + query: `$['two'.'some']`, + data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42", "two'.'some": "43" }`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$['two'.'some']' invalid token. '['two'.'some']' does not match any token format", + }, + { + query: `$[two.some]`, + data: `{ "one": {"key": "value"}, "two": {"some": "more", "key": "other value"}, "two.some": "42" }`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$[two.some]' invalid token. '[two.some]' does not match any token format", + }, + { + query: `$[*]`, + data: `[ "string", 42, { "key": "value" }, [0, 1] ]`, + expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + expectedError: "", + }, + { + query: `$[*]`, + data: `[]`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$[*]`, + data: `{}`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$[*]`, + data: `[ 40, null, 42 ]`, + expected: []interface{}{float64(40), nil, float64(42)}, + consensus: []interface{}{float64(40), nil, float64(42)}, + expectedError: "", + }, + { + query: `$[*]`, + data: `{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`, + expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + expectedError: "", + }, + { + query: `$[0:2][*]`, + data: `[[1, 2], ["a", "b"], [0, 0]]`, + expected: []interface{}{[]interface{}{float64(1), float64(2)}, []interface{}{"a", "b"}}, + consensus: []interface{}{float64(1), float64(2), "a", "b"}, + expectedError: "", + }, + { + query: `$[*].bar[*]`, + data: `[{"bar": [42]}]`, + expected: []interface{}{[]interface{}{float64(42)}}, + consensus: []interface{}{float64(42)}, + expectedError: "", + }, + { + query: `$..[*]`, + data: `{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`, + expected: []interface{}{"value", map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, "string", float64(0), float64(1)}, + consensus: []interface{}{"value", map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, "string", float64(0), float64(1)}, + expectedError: "", + }, + { + query: `$[key]`, + data: `{ "key": "value" }`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$[key]' invalid token. '[key]' does not match any token format", + }, } diff --git a/test/dot_test.go b/test/dot_test.go index f4f7c17..4703c95 100644 --- a/test/dot_test.go +++ b/test/dot_test.go @@ -3,372 +3,371 @@ package test import "testing" func Test_Dot(t *testing.T) { - tests := []testData{ - { - query: `@.a`, - data: `{"a": 1}`, - expected: float64(1), - consensus: nil, - }, - { - query: `$.['key']`, - data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.["key"]`, - data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$.[\"key\"]' invalid token. '[\"key\"]' does not match any token format", - }, - { - query: `$.[key]`, - data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$.[key]' invalid token. '[key]' does not match any token format", - }, - { - query: `$.key`, - data: `{ "key": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.key`, - data: `[0, 1]`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token target. expected [map] got [slice]", - }, - { - query: `$.key`, - data: `{ "key": ["first", "second"] }`, - expected: []interface{}{"first", "second"}, - consensus: []interface{}{"first", "second"}, - expectedError: "", - }, - { - query: `$.id`, - data: `[{"id": 2}]`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token target. expected [map] got [slice]", - }, - { - query: `$.key`, - data: `{ "key": {} }`, - expected: map[string]interface{}{}, - consensus: map[string]interface{}{}, - expectedError: "", - }, - { - query: `$.key`, - data: `{ "key": null }`, - expected: nil, - consensus: nil, - expectedError: "", - }, - { - query: `$.missing`, - data: `{"key": "value"}`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token key 'missing' not found", - }, - { - query: `$[0:2].key`, - data: `[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`, - expected: []interface{}{"ey", "bee"}, - consensus: []interface{}{"ey", "bee"}, - expectedError: "", - }, - { - query: `$..[1].key`, - data: `{ "k": [{"key": "some value"}, {"key": 42}], "kk": [[{"key": 100}, {"key": 200}, {"key": 300}], [{"key": 400}, {"key": 500}, {"key": 600}]], "key": [0, 1] }`, - expected: []interface{}{float64(200), float64(42), float64(500)}, - consensus: []interface{}{float64(200), float64(42), float64(500)}, - expectedError: "", - }, - { - query: `$[*].a`, - data: `[{"a": 1},{"a": 1}]`, - expected: []interface{}{float64(1), float64(1)}, - consensus: []interface{}{float64(1), float64(1)}, - expectedError: "", - }, - { - query: `$[*].a`, - data: `[{"a": 1}]`, - expected: []interface{}{float64(1)}, - consensus: []interface{}{float64(1)}, - expectedError: "", - }, - { - query: `$[*].a`, - data: `[{"a": 1},{"b": 1}]`, - expected: []interface{}{float64(1)}, - consensus: []interface{}{float64(1)}, - expectedError: "", - }, - { - query: `$[?(@.id==42)].name`, - data: `[{"id": 42, "name": "forty-two"}, {"id": 1, "name": "one"}]`, - expected: []interface{}{"forty-two"}, - consensus: []interface{}{"forty-two"}, - expectedError: "", - }, - { - query: `$..key`, - data: `{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`, - expected: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, - consensus: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, - expectedError: "", - }, - { - query: `$.store..price`, - data: `{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }`, - expected: []interface{}{float64(12.99), float64(19.95), float64(22.99), float64(8.95), float64(8.99)}, - consensus: []interface{}{float64(12.99), float64(19.95), float64(22.99), float64(8.95), float64(8.99)}, - expectedError: "", - }, - { - query: `$...key`, - data: `{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`, - expected: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, - consensus: []interface{}{"russian dolls", "something", "top", "value"}, - expectedError: "", - }, - { - query: `$[0,2].key`, - data: `[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`, - expected: []interface{}{"ey", "see"}, - consensus: []interface{}{"ey", "see"}, - expectedError: "", - }, - { - query: `$['one','three'].key`, - data: `{ "one": {"key": "value"}, "two": {"k": "v"}, "three": {"some": "more", "key": "other value"} }`, - expected: []interface{}{"value", "other value"}, - consensus: []interface{}{"value", "other value"}, - expectedError: "", - }, - { - query: `$.key-dash`, - data: `{ "key": 42, "key-": 43, "-": 44, "dash": 45, "-dash": 46, "": 47, "key-dash": "value", "something": "else" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$."key"`, - data: `{ "key": "value", "\"key\"": 42 }`, - expected: float64(42), - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.."key"`, - data: `{ "object": { "key": "value", "\"key\"": 100, "array": [ {"key": "something", "\"key\"": 0}, {"key": {"key": "russian dolls"}, "\"key\"": {"\"key\"": 99}} ] }, "key": "top", "\"key\"": 42 }`, - expected: []interface{}{float64(0), float64(42), float64(99), float64(100), map[string]interface{}{`"key"`: float64(99)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.`, - data: `{"key": 42, "": 9001, "''": "nice"}`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$.' invalid token. token string is empty", - }, - { - query: `$.in`, - data: `{ "in": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.length`, - data: `{ "length": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.length`, - data: `[4, 5, 6]`, - expected: int64(3), - consensus: nil, - expectedError: "", - }, - { - query: `$.null`, - data: `{ "null": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.true`, - data: `{ "true": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.$`, - data: `{ "$": "value" }`, - expected: map[string]interface{}{"$": "value"}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.屬性`, - data: `{ "屬性": "value" }`, - expected: "value", - consensus: "value", - expectedError: "", - }, - { - query: `$.2`, - data: `["first", "second", "third", "forth", "fifth"]`, - expected: nil, - consensus: consensusNone, - expectedError: "key: invalid token target. expected [map] got [slice]", - }, - { - query: `$.2`, - data: `{"a": "first", "2": "second", "b": "third"}`, - expected: "second", - consensus: "second", - expectedError: "", - }, - { - query: `$.-1`, - data: `["first", "second", "third", "forth", "fifth"]`, - expected: nil, - consensus: nil, - expectedError: "key: invalid token target. expected [map] got [slice]", - }, - { - query: `$.'key'`, - data: `{ "key": "value", "'key'": 42 }`, - expected: float64(42), - consensus: consensusNone, - expectedError: "", - }, - { - query: `$..'key'`, - data: `{ "object": { "key": "value", "'key'": 100, "array": [ {"key": "something", "'key'": 0}, {"key": {"key": "russian dolls"}, "'key'": {"'key'": 99}} ] }, "key": "top", "'key'": 42 }`, - expected: []interface{}{float64(42), float64(100), float64(0), map[string]interface{}{"'key'": float64(99)}, float64(99)}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.'some.key'`, - data: `{"some.key": 42, "some": {"key": "value"}, "'some.key'": 43}`, - expected: float64(43), - consensus: consensusNone, - expectedError: "", - }, - { - query: `$. a`, - data: `{" a": 1, "a": 2, " a ": 3, "": 4}`, - expected: float64(2), - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.*`, - data: `[ "string", 42, { "key": "value" }, [0, 1] ]`, - expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, - expectedError: "", - }, - { - query: `$.*`, - data: `[]`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$.*`, - data: `{}`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$.*`, - data: `{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`, - expected: []interface{}{"string", float64(42), []interface{}{float64(0), float64(1)}, map[string]interface{}{"key": "value"}}, - consensus: []interface{}{"string", float64(42), []interface{}{float64(0), float64(1)}, map[string]interface{}{"key": "value"}}, - expectedError: "", - }, - { - query: `$.*.bar.*`, - data: `[{"bar": [42]}]`, - expected: []interface{}{[]interface{}{float64(42)}}, - consensus: []interface{}{float64(42)}, - expectedError: "", - }, - { - query: `$.*.*`, - data: `[[1, 2, 3], [4, 5, 6]]`, - expected: []interface{}{[]interface{}{float64(1), float64(2), float64(3)}, []interface{}{float64(4), float64(5), float64(6)}}, - consensus: []interface{}{float64(1), float64(2), float64(3), float64(4), float64(5), float64(6)}, - expectedError: "", - }, - { - query: `$..*`, - data: `{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`, - expected: []interface{}{"string", "value", float64(0), float64(1), []interface{}{float64(0), float64(1)}, map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}}, - consensus: []interface{}{"string", "value", float64(0), float64(1), []interface{}{float64(0), float64(1)}, map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}}, - expectedError: "", - }, - { - query: `$..*`, - data: `[ 40, null, 42 ]`, - expected: []interface{}{float64(40), float64(42), nil}, - consensus: []interface{}{float64(40), float64(42), nil}, - expectedError: "", - }, - { - query: `$..*`, - data: `42`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$a`, - data: `{"a": 1, "$a": 2}`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$a' unexpected token 'a' at index 1", - }, - { - query: `.key`, - data: `{ "key": "value" }`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '.key' unexpected token '.' at index 0", - }, - { - query: `key`, - data: `{ "key": "value" }`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query 'key' unexpected token 'k' at index 0", - }, - } + batchTest(t, dotTests) +} - batchTest(t, tests) - // printConsensusMatrix(tests) +var dotTests []testData = []testData{ + { + query: `@.a`, + data: `{"a": 1}`, + expected: float64(1), + consensus: nil, + }, + { + query: `$.['key']`, + data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.["key"]`, + data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$.[\"key\"]' invalid token. '[\"key\"]' does not match any token format", + }, + { + query: `$.[key]`, + data: `{ "key": "value", "other": {"key": [{"key": 42}]} }`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$.[key]' invalid token. '[key]' does not match any token format", + }, + { + query: `$.key`, + data: `{ "key": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.key`, + data: `[0, 1]`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token target. expected [map] got [slice]", + }, + { + query: `$.key`, + data: `{ "key": ["first", "second"] }`, + expected: []interface{}{"first", "second"}, + consensus: []interface{}{"first", "second"}, + expectedError: "", + }, + { + query: `$.id`, + data: `[{"id": 2}]`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token target. expected [map] got [slice]", + }, + { + query: `$.key`, + data: `{ "key": {} }`, + expected: map[string]interface{}{}, + consensus: map[string]interface{}{}, + expectedError: "", + }, + { + query: `$.key`, + data: `{ "key": null }`, + expected: nil, + consensus: nil, + expectedError: "", + }, + { + query: `$.missing`, + data: `{"key": "value"}`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token key 'missing' not found", + }, + { + query: `$[0:2].key`, + data: `[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`, + expected: []interface{}{"ey", "bee"}, + consensus: []interface{}{"ey", "bee"}, + expectedError: "", + }, + { + query: `$..[1].key`, + data: `{ "k": [{"key": "some value"}, {"key": 42}], "kk": [[{"key": 100}, {"key": 200}, {"key": 300}], [{"key": 400}, {"key": 500}, {"key": 600}]], "key": [0, 1] }`, + expected: []interface{}{float64(200), float64(42), float64(500)}, + consensus: []interface{}{float64(200), float64(42), float64(500)}, + expectedError: "", + }, + { + query: `$[*].a`, + data: `[{"a": 1},{"a": 1}]`, + expected: []interface{}{float64(1), float64(1)}, + consensus: []interface{}{float64(1), float64(1)}, + expectedError: "", + }, + { + query: `$[*].a`, + data: `[{"a": 1}]`, + expected: []interface{}{float64(1)}, + consensus: []interface{}{float64(1)}, + expectedError: "", + }, + { + query: `$[*].a`, + data: `[{"a": 1},{"b": 1}]`, + expected: []interface{}{float64(1)}, + consensus: []interface{}{float64(1)}, + expectedError: "", + }, + { + query: `$[?(@.id==42)].name`, + data: `[{"id": 42, "name": "forty-two"}, {"id": 1, "name": "one"}]`, + expected: []interface{}{"forty-two"}, + consensus: []interface{}{"forty-two"}, + expectedError: "", + }, + { + query: `$..key`, + data: `{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`, + expected: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, + consensus: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, + expectedError: "", + }, + { + query: `$.store..price`, + data: `{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }`, + expected: []interface{}{float64(12.99), float64(19.95), float64(22.99), float64(8.95), float64(8.99)}, + consensus: []interface{}{float64(12.99), float64(19.95), float64(22.99), float64(8.95), float64(8.99)}, + expectedError: "", + }, + { + query: `$...key`, + data: `{ "object": { "key": "value", "array": [ {"key": "something"}, {"key": {"key": "russian dolls"}} ] }, "key": "top" }`, + expected: []interface{}{"russian dolls", "something", "top", "value", map[string]interface{}{"key": "russian dolls"}}, + consensus: []interface{}{"russian dolls", "something", "top", "value"}, + expectedError: "", + }, + { + query: `$[0,2].key`, + data: `[{"key": "ey"}, {"key": "bee"}, {"key": "see"}]`, + expected: []interface{}{"ey", "see"}, + consensus: []interface{}{"ey", "see"}, + expectedError: "", + }, + { + query: `$['one','three'].key`, + data: `{ "one": {"key": "value"}, "two": {"k": "v"}, "three": {"some": "more", "key": "other value"} }`, + expected: []interface{}{"value", "other value"}, + consensus: []interface{}{"value", "other value"}, + expectedError: "", + }, + { + query: `$.key-dash`, + data: `{ "key": 42, "key-": 43, "-": 44, "dash": 45, "-dash": 46, "": 47, "key-dash": "value", "something": "else" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$."key"`, + data: `{ "key": "value", "\"key\"": 42 }`, + expected: float64(42), + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.."key"`, + data: `{ "object": { "key": "value", "\"key\"": 100, "array": [ {"key": "something", "\"key\"": 0}, {"key": {"key": "russian dolls"}, "\"key\"": {"\"key\"": 99}} ] }, "key": "top", "\"key\"": 42 }`, + expected: []interface{}{float64(0), float64(42), float64(99), float64(100), map[string]interface{}{`"key"`: float64(99)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.`, + data: `{"key": 42, "": 9001, "''": "nice"}`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$.' invalid token. token string is empty", + }, + { + query: `$.in`, + data: `{ "in": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.length`, + data: `{ "length": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.length`, + data: `[4, 5, 6]`, + expected: int64(3), + consensus: nil, + expectedError: "", + }, + { + query: `$.null`, + data: `{ "null": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.true`, + data: `{ "true": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.$`, + data: `{ "$": "value" }`, + expected: map[string]interface{}{"$": "value"}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.屬性`, + data: `{ "屬性": "value" }`, + expected: "value", + consensus: "value", + expectedError: "", + }, + { + query: `$.2`, + data: `["first", "second", "third", "forth", "fifth"]`, + expected: nil, + consensus: consensusNone, + expectedError: "key: invalid token target. expected [map] got [slice]", + }, + { + query: `$.2`, + data: `{"a": "first", "2": "second", "b": "third"}`, + expected: "second", + consensus: "second", + expectedError: "", + }, + { + query: `$.-1`, + data: `["first", "second", "third", "forth", "fifth"]`, + expected: nil, + consensus: nil, + expectedError: "key: invalid token target. expected [map] got [slice]", + }, + { + query: `$.'key'`, + data: `{ "key": "value", "'key'": 42 }`, + expected: float64(42), + consensus: consensusNone, + expectedError: "", + }, + { + query: `$..'key'`, + data: `{ "object": { "key": "value", "'key'": 100, "array": [ {"key": "something", "'key'": 0}, {"key": {"key": "russian dolls"}, "'key'": {"'key'": 99}} ] }, "key": "top", "'key'": 42 }`, + expected: []interface{}{float64(42), float64(100), float64(0), map[string]interface{}{"'key'": float64(99)}, float64(99)}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.'some.key'`, + data: `{"some.key": 42, "some": {"key": "value"}, "'some.key'": 43}`, + expected: float64(43), + consensus: consensusNone, + expectedError: "", + }, + { + query: `$. a`, + data: `{" a": 1, "a": 2, " a ": 3, "": 4}`, + expected: float64(2), + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.*`, + data: `[ "string", 42, { "key": "value" }, [0, 1] ]`, + expected: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + consensus: []interface{}{"string", float64(42), map[string]interface{}{"key": "value"}, []interface{}{float64(0), float64(1)}}, + expectedError: "", + }, + { + query: `$.*`, + data: `[]`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$.*`, + data: `{}`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$.*`, + data: `{ "some": "string", "int": 42, "object": { "key": "value" }, "array": [0, 1] }`, + expected: []interface{}{"string", float64(42), []interface{}{float64(0), float64(1)}, map[string]interface{}{"key": "value"}}, + consensus: []interface{}{"string", float64(42), []interface{}{float64(0), float64(1)}, map[string]interface{}{"key": "value"}}, + expectedError: "", + }, + { + query: `$.*.bar.*`, + data: `[{"bar": [42]}]`, + expected: []interface{}{[]interface{}{float64(42)}}, + consensus: []interface{}{float64(42)}, + expectedError: "", + }, + { + query: `$.*.*`, + data: `[[1, 2, 3], [4, 5, 6]]`, + expected: []interface{}{[]interface{}{float64(1), float64(2), float64(3)}, []interface{}{float64(4), float64(5), float64(6)}}, + consensus: []interface{}{float64(1), float64(2), float64(3), float64(4), float64(5), float64(6)}, + expectedError: "", + }, + { + query: `$..*`, + data: `{ "key": "value", "another key": { "complex": "string", "primitives": [0, 1] } }`, + expected: []interface{}{"string", "value", float64(0), float64(1), []interface{}{float64(0), float64(1)}, map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}}, + consensus: []interface{}{"string", "value", float64(0), float64(1), []interface{}{float64(0), float64(1)}, map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}}, + expectedError: "", + }, + { + query: `$..*`, + data: `[ 40, null, 42 ]`, + expected: []interface{}{float64(40), float64(42), nil}, + consensus: []interface{}{float64(40), float64(42), nil}, + expectedError: "", + }, + { + query: `$..*`, + data: `42`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$a`, + data: `{"a": 1, "$a": 2}`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$a' unexpected token 'a' at index 1", + }, + { + query: `.key`, + data: `{ "key": "value" }`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '.key' unexpected token '.' at index 0", + }, + { + query: `key`, + data: `{ "key": "value" }`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query 'key' unexpected token 'k' at index 0", + }, } diff --git a/test/filter_test.go b/test/filter_test.go index 7d96162..6a80ec0 100644 --- a/test/filter_test.go +++ b/test/filter_test.go @@ -3,663 +3,661 @@ package test import "testing" func Test_Filter(t *testing.T) { + batchTest(t, filterTests) +} - tests := []testData{ - { - query: `$[?(@.key)]`, - data: `{"key": 42, "another": {"key": 1}}`, - expected: []interface{}{map[string]interface{}{"key": float64(1)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$..*[?(@.id>2)]`, - data: `[ { "complext": { "one": [ { "name": "first", "id": 1 }, { "name": "next", "id": 2 }, { "name": "another", "id": 3 }, { "name": "more", "id": 4 } ], "more": { "name": "next to last", "id": 5 } } }, { "name": "last", "id": 6 } ]`, - expected: []interface{}{ - []interface{}{}, - []interface{}{}, - []interface{}{map[string]interface{}{"id": float64(5), "name": "next to last"}}, - []interface{}{map[string]interface{}{"id": float64(3), "name": "another"}, map[string]interface{}{"id": float64(4), "name": "more"}}, - []interface{}{}, - []interface{}{}, - []interface{}{}, - []interface{}{}, - []interface{}{}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$..[?(@.id==2)]`, - data: `{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`, - expected: []interface{}{ - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key+50==100)]`, - data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key+50": 100}]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(50)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>42 && @.key<44)]`, - data: `[ {"key": 42}, {"key": 43}, {"key": 44} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(43)}}, - consensus: []interface{}{map[string]interface{}{"key": float64(43)}}, - expectedError: "", - }, - { - query: `$[?(@.key>0 && false)]`, - data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>0 && true)]`, - data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>43 || @.key<43)]`, - data: `[ {"key": 42}, {"key": 43}, {"key": 44} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(42)}, map[string]interface{}{"key": float64(44)}}, - consensus: []interface{}{map[string]interface{}{"key": float64(42)}, map[string]interface{}{"key": float64(44)}}, - expectedError: "", - }, - { - query: `$[?(@.key>0 || false)]`, - data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>0 || true)]`, - data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}, map[string]interface{}{"key": float64(-1)}, map[string]interface{}{"key": float64(0)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@['key']==42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(42)}}, - consensus: []interface{}{map[string]interface{}{"key": float64(42)}}, - expectedError: "", - }, - { - query: `$[?(@['@key']==42)]`, - data: `[ {"@key": 0}, {"@key": 42}, {"key": 42}, {"@key": 43}, {"some": "value"} ]`, - expected: []interface{}{map[string]interface{}{"@key": float64(42)}}, - consensus: []interface{}{map[string]interface{}{"@key": float64(42)}}, - expectedError: "", - }, - { - query: `$[?(@[-1]==2)]`, - data: `[[2, 3], ["a"], [0, 2], [2]]`, - expected: []interface{}{[]interface{}{float64(0), float64(2)}, []interface{}{float64(2)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@[1]=='b')]`, - data: `[["a", "b"], ["x", "y"]]`, - expected: []interface{}{[]interface{}{"a", "b"}}, - consensus: []interface{}{[]interface{}{"a", "b"}}, - expectedError: "", - }, - { - query: `$[?(@[1]=='b')]`, - data: `{"1": ["a", "b"], "2": ["x", "y"]}`, - expected: []interface{}{[]interface{}{"a", "b"}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@)]`, - data: `[ "some value", null, "value", 0, 1, -1, "", [], {}, false, true ]`, - expected: []interface{}{"some value", "value", float64(0), float64(1), float64(-1), true}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.a && (@.b || @.c))]`, - data: `[ { "a": true }, { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "c": true }, { "b": true } ]`, - expected: []interface{}{}, // TODO : this should be different - consensus: consensusNone, - expectedError: "", - }, - { - query: `[?(@.a && @.b || @.c)]`, - data: `[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '[?(@.a && @.b || @.c)]' unexpected token '[' at index 0", - }, - { - query: `$[?(@.key/10==5)]`, - data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key/10": 5}]`, - expected: []interface{}{map[string]interface{}{"key": float64(50)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key-dash == 'value')]`, - data: `[ { "key-dash": "value" } ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.2 == 'second')]`, - data: `[{"a": "first", "2": "second", "b": "third"}]`, - expected: []interface{}{map[string]interface{}{"2": "second", "a": "first", "b": "third"}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.2 == 'third')]`, - data: `[["first", "second", "third", "forth", "fifth"]] `, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?()]`, - data: `[1, {"key": 42}, "value", null]`, - expected: nil, - consensus: nil, - expectedError: "invalid expression. is empty", - }, - { - query: `$[?(@.key==42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, - expected: []interface{}{map[string]interface{}{"key": float64(42)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@==42)]`, - data: `[ 0, 42, -1, 41, 43, 42.0001, 41.9999, null, 100 ]`, - expected: []interface{}{}, // TODO : doesn't match as float == int, needs fixed - consensus: []interface{}{float64(42)}, - expectedError: "", - }, - { - query: `$[?(@.key==43)]`, - data: `[{"key": 42}]`, - expected: []interface{}{}, - consensus: []interface{}{}, - expectedError: "", - }, - { - query: `$[?(@.key==42)]`, - data: `{ "a": {"key": 0}, "b": {"key": 42}, "c": {"key": -1}, "d": {"key": 41}, "e": {"key": 43}, "f": {"key": 42.0001}, "g": {"key": 41.9999}, "h": {"key": 100}, "i": {"some": "value"} }`, - expected: []interface{}{map[string]interface{}{"key": float64(42)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.id==2)]`, - data: `{"id": 2}`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.d==["v1","v2"])]`, - data: `[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`, - expected: []interface{}{}, // TODO : doesn't know [] is array - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@[0:1]==[1])]`, - data: `[[1, 2, 3], [1], [2, 3], 1, 2]`, - expected: []interface{}{}, // TODO : doesn't know [] is array - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.*==[1,2])]`, - data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, - expected: []interface{}{}, // TODO : need to parse [1,2] as array - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.d==['v1','v2'])]`, - data: `[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`, - expected: []interface{}{}, // TODO : need to parse ['v1','v2'] as array - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?((@.key<44)==false)]`, - data: `[{"key": 42}, {"key": 43}, {"key": 44}]`, - expected: []interface{}{map[string]interface{}{"key": float64(44)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key==false)]`, - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{map[string]interface{}{"key": false}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key==null)]`, // TODO : nil/null support - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@[0:1]==1)]`, // TODO array in expression support - data: `[[1, 2, 3], [1], [2, 3], 1, 2]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@[*]==2)]`, // TODO array in expression support - data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.*==2)]`, - data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key==-0.123e2)]`, - data: `[{"key": -12.3}, {"key": -0.123}, {"key": -12}, {"key": 12.3}, {"key": 2}, {"key": "-0.123e2"}]`, - expected: []interface{}{map[string]interface{}{"key": float64(-12.3)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key==010)]`, // TODO : is this expected - data: `[{"key": "010"}, {"key": "10"}, {"key": 10}, {"key": 0}, {"key": 8}]`, - expected: []interface{}{map[string]interface{}{"key": float64(8)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.d=={"k":"v"})]`, // TODO: will not parse as map - data: `[ { "d": { "k": "v" } }, { "d": { "a": "b" } }, { "d": "k" }, { "d": "v" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "[object Object]" }, { "d": "{\"k\": \"v\"}" }, { "d": "{\"k\":\"v\"}" }, "v" ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key=="value")]`, - data: `[ {"key": "some"}, {"key": "value"}, {"key": null}, {"key": 0}, {"key": 1}, {"key": -1}, {"key": ""}, {"key": {}}, {"key": []}, {"key": "valuemore"}, {"key": "morevalue"}, {"key": ["value"]}, {"key": {"some": "value"}}, {"key": {"key": "value"}}, {"some": "value"} ]`, - expected: []interface{}{map[string]interface{}{"key": "value"}}, - consensus: []interface{}{map[string]interface{}{"key": "value"}}, - expectedError: "", - }, - { - query: `$[?(@.key=="Motörhead")]`, - data: `[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`, - expected: []interface{}{map[string]interface{}{"key": "Mot\u00f6rhead"}}, - consensus: []interface{}{map[string]interface{}{"key": "Mot\u00f6rhead"}}, - expectedError: "", - }, - { - query: `$[?(@.key=="hi@example.com")]`, // TODO: double quotes in filters - data: `[ {"key": "some"}, {"key": "value"}, {"key": "hi@example.com"} ]`, - expected: []interface{}{}, - consensus: []interface{}{map[string]interface{}{"key": "hi@example.com"}}, - expectedError: "", - }, - { - query: `$[?(@.key=="some.value")]`, - data: `[ {"key": "some"}, {"key": "value"}, {"key": "some.value"} ]`, - expected: []interface{}{map[string]interface{}{"key": "some.value"}}, - consensus: []interface{}{map[string]interface{}{"key": "some.value"}}, - expectedError: "", - }, - { - query: `$[?(@.key=='value')]`, - data: `[ {"key": "some"}, {"key": "value"} ]`, - expected: []interface{}{map[string]interface{}{"key": "value"}}, - consensus: []interface{}{map[string]interface{}{"key": "value"}}, - expectedError: "", - }, - { - query: `$[?(@.key=="Mot\u00f6rhead")]`, - data: `[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`, - expected: []interface{}{map[string]interface{}{"key": "Motörhead"}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key==true)]`, - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{map[string]interface{}{"key": true}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key1==@.key2)]`, - data: `[ {"key1": 10, "key2": 10}, {"key1": 42, "key2": 50}, {"key1": 10}, {"key2": 10}, {}, {"key1": null, "key2": null}, {"key1": null}, {"key2": null}, {"key1": 0, "key2": 0}, {"key1": 0}, {"key2": 0}, {"key1": -1, "key2": -1}, {"key1": "", "key2": ""}, {"key1": false, "key2": false}, {"key1": false}, {"key2": false}, {"key1": true, "key2": true}, {"key1": [], "key2": []}, {"key1": {}, "key2": {}}, {"key1": {"a": 1, "b": 2}, "key2": {"b": 2, "a": 1}} ]`, - expected: []interface{}{ - map[string]interface{}{"key1": float64(10), "key2": float64(10)}, - map[string]interface{}{"key1": float64(0), "key2": float64(0)}, - map[string]interface{}{"key1": float64(-1), "key2": float64(-1)}, - map[string]interface{}{"key1": "", "key2": ""}, - map[string]interface{}{"key1": false, "key2": false}, - map[string]interface{}{"key1": true, "key2": true}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.items[?(@.key==$.value)]`, - data: `{"value": 42, "items": [{"key": 10}, {"key": 42}, {"key": 50}]}`, - expected: []interface{}{map[string]interface{}{"key": float64(42)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(43)}, - map[string]interface{}{"key": float64(42.0001)}, - map[string]interface{}{"key": float64(100)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key>=42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(42)}, - map[string]interface{}{"key": float64(43)}, - map[string]interface{}{"key": float64(42.0001)}, - map[string]interface{}{"key": float64(100)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.d in [2, 3])]`, // TODO : in keywork will not work - data: `[{"d": 1}, {"d": 2}, {"d": 1}, {"d": 3}, {"d": 4}]`, - expected: []interface{}{}, - consensus: nil, - expectedError: "", - }, - { - query: `$[?(2 in @.d)]`, // TODO : in keywork will not work - data: `[{"d": [1, 2, 3]}, {"d": [2]}, {"d": [1]}, {"d": [3, 4]}, {"d": [4, 2]}]`, - expected: []interface{}{}, - consensus: nil, - expectedError: "", - }, - { - query: `$[?(@.key<42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(41)}, - map[string]interface{}{"key": float64(41.9999)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key<=42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(42)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(41)}, - map[string]interface{}{"key": float64(41.9999)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key*2==100)]`, - data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key*2": 100}]`, - expected: []interface{}{map[string]interface{}{"key": float64(50)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(!(@.key==42))]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(41)}, - map[string]interface{}{"key": float64(43)}, - map[string]interface{}{"key": float64(42.0001)}, - map[string]interface{}{"key": float64(41.9999)}, - map[string]interface{}{"key": float64(100)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(!(@.key<42))]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(42)}, - map[string]interface{}{"key": float64(43)}, - map[string]interface{}{"key": float64(42.0001)}, - map[string]interface{}{"key": float64(100)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(!@.key)]`, - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{map[string]interface{}{"key": false}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key!=42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, - expected: []interface{}{ - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(1)}, - map[string]interface{}{"key": float64(41)}, - map[string]interface{}{"key": float64(43)}, - map[string]interface{}{"key": float64(42.0001)}, - map[string]interface{}{"key": float64(41.9999)}, - map[string]interface{}{"key": float64(100)}, - map[string]interface{}{"key": float64(420)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[*].bookmarks[?(@.page == 45)]^^^`, - data: `[ { "title": "Sayings of the Century", "bookmarks": [{ "page": 40 }] }, { "title": "Sword of Honour", "bookmarks": [ { "page": 35 }, { "page": 45 } ] }, { "title": "Moby Dick", "bookmarks": [ { "page": 3035 }, { "page": 45 } ] } ]`, - expected: []interface{}{[]interface{}{}, []interface{}{}, []interface{}{}}, - consensus: nil, - expectedError: "", - }, - { - query: `$[?(@.name=~/hello.*/)]`, // TODO : need regex support - data: `[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"} ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.name=~/@.pattern/)]`, - data: `[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"}, {"pattern": "hello.*"} ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@[*]>=4)]`, - data: `[[1,2],[3,4],[5,6]]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.x[?(@[*]>=$.y[*])]`, - data: `{"x":[[1,2],[3,4],[5,6]],"y":[3,4,5]}`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key=42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, - expected: []interface{}{}, - consensus: nil, - expectedError: "", - }, - { - query: `$[?(@.a[?(@.price>10)])]`, - data: `[ { "a": [{"price": 1}, {"price": 3}] }, { "a": [{"price": 11}] }, { "a": [{"price": 8}, {"price": 12}, {"price": 3}] }, { "a": [] } ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.address.city=='Berlin')]`, - data: `[ { "address": { "city": "Berlin" } }, { "address": { "city": "London" } } ]`, - expected: []interface{}{map[string]interface{}{"address": map[string]interface{}{"city": "Berlin"}}}, - consensus: []interface{}{map[string]interface{}{"address": map[string]interface{}{"city": "Berlin"}}}, - expectedError: "", - }, - { - query: `$[?(@.key-50==-100)]`, - data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key-50": -100}]`, - expected: []interface{}{map[string]interface{}{"key": float64(-50)}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(1==1)]`, - data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, - expected: []interface{}{float64(1), float64(3), "nice", true, interface{}(nil), false, map[string]interface{}{}, []interface{}{}, float64(-1), float64(0), ""}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key===42)]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@.key)]`, - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{ - map[string]interface{}{"key": true}, - map[string]interface{}{"key": "value"}, - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(1)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(42)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.*[?(@.key)]`, - data: `[ { "some": "some value" }, { "key": "value" } ]`, - expected: []interface{}{[]interface{}{}, []interface{}{}}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$..[?(@.id)]`, - data: `{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`, - expected: []interface{}{ - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - map[string]interface{}{"id": float64(2)}, - }, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(false)]`, - data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(@..child)]`, - data: `[{"key": [{"child": 1}, {"child": 2}]}, {"key": [{"child": 2}]}, {"key": [{}]}, {"key": [{"something": 42}]}, {}]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(null)]`, // TODO: null should be parsed to nil - data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?(true)]`, - data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, - expected: []interface{}{float64(1), float64(3), "nice", true, interface{}(nil), false, map[string]interface{}{}, []interface{}{}, float64(-1), float64(0), ""}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[?@.key==42]`, - data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$[?@.key==42]' invalid token. '[?@.key==42]' does not match any token format", - }, - { - query: `$[?(@.key)]`, - data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, - expected: []interface{}{ - map[string]interface{}{"key": true}, - map[string]interface{}{"key": "value"}, - map[string]interface{}{"key": float64(0)}, - map[string]interface{}{"key": float64(1)}, - map[string]interface{}{"key": float64(-1)}, - map[string]interface{}{"key": float64(42)}, - }, - consensus: consensusNone, - expectedError: "", - }, - } - - batchTest(t, tests) - // printConsensusMatrix(tests) +var filterTests []testData = []testData{ + { + query: `$[?(@.key)]`, + data: `{"key": 42, "another": {"key": 1}}`, + expected: []interface{}{map[string]interface{}{"key": float64(1)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$..*[?(@.id>2)]`, + data: `[ { "complext": { "one": [ { "name": "first", "id": 1 }, { "name": "next", "id": 2 }, { "name": "another", "id": 3 }, { "name": "more", "id": 4 } ], "more": { "name": "next to last", "id": 5 } } }, { "name": "last", "id": 6 } ]`, + expected: []interface{}{ + []interface{}{}, + []interface{}{}, + []interface{}{map[string]interface{}{"id": float64(5), "name": "next to last"}}, + []interface{}{map[string]interface{}{"id": float64(3), "name": "another"}, map[string]interface{}{"id": float64(4), "name": "more"}}, + []interface{}{}, + []interface{}{}, + []interface{}{}, + []interface{}{}, + []interface{}{}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$..[?(@.id==2)]`, + data: `{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`, + expected: []interface{}{ + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key+50==100)]`, + data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key+50": 100}]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(50)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>42 && @.key<44)]`, + data: `[ {"key": 42}, {"key": 43}, {"key": 44} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(43)}}, + consensus: []interface{}{map[string]interface{}{"key": float64(43)}}, + expectedError: "", + }, + { + query: `$[?(@.key>0 && false)]`, + data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>0 && true)]`, + data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>43 || @.key<43)]`, + data: `[ {"key": 42}, {"key": 43}, {"key": 44} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(42)}, map[string]interface{}{"key": float64(44)}}, + consensus: []interface{}{map[string]interface{}{"key": float64(42)}, map[string]interface{}{"key": float64(44)}}, + expectedError: "", + }, + { + query: `$[?(@.key>0 || false)]`, + data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>0 || true)]`, + data: `[ {"key": 1}, {"key": 3}, {"key": "nice"}, {"key": true}, {"key": null}, {"key": false}, {"key": {}}, {"key": []}, {"key": -1}, {"key": 0}, {"key": ""} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(1)}, map[string]interface{}{"key": float64(3)}, map[string]interface{}{"key": float64(-1)}, map[string]interface{}{"key": float64(0)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@['key']==42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"some": "value"} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(42)}}, + consensus: []interface{}{map[string]interface{}{"key": float64(42)}}, + expectedError: "", + }, + { + query: `$[?(@['@key']==42)]`, + data: `[ {"@key": 0}, {"@key": 42}, {"key": 42}, {"@key": 43}, {"some": "value"} ]`, + expected: []interface{}{map[string]interface{}{"@key": float64(42)}}, + consensus: []interface{}{map[string]interface{}{"@key": float64(42)}}, + expectedError: "", + }, + { + query: `$[?(@[-1]==2)]`, + data: `[[2, 3], ["a"], [0, 2], [2]]`, + expected: []interface{}{[]interface{}{float64(0), float64(2)}, []interface{}{float64(2)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@[1]=='b')]`, + data: `[["a", "b"], ["x", "y"]]`, + expected: []interface{}{[]interface{}{"a", "b"}}, + consensus: []interface{}{[]interface{}{"a", "b"}}, + expectedError: "", + }, + { + query: `$[?(@[1]=='b')]`, + data: `{"1": ["a", "b"], "2": ["x", "y"]}`, + expected: []interface{}{[]interface{}{"a", "b"}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@)]`, + data: `[ "some value", null, "value", 0, 1, -1, "", [], {}, false, true ]`, + expected: []interface{}{"some value", "value", float64(0), float64(1), float64(-1), true}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.a && (@.b || @.c))]`, + data: `[ { "a": true }, { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "c": true }, { "b": true } ]`, + expected: []interface{}{}, // TODO : this should be different + consensus: consensusNone, + expectedError: "", + }, + { + query: `[?(@.a && @.b || @.c)]`, + data: `[ { "a": true, "b": true }, { "a": true, "b": true, "c": true }, { "b": true, "c": true }, { "a": true, "c": true }, { "a": true }, { "b": true }, { "c": true }, { "d": true }, {} ]`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '[?(@.a && @.b || @.c)]' unexpected token '[' at index 0", + }, + { + query: `$[?(@.key/10==5)]`, + data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key/10": 5}]`, + expected: []interface{}{map[string]interface{}{"key": float64(50)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key-dash == 'value')]`, + data: `[ { "key-dash": "value" } ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.2 == 'second')]`, + data: `[{"a": "first", "2": "second", "b": "third"}]`, + expected: []interface{}{map[string]interface{}{"2": "second", "a": "first", "b": "third"}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.2 == 'third')]`, + data: `[["first", "second", "third", "forth", "fifth"]] `, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?()]`, + data: `[1, {"key": 42}, "value", null]`, + expected: nil, + consensus: nil, + expectedError: "invalid expression. is empty", + }, + { + query: `$[?(@.key==42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, + expected: []interface{}{map[string]interface{}{"key": float64(42)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@==42)]`, + data: `[ 0, 42, -1, 41, 43, 42.0001, 41.9999, null, 100 ]`, + expected: []interface{}{}, // TODO : doesn't match as float == int, needs fixed + consensus: []interface{}{float64(42)}, + expectedError: "", + }, + { + query: `$[?(@.key==43)]`, + data: `[{"key": 42}]`, + expected: []interface{}{}, + consensus: []interface{}{}, + expectedError: "", + }, + { + query: `$[?(@.key==42)]`, + data: `{ "a": {"key": 0}, "b": {"key": 42}, "c": {"key": -1}, "d": {"key": 41}, "e": {"key": 43}, "f": {"key": 42.0001}, "g": {"key": 41.9999}, "h": {"key": 100}, "i": {"some": "value"} }`, + expected: []interface{}{map[string]interface{}{"key": float64(42)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.id==2)]`, + data: `{"id": 2}`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.d==["v1","v2"])]`, + data: `[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`, + expected: []interface{}{}, // TODO : doesn't know [] is array + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@[0:1]==[1])]`, + data: `[[1, 2, 3], [1], [2, 3], 1, 2]`, + expected: []interface{}{}, // TODO : doesn't know [] is array + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.*==[1,2])]`, + data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, + expected: []interface{}{}, // TODO : need to parse [1,2] as array + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.d==['v1','v2'])]`, + data: `[ { "d": [ "v1", "v2" ] }, { "d": [ "a", "b" ] }, { "d": "v1" }, { "d": "v2" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "['v1','v2']" }, { "d": "['v1', 'v2']" }, { "d": "v1,v2" }, { "d": "[\"v1\", \"v2\"]" }, { "d": "[\"v1\",\"v2\"]" } ]`, + expected: []interface{}{}, // TODO : need to parse ['v1','v2'] as array + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?((@.key<44)==false)]`, + data: `[{"key": 42}, {"key": 43}, {"key": 44}]`, + expected: []interface{}{map[string]interface{}{"key": float64(44)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key==false)]`, + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{map[string]interface{}{"key": false}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key==null)]`, // TODO : nil/null support + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@[0:1]==1)]`, // TODO array in expression support + data: `[[1, 2, 3], [1], [2, 3], 1, 2]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@[*]==2)]`, // TODO array in expression support + data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.*==2)]`, + data: `[[1,2], [2,3], [1], [2], [1, 2, 3], 1, 2, 3]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key==-0.123e2)]`, + data: `[{"key": -12.3}, {"key": -0.123}, {"key": -12}, {"key": 12.3}, {"key": 2}, {"key": "-0.123e2"}]`, + expected: []interface{}{map[string]interface{}{"key": float64(-12.3)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key==010)]`, // TODO : is this expected + data: `[{"key": "010"}, {"key": "10"}, {"key": 10}, {"key": 0}, {"key": 8}]`, + expected: []interface{}{map[string]interface{}{"key": float64(8)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.d=={"k":"v"})]`, // TODO: will not parse as map + data: `[ { "d": { "k": "v" } }, { "d": { "a": "b" } }, { "d": "k" }, { "d": "v" }, { "d": {} }, { "d": [] }, { "d": null }, { "d": -1 }, { "d": 0 }, { "d": 1 }, { "d": "[object Object]" }, { "d": "{\"k\": \"v\"}" }, { "d": "{\"k\":\"v\"}" }, "v" ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key=="value")]`, + data: `[ {"key": "some"}, {"key": "value"}, {"key": null}, {"key": 0}, {"key": 1}, {"key": -1}, {"key": ""}, {"key": {}}, {"key": []}, {"key": "valuemore"}, {"key": "morevalue"}, {"key": ["value"]}, {"key": {"some": "value"}}, {"key": {"key": "value"}}, {"some": "value"} ]`, + expected: []interface{}{map[string]interface{}{"key": "value"}}, + consensus: []interface{}{map[string]interface{}{"key": "value"}}, + expectedError: "", + }, + { + query: `$[?(@.key=="Motörhead")]`, + data: `[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`, + expected: []interface{}{map[string]interface{}{"key": "Mot\u00f6rhead"}}, + consensus: []interface{}{map[string]interface{}{"key": "Mot\u00f6rhead"}}, + expectedError: "", + }, + { + query: `$[?(@.key=="hi@example.com")]`, // TODO: double quotes in filters + data: `[ {"key": "some"}, {"key": "value"}, {"key": "hi@example.com"} ]`, + expected: []interface{}{}, + consensus: []interface{}{map[string]interface{}{"key": "hi@example.com"}}, + expectedError: "", + }, + { + query: `$[?(@.key=="some.value")]`, + data: `[ {"key": "some"}, {"key": "value"}, {"key": "some.value"} ]`, + expected: []interface{}{map[string]interface{}{"key": "some.value"}}, + consensus: []interface{}{map[string]interface{}{"key": "some.value"}}, + expectedError: "", + }, + { + query: `$[?(@.key=='value')]`, + data: `[ {"key": "some"}, {"key": "value"} ]`, + expected: []interface{}{map[string]interface{}{"key": "value"}}, + consensus: []interface{}{map[string]interface{}{"key": "value"}}, + expectedError: "", + }, + { + query: `$[?(@.key=="Mot\u00f6rhead")]`, + data: `[ {"key": "something"}, {"key": "Mot\u00f6rhead"}, {"key": "mot\u00f6rhead"}, {"key": "Motorhead"}, {"key": "Motoo\u0308rhead"}, {"key": "motoo\u0308rhead"} ]`, + expected: []interface{}{map[string]interface{}{"key": "Motörhead"}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key==true)]`, + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{map[string]interface{}{"key": true}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key1==@.key2)]`, + data: `[ {"key1": 10, "key2": 10}, {"key1": 42, "key2": 50}, {"key1": 10}, {"key2": 10}, {}, {"key1": null, "key2": null}, {"key1": null}, {"key2": null}, {"key1": 0, "key2": 0}, {"key1": 0}, {"key2": 0}, {"key1": -1, "key2": -1}, {"key1": "", "key2": ""}, {"key1": false, "key2": false}, {"key1": false}, {"key2": false}, {"key1": true, "key2": true}, {"key1": [], "key2": []}, {"key1": {}, "key2": {}}, {"key1": {"a": 1, "b": 2}, "key2": {"b": 2, "a": 1}} ]`, + expected: []interface{}{ + map[string]interface{}{"key1": float64(10), "key2": float64(10)}, + map[string]interface{}{"key1": float64(0), "key2": float64(0)}, + map[string]interface{}{"key1": float64(-1), "key2": float64(-1)}, + map[string]interface{}{"key1": "", "key2": ""}, + map[string]interface{}{"key1": false, "key2": false}, + map[string]interface{}{"key1": true, "key2": true}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.items[?(@.key==$.value)]`, + data: `{"value": 42, "items": [{"key": 10}, {"key": 42}, {"key": 50}]}`, + expected: []interface{}{map[string]interface{}{"key": float64(42)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(43)}, + map[string]interface{}{"key": float64(42.0001)}, + map[string]interface{}{"key": float64(100)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key>=42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(42)}, + map[string]interface{}{"key": float64(43)}, + map[string]interface{}{"key": float64(42.0001)}, + map[string]interface{}{"key": float64(100)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.d in [2, 3])]`, // TODO : in keywork will not work + data: `[{"d": 1}, {"d": 2}, {"d": 1}, {"d": 3}, {"d": 4}]`, + expected: []interface{}{}, + consensus: nil, + expectedError: "", + }, + { + query: `$[?(2 in @.d)]`, // TODO : in keywork will not work + data: `[{"d": [1, 2, 3]}, {"d": [2]}, {"d": [1]}, {"d": [3, 4]}, {"d": [4, 2]}]`, + expected: []interface{}{}, + consensus: nil, + expectedError: "", + }, + { + query: `$[?(@.key<42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(41)}, + map[string]interface{}{"key": float64(41.9999)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key<=42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(42)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(41)}, + map[string]interface{}{"key": float64(41.9999)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key*2==100)]`, + data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key*2": 100}]`, + expected: []interface{}{map[string]interface{}{"key": float64(50)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(!(@.key==42))]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(41)}, + map[string]interface{}{"key": float64(43)}, + map[string]interface{}{"key": float64(42.0001)}, + map[string]interface{}{"key": float64(41.9999)}, + map[string]interface{}{"key": float64(100)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(!(@.key<42))]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "43"}, {"key": "42"}, {"key": "41"}, {"key": "value"}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(42)}, + map[string]interface{}{"key": float64(43)}, + map[string]interface{}{"key": float64(42.0001)}, + map[string]interface{}{"key": float64(100)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(!@.key)]`, + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{map[string]interface{}{"key": false}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key!=42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, + expected: []interface{}{ + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(1)}, + map[string]interface{}{"key": float64(41)}, + map[string]interface{}{"key": float64(43)}, + map[string]interface{}{"key": float64(42.0001)}, + map[string]interface{}{"key": float64(41.9999)}, + map[string]interface{}{"key": float64(100)}, + map[string]interface{}{"key": float64(420)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[*].bookmarks[?(@.page == 45)]^^^`, + data: `[ { "title": "Sayings of the Century", "bookmarks": [{ "page": 40 }] }, { "title": "Sword of Honour", "bookmarks": [ { "page": 35 }, { "page": 45 } ] }, { "title": "Moby Dick", "bookmarks": [ { "page": 3035 }, { "page": 45 } ] } ]`, + expected: []interface{}{[]interface{}{}, []interface{}{}, []interface{}{}}, + consensus: nil, + expectedError: "", + }, + { + query: `$[?(@.name=~/hello.*/)]`, // TODO : need regex support + data: `[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"} ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.name=~/@.pattern/)]`, + data: `[ {"name": "hullo world"}, {"name": "hello world"}, {"name": "yes hello world"}, {"name": "HELLO WORLD"}, {"name": "good bye"}, {"pattern": "hello.*"} ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@[*]>=4)]`, + data: `[[1,2],[3,4],[5,6]]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.x[?(@[*]>=$.y[*])]`, + data: `{"x":[[1,2],[3,4],[5,6]],"y":[3,4,5]}`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key=42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, + expected: []interface{}{}, + consensus: nil, + expectedError: "", + }, + { + query: `$[?(@.a[?(@.price>10)])]`, + data: `[ { "a": [{"price": 1}, {"price": 3}] }, { "a": [{"price": 11}] }, { "a": [{"price": 8}, {"price": 12}, {"price": 3}] }, { "a": [] } ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.address.city=='Berlin')]`, + data: `[ { "address": { "city": "Berlin" } }, { "address": { "city": "London" } } ]`, + expected: []interface{}{map[string]interface{}{"address": map[string]interface{}{"city": "Berlin"}}}, + consensus: []interface{}{map[string]interface{}{"address": map[string]interface{}{"city": "Berlin"}}}, + expectedError: "", + }, + { + query: `$[?(@.key-50==-100)]`, + data: `[{"key": 60}, {"key": 50}, {"key": 10}, {"key": -50}, {"key-50": -100}]`, + expected: []interface{}{map[string]interface{}{"key": float64(-50)}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(1==1)]`, + data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, + expected: []interface{}{float64(1), float64(3), "nice", true, interface{}(nil), false, map[string]interface{}{}, []interface{}{}, float64(-1), float64(0), ""}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key===42)]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@.key)]`, + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{ + map[string]interface{}{"key": true}, + map[string]interface{}{"key": "value"}, + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(1)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(42)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.*[?(@.key)]`, + data: `[ { "some": "some value" }, { "key": "value" } ]`, + expected: []interface{}{[]interface{}{}, []interface{}{}}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$..[?(@.id)]`, + data: `{"id": 2, "more": [{"id": 2}, {"more": {"id": 2}}, {"id": {"id": 2}}, [{"id": 2}]]}`, + expected: []interface{}{ + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + map[string]interface{}{"id": float64(2)}, + }, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(false)]`, + data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(@..child)]`, + data: `[{"key": [{"child": 1}, {"child": 2}]}, {"key": [{"child": 2}]}, {"key": [{}]}, {"key": [{"something": 42}]}, {}]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(null)]`, // TODO: null should be parsed to nil + data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?(true)]`, + data: `[1, 3, "nice", true, null, false, {}, [], -1, 0, ""]`, + expected: []interface{}{float64(1), float64(3), "nice", true, interface{}(nil), false, map[string]interface{}{}, []interface{}{}, float64(-1), float64(0), ""}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[?@.key==42]`, + data: `[ {"key": 0}, {"key": 42}, {"key": -1}, {"key": 1}, {"key": 41}, {"key": 43}, {"key": 42.0001}, {"key": 41.9999}, {"key": 100}, {"key": "some"}, {"key": "42"}, {"key": null}, {"key": 420}, {"key": ""}, {"key": {}}, {"key": []}, {"key": [42]}, {"key": {"key": 42}}, {"key": {"some": 42}}, {"some": "value"} ]`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$[?@.key==42]' invalid token. '[?@.key==42]' does not match any token format", + }, + { + query: `$[?(@.key)]`, + data: `[ { "some": "some value" }, { "key": true }, { "key": false }, { "key": null }, { "key": "value" }, { "key": "" }, { "key": 0 }, { "key": 1 }, { "key": -1 }, { "key": 42 }, { "key": {} }, { "key": [] } ]`, + expected: []interface{}{ + map[string]interface{}{"key": true}, + map[string]interface{}{"key": "value"}, + map[string]interface{}{"key": float64(0)}, + map[string]interface{}{"key": float64(1)}, + map[string]interface{}{"key": float64(-1)}, + map[string]interface{}{"key": float64(42)}, + }, + consensus: consensusNone, + expectedError: "", + }, } diff --git a/test/helper_test.go b/test/helper_test.go index 6220b5e..a0acbbf 100644 --- a/test/helper_test.go +++ b/test/helper_test.go @@ -3,7 +3,11 @@ package test import ( + "bufio" + "encoding/json" "fmt" + "io" + "os" "reflect" "testing" @@ -44,23 +48,87 @@ func batchTest(t *testing.T, tests []testData) { } } -func printConsensusMatrix(tests []testData) { - fmt.Println("|query|data|consensus|actual|match|") - fmt.Println("|---|---|---|---|---|") +func Test_generateReadme(t *testing.T) { + + header := `# cburgmer tests + +This test package has tests detailed by https://cburgmer.github.io/json-path-comparison/ comparison matrix which details the community consensus on the expected response from multiple JSONPath queries + +This implementation would be closer to the 'Scalar consensus' as it does not always return an array, but instead can return a single item when that is expected. + ` + + type section struct { + title string + testData []testData + } + + sections := []section{ + { + title: "Array Test", + testData: arrayTests, + }, + { + title: "Bracket Test", + testData: bracketTests, + }, + { + title: "Dot Test", + testData: dotTests, + }, + { + title: "Filter Test", + testData: filterTests, + }, + { + title: "Misc Test", + testData: miscTests, + }, + { + title: "Union Test", + testData: unionTests, + }, + } + + file, err := os.OpenFile("README.md", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + t.FailNow() + } + defer file.Close() + + writer := bufio.NewWriter(file) + defer writer.Flush() + + fmt.Fprintf(writer, "%s\n", header) + + for _, section := range sections { + fmt.Fprintf(writer, "\n## %s\n\n", section.title) + printConsensusMatrix(writer, section.testData) + } +} + +func printConsensusMatrix(writer io.Writer, tests []testData) { + fmt.Fprintf(writer, "|query|data|consensus|actual|match|\n") + fmt.Fprintf(writer, "|---|---|---|---|---|\n") for _, test := range tests { expected := test.expected if expected == nil { - expected = "nil" + expected = "null" + } else { + bytes, _ := json.Marshal(expected) + expected = string(bytes) } if test.consensus == consensusNone { - fmt.Printf("|`%s`|`%v`|%s|`%v`|%s|\n", test.query, test.data, "none", expected, ":question:") + fmt.Fprintf(writer, "|`%s`|`%v`|%s|`%v`|%s|\n", test.query, test.data, "none", expected, ":question:") continue } consensus := test.consensus if consensus == nil { consensus = "nil" + } else if consensus != consensusNone { + bytes, _ := json.Marshal(consensus) + consensus = string(bytes) } symbol := ":no_entry:" @@ -68,6 +136,6 @@ func printConsensusMatrix(tests []testData) { symbol = ":white_check_mark:" } - fmt.Printf("|`%s`|`%v`|`%v`|`%v`|%s|\n", test.query, test.data, consensus, expected, symbol) + fmt.Fprintf(writer, "|`%s`|`%v`|`%v`|`%v`|%s|\n", test.query, test.data, consensus, expected, symbol) } } diff --git a/test/misc_test.go b/test/misc_test.go index 118e841..73096ce 100644 --- a/test/misc_test.go +++ b/test/misc_test.go @@ -3,80 +3,78 @@ package test import "testing" func Test_Misc(t *testing.T) { + batchTest(t, miscTests) +} - tests := []testData{ - { - query: "", // empty - data: `{"a": 42, "": 21}`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '' unexpected token '' at index 0", - }, - { - query: `$.data.sum()`, - data: `{"data": [1,2,3,4]}`, - expected: nil, - consensus: consensusNone, - expectedError: "key: invalid token target. expected [map] got [slice]", - }, - { - query: `$(key,more)`, - data: `{"key": 1, "some": 2, "more": 3}`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$(key,more)' unexpected token '(' at index 1", - }, - { - query: `$..`, - data: `[{"a": {"b": "c"}}, [0, 1]]`, - expected: []interface{}{[]interface{}{map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, []interface{}{float64(0), float64(1)}}, map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, map[string]interface{}{"b": "c"}, "c", []interface{}{float64(0), float64(1)}, float64(0), float64(1)}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$.key..`, - data: `{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}`, - expected: []interface{}{map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, float64(0), float64(1), "string"}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$`, - data: `{ "key": "value", "another key": { "complex": [ "a", 1 ] } }`, - expected: map[string]interface{}{"key": "value", "another key": map[string]interface{}{"complex": []interface{}{"a", float64(1)}}}, - consensus: map[string]interface{}{"key": "value", "another key": map[string]interface{}{"complex": []interface{}{"a", float64(1)}}}, - expectedError: "", - }, - { - query: `$`, - data: `42`, - expected: int64(42), - consensus: int64(42), - expectedError: "", - }, - { - query: `$`, - data: `false`, - expected: false, - consensus: false, - expectedError: "", - }, - { - query: `$`, - data: `true`, - expected: true, - consensus: true, - expectedError: "", - }, - { - query: `$[(@.length-1)]`, - data: `["first", "second", "third", "forth", "fifth"]`, - expected: "fifth", - consensus: nil, - expectedError: "", - }, - } - - batchTest(t, tests) - // printConsensusMatrix(tests) +var miscTests []testData = []testData{ + { + query: "", // empty + data: `{"a": 42, "": 21}`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '' unexpected token '' at index 0", + }, + { + query: `$.data.sum()`, + data: `{"data": [1,2,3,4]}`, + expected: nil, + consensus: consensusNone, + expectedError: "key: invalid token target. expected [map] got [slice]", + }, + { + query: `$(key,more)`, + data: `{"key": 1, "some": 2, "more": 3}`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$(key,more)' unexpected token '(' at index 1", + }, + { + query: `$..`, + data: `[{"a": {"b": "c"}}, [0, 1]]`, + expected: []interface{}{[]interface{}{map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, []interface{}{float64(0), float64(1)}}, map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, map[string]interface{}{"b": "c"}, "c", []interface{}{float64(0), float64(1)}, float64(0), float64(1)}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$.key..`, + data: `{"some key": "value", "key": {"complex": "string", "primitives": [0, 1]}}`, + expected: []interface{}{map[string]interface{}{"complex": "string", "primitives": []interface{}{float64(0), float64(1)}}, []interface{}{float64(0), float64(1)}, float64(0), float64(1), "string"}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$`, + data: `{ "key": "value", "another key": { "complex": [ "a", 1 ] } }`, + expected: map[string]interface{}{"key": "value", "another key": map[string]interface{}{"complex": []interface{}{"a", float64(1)}}}, + consensus: map[string]interface{}{"key": "value", "another key": map[string]interface{}{"complex": []interface{}{"a", float64(1)}}}, + expectedError: "", + }, + { + query: `$`, + data: `42`, + expected: int64(42), + consensus: int64(42), + expectedError: "", + }, + { + query: `$`, + data: `false`, + expected: false, + consensus: false, + expectedError: "", + }, + { + query: `$`, + data: `true`, + expected: true, + consensus: true, + expectedError: "", + }, + { + query: `$[(@.length-1)]`, + data: `["first", "second", "third", "forth", "fifth"]`, + expected: "fifth", + consensus: nil, + expectedError: "", + }, } diff --git a/test/union_test.go b/test/union_test.go index e894540..f1c5cc2 100644 --- a/test/union_test.go +++ b/test/union_test.go @@ -3,115 +3,113 @@ package test import "testing" func Test_Union(t *testing.T) { + batchTest(t, unionTests) +} - tests := []testData{ - { - query: `$[0,1]`, - data: `["first", "second", "third"]`, - expected: []interface{}{"first", "second"}, - consensus: []interface{}{"first", "second"}, - expectedError: "", - }, - { - query: `$[0,0]`, - data: `["a"]`, - expected: []interface{}{"a", "a"}, - consensus: []interface{}{"a", "a"}, - expectedError: "", - }, - { - query: `$['a','a']`, - data: `{"a":1}`, - expected: []interface{}{float64(1), float64(1)}, - consensus: []interface{}{float64(1), float64(1)}, - expectedError: "", - }, - { - query: `$[?(@.key<3),?(@.key>6)]`, - data: `[{"key": 1}, {"key": 8}, {"key": 3}, {"key": 10}, {"key": 7}, {"key": 2}, {"key": 6}, {"key": 4}]`, - expected: []interface{}{}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$['key','another']`, - data: `{ "key": "value", "another": "entry" }`, - expected: []interface{}{"value", "entry"}, - consensus: []interface{}{"value", "entry"}, - expectedError: "", - }, - { - query: `$['missing','key']`, - data: `{ "key": "value", "another": "entry" }`, - expected: []interface{}{"value"}, - consensus: []interface{}{"value"}, - expectedError: "", - }, - { - query: `$[:]['c','d']`, - data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, - expected: []interface{}{[]interface{}{"cc1", "dd1"}, []interface{}{"cc2", "dd2"}}, - consensus: []interface{}{"cc1", "dd1", "cc2", "dd2"}, - expectedError: "", - }, - { - query: `$[0]['c','d']`, - data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, - expected: []interface{}{"cc1", "dd1"}, - consensus: []interface{}{"cc1", "dd1"}, - expectedError: "", - }, - { - query: `$.*['c','d']`, - data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, - expected: []interface{}{[]interface{}{"cc1", "dd1"}, []interface{}{"cc2", "dd2"}}, - consensus: []interface{}{"cc1", "dd1", "cc2", "dd2"}, - expectedError: "", - }, - { - query: `$..['c','d']`, - data: `[{"c":"cc1","d":"dd1","e":"ee1"}, {"c": "cc2", "child": {"d": "dd2"}}, {"c": "cc3"}, {"d": "dd4"}, {"child": {"c": "cc5"}}]`, - expected: []interface{}{"cc1", "dd1", "cc2", "dd2", "cc3", "dd4", "cc5"}, - consensus: consensusNone, - expectedError: "", - }, - { - query: `$[4,1]`, - data: `[1,2,3,4,5]`, - expected: []interface{}{float64(5), float64(2)}, - consensus: []interface{}{float64(5), float64(2)}, - expectedError: "", - }, - { - query: `$.*[0,:5]`, - data: `{ "a": [ "string", null, true ], "b": [ false, "string", 5.4 ] }`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$.*[0,:5]' invalid token. '[0,:5]' does not match any token format", - }, - { - query: `$[1:3,4]`, - data: `[1,2,3,4,5]`, - expected: nil, - consensus: consensusNone, - expectedError: "invalid JSONPath query '$[1:3,4]' invalid token. '[1:3,4]' does not match any token format", - }, - { - query: `$[ 0 , 1 ]`, - data: `["first", "second", "third"]`, - expected: []interface{}{"first", "second"}, - consensus: []interface{}{"first", "second"}, - expectedError: "", - }, - { - query: `$[*,1]`, - data: `["first", "second", "third", "forth", "fifth"]`, - expected: nil, - consensus: nil, - expectedError: "invalid JSONPath query '$[*,1]' invalid token. '[*,1]' does not match any token format", - }, - } - - batchTest(t, tests) - //printConsensusMatrix(tests) +var unionTests []testData = []testData{ + { + query: `$[0,1]`, + data: `["first", "second", "third"]`, + expected: []interface{}{"first", "second"}, + consensus: []interface{}{"first", "second"}, + expectedError: "", + }, + { + query: `$[0,0]`, + data: `["a"]`, + expected: []interface{}{"a", "a"}, + consensus: []interface{}{"a", "a"}, + expectedError: "", + }, + { + query: `$['a','a']`, + data: `{"a":1}`, + expected: []interface{}{float64(1), float64(1)}, + consensus: []interface{}{float64(1), float64(1)}, + expectedError: "", + }, + { + query: `$[?(@.key<3),?(@.key>6)]`, + data: `[{"key": 1}, {"key": 8}, {"key": 3}, {"key": 10}, {"key": 7}, {"key": 2}, {"key": 6}, {"key": 4}]`, + expected: []interface{}{}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$['key','another']`, + data: `{ "key": "value", "another": "entry" }`, + expected: []interface{}{"value", "entry"}, + consensus: []interface{}{"value", "entry"}, + expectedError: "", + }, + { + query: `$['missing','key']`, + data: `{ "key": "value", "another": "entry" }`, + expected: []interface{}{"value"}, + consensus: []interface{}{"value"}, + expectedError: "", + }, + { + query: `$[:]['c','d']`, + data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, + expected: []interface{}{[]interface{}{"cc1", "dd1"}, []interface{}{"cc2", "dd2"}}, + consensus: []interface{}{"cc1", "dd1", "cc2", "dd2"}, + expectedError: "", + }, + { + query: `$[0]['c','d']`, + data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, + expected: []interface{}{"cc1", "dd1"}, + consensus: []interface{}{"cc1", "dd1"}, + expectedError: "", + }, + { + query: `$.*['c','d']`, + data: `[{"c":"cc1","d":"dd1","e":"ee1"},{"c":"cc2","d":"dd2","e":"ee2"}]`, + expected: []interface{}{[]interface{}{"cc1", "dd1"}, []interface{}{"cc2", "dd2"}}, + consensus: []interface{}{"cc1", "dd1", "cc2", "dd2"}, + expectedError: "", + }, + { + query: `$..['c','d']`, + data: `[{"c":"cc1","d":"dd1","e":"ee1"}, {"c": "cc2", "child": {"d": "dd2"}}, {"c": "cc3"}, {"d": "dd4"}, {"child": {"c": "cc5"}}]`, + expected: []interface{}{"cc1", "dd1", "cc2", "dd2", "cc3", "dd4", "cc5"}, + consensus: consensusNone, + expectedError: "", + }, + { + query: `$[4,1]`, + data: `[1,2,3,4,5]`, + expected: []interface{}{float64(5), float64(2)}, + consensus: []interface{}{float64(5), float64(2)}, + expectedError: "", + }, + { + query: `$.*[0,:5]`, + data: `{ "a": [ "string", null, true ], "b": [ false, "string", 5.4 ] }`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$.*[0,:5]' invalid token. '[0,:5]' does not match any token format", + }, + { + query: `$[1:3,4]`, + data: `[1,2,3,4,5]`, + expected: nil, + consensus: consensusNone, + expectedError: "invalid JSONPath query '$[1:3,4]' invalid token. '[1:3,4]' does not match any token format", + }, + { + query: `$[ 0 , 1 ]`, + data: `["first", "second", "third"]`, + expected: []interface{}{"first", "second"}, + consensus: []interface{}{"first", "second"}, + expectedError: "", + }, + { + query: `$[*,1]`, + data: `["first", "second", "third", "forth", "fifth"]`, + expected: nil, + consensus: nil, + expectedError: "invalid JSONPath query '$[*,1]' invalid token. '[*,1]' does not match any token format", + }, }