Skip to content

Cover function expressions as function parameters #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions cts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down Expand Up @@ -4085,6 +4111,51 @@
"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, 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.*')]",
Expand Down Expand Up @@ -4250,6 +4321,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.*')]",
Expand Down Expand Up @@ -4446,6 +4537,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]",
Expand Down
16 changes: 16 additions & 0 deletions tests/filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}
]
}
]
}
28 changes: 28 additions & 0 deletions tests/functions/length.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@
"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"}
]
},
{
"name": "arg is special nothing",
"selector" : "$[?length(value(@.a))>0]",
"document" : [
{"a": "ab"},
{"c": "d"},
{"a": null}
],
"result": [
{"a": "ab"}
]
}
]
}
20 changes: 20 additions & 0 deletions tests/functions/match.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
}
19 changes: 19 additions & 0 deletions tests/functions/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
}