From e5fd6fa6e603853e148bb3ecda5b79502d14c30d Mon Sep 17 00:00:00 2001 From: James Prior Date: Wed, 20 Dec 2023 11:59:46 +0000 Subject: [PATCH 1/2] Cover function expressions as function parameters --- cts.json | 68 +++++++++++++++++++++++++++++++++++++ tests/functions/length.json | 16 +++++++++ tests/functions/match.json | 20 +++++++++++ tests/functions/search.json | 19 +++++++++++ 4 files changed, 123 insertions(+) diff --git a/cts.json b/cts.json index 35ec022..34bad52 100644 --- a/cts.json +++ b/cts.json @@ -4085,6 +4085,31 @@ "selector": "$[?length(@.a,@.b)==1]", "invalid_selector": true }, + { + "name": "functions, length, non-singular query arg", + "selector": "$[?length(@.*)<3]", + "invalid_selector": true + }, + { + "name": "functions, length, arg is a function expression", + "selector": "$.values[?length(@.a)==length(value($..c))]", + "document": { + "c": "cd", + "values": [ + { + "a": "ab" + }, + { + "a": "d" + } + ] + }, + "result": [ + { + "a": "ab" + } + ] + }, { "name": "functions, match, found match", "selector": "$[?match(@.a, 'a.*')]", @@ -4250,6 +4275,26 @@ "selector": "$[?match(@.a,@.b,@.c)==1]", "invalid_selector": true }, + { + "name": "functions, match, arg is a function expression", + "selector": "$.values[?match(@.a, value($..['regex']))]", + "document": { + "regex": "a.*", + "values": [ + { + "a": "ab" + }, + { + "a": "ba" + } + ] + }, + "result": [ + { + "a": "ab" + } + ] + }, { "name": "functions, search, at the end", "selector": "$[?search(@.a, 'a.*')]", @@ -4446,6 +4491,29 @@ "selector": "$[?search(@.a,@.b,@.c)]", "invalid_selector": true }, + { + "name": "functions, search, arg is a function expression", + "selector": "$.values[?search(@, value($..['regex']))]", + "document": { + "regex": "b.?b", + "values": [ + "abc", + "bcd", + "bab", + "bba", + "bbab", + "b", + true, + [], + {} + ] + }, + "result": [ + "bab", + "bba", + "bbab" + ] + }, { "name": "functions, value, single-value nodelist", "selector": "$[?value(@.*)==4]", diff --git a/tests/functions/length.json b/tests/functions/length.json index 56812ac..7213298 100644 --- a/tests/functions/length.json +++ b/tests/functions/length.json @@ -66,6 +66,22 @@ "name": "too many params", "selector" : "$[?length(@.a,@.b)==1]", "invalid_selector": true + }, + { + "name": "non-singular query arg", + "selector": "$[?length(@.*)<3]", + "invalid_selector": true + }, + { + "name": "arg is a function expression", + "selector" : "$.values[?length(@.a)==length(value($..c))]", + "document" : { + "c": "cd", + "values": [{"a": "ab"}, {"a": "d"}] + }, + "result": [ + {"a": "ab"} + ] } ] } diff --git a/tests/functions/match.json b/tests/functions/match.json index 5964a21..8c3b253 100644 --- a/tests/functions/match.json +++ b/tests/functions/match.json @@ -85,6 +85,26 @@ "name": "too many params", "selector" : "$[?match(@.a,@.b,@.c)==1]", "invalid_selector": true + }, + { + "name": "arg is a function expression", + "selector": "$.values[?match(@.a, value($..['regex']))]", + "document": { + "regex": "a.*", + "values": [ + { + "a": "ab" + }, + { + "a": "ba" + } + ] + }, + "result": [ + { + "a": "ab" + } + ] } ] } diff --git a/tests/functions/search.json b/tests/functions/search.json index f14659e..c536af8 100644 --- a/tests/functions/search.json +++ b/tests/functions/search.json @@ -100,6 +100,25 @@ "name": "too many params", "selector" : "$[?search(@.a,@.b,@.c)]", "invalid_selector": true + }, + { + "name": "arg is a function expression", + "selector" : "$.values[?search(@, value($..['regex']))]", + "document" : { + "regex": "b.?b", + "values": [ + "abc", + "bcd", + "bab", + "bba", + "bbab", + "b", + true, + [], + {} + ] + }, + "result": ["bab", "bba", "bbab"] } ] } From d5547781465f5034bfd5969460209e56fce57d35 Mon Sep 17 00:00:00 2001 From: James Prior Date: Wed, 27 Dec 2023 15:00:03 +0000 Subject: [PATCH 2/2] Tests functions that return special nothing --- cts.json | 46 +++++++++++++++++++++++++++++++++++++ tests/filter.json | 16 +++++++++++++ tests/functions/length.json | 12 ++++++++++ 3 files changed, 74 insertions(+) diff --git a/cts.json b/cts.json index 34bad52..11af641 100644 --- a/cts.json +++ b/cts.json @@ -2397,6 +2397,32 @@ } ] }, + { + "name": "filter, equals, special nothing", + "selector": "$.values[?length(@.a) == value($..c)]", + "document": { + "c": "cd", + "values": [ + { + "a": "ab" + }, + { + "c": "d" + }, + { + "a": null + } + ] + }, + "result": [ + { + "c": "d" + }, + { + "a": null + } + ] + }, { "name": "index selector, first element", "selector": "$[0]", @@ -4110,6 +4136,26 @@ } ] }, + { + "name": "functions, length, arg is special nothing", + "selector": "$[?length(value(@.a))>0]", + "document": [ + { + "a": "ab" + }, + { + "c": "d" + }, + { + "a": null + } + ], + "result": [ + { + "a": "ab" + } + ] + }, { "name": "functions, match, found match", "selector": "$[?match(@.a, 'a.*')]", diff --git a/tests/filter.json b/tests/filter.json index c42160a..519bf21 100644 --- a/tests/filter.json +++ b/tests/filter.json @@ -770,6 +770,22 @@ "result": [ {"a": 0.011, "d": "e"} ] + }, + { + "name": "equals, special nothing", + "selector" : "$.values[?length(@.a) == value($..c)]", + "document" : { + "c": "cd", + "values": [ + {"a": "ab"}, + {"c": "d"}, + {"a": null} + ] + }, + "result": [ + {"c": "d"}, + {"a": null} + ] } ] } diff --git a/tests/functions/length.json b/tests/functions/length.json index 7213298..9382c2e 100644 --- a/tests/functions/length.json +++ b/tests/functions/length.json @@ -82,6 +82,18 @@ "result": [ {"a": "ab"} ] + }, + { + "name": "arg is special nothing", + "selector" : "$[?length(value(@.a))>0]", + "document" : [ + {"a": "ab"}, + {"c": "d"}, + {"a": null} + ], + "result": [ + {"a": "ab"} + ] } ] }