Skip to content

Commit

Permalink
Merge pull request #53 from jg-rp/functions-as-function-params
Browse files Browse the repository at this point in the history
Cover function expressions as function parameters
  • Loading branch information
gregsdennis authored Dec 27, 2023
2 parents ca076c0 + d554778 commit 446336c
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
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"]
}
]
}

0 comments on commit 446336c

Please sign in to comment.