Skip to content

Commit

Permalink
Sync upstream test from jmespath.test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed May 25, 2022
1 parent 9eb120d commit ebad302
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
4 changes: 4 additions & 0 deletions tests/compliance/boolean.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
"expression": "!False && !EmptyList",
"result": true
},
{
"expression": "!True && False",
"result": false
},
{
"expression": "!(True && False)",
"result": true
Expand Down
44 changes: 44 additions & 0 deletions tests/compliance/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,50 @@
}
]
},
{
"given": {"foo": [{"weight": 33.3},
{"weight": 44.4},
{"weight": 55.5}]},
"cases": [
{
"comment": "Greater than with a number",
"expression": "foo[?weight > `44.4`]",
"result": [{"weight": 55.5}]
},
{
"expression": "foo[?weight >= `44.4`]",
"result": [{"weight": 44.4}, {"weight": 55.5}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight > `55.5`]",
"result": []
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight < `44.4`]",
"result": [{"weight": 33.3}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight <= `44.4`]",
"result": [{"weight": 33.3}, {"weight": 44.4}]
},
{
"comment": "Greater than with a number",
"expression": "foo[?weight < `33.3`]",
"result": []
},
{
"expression": "foo[?weight == `33.3`]",
"result": [{"weight": 33.3}]
},
{
"expression": "foo[?weight != `33.3`]",
"result": [{"weight": 44.4}, {"weight": 55.5}]
}
]
},
{
"given": {"foo": [{"top": {"name": "a"}},
{"top": {"name": "b"}}]},
Expand Down
14 changes: 7 additions & 7 deletions tests/compliance/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,12 @@
"error": "invalid-arity"
},
{
"description": "function projection on single arg function",
"comment": "function projection on single arg function",
"expression": "numbers[].to_string(@)",
"result": ["-1", "3", "4", "5"]
},
{
"description": "function projection on single arg function",
"comment": "function projection on single arg function",
"expression": "array[].to_number(@)",
"result": [-1, 3, 4, 5, 100]
}
Expand All @@ -603,7 +603,7 @@
},
"cases": [
{
"description": "function projection on variadic function",
"comment": "function projection on variadic function",
"expression": "foo[].not_null(f, e, d, c, b, a)",
"result": ["b", "c", "d", "e", "f"]
}
Expand All @@ -621,7 +621,7 @@
},
"cases": [
{
"description": "sort by field expression",
"comment": "sort by field expression",
"expression": "sort_by(people, &age)",
"result": [
{"age": 10, "age_str": "10", "bool": true, "name": 3},
Expand All @@ -642,7 +642,7 @@
]
},
{
"description": "sort by function expression",
"comment": "sort by function expression",
"expression": "sort_by(people, &to_number(age_str))",
"result": [
{"age": 10, "age_str": "10", "bool": true, "name": 3},
Expand All @@ -653,7 +653,7 @@
]
},
{
"description": "function projection on sort_by function",
"comment": "function projection on sort_by function",
"expression": "sort_by(people, &age)[].name",
"result": [3, "a", "c", "b", "d"]
},
Expand Down Expand Up @@ -749,7 +749,7 @@
},
"cases": [
{
"description": "stable sort order",
"comment": "stable sort order",
"expression": "sort_by(people, &age)",
"result": [
{"age": 10, "order": "1"},
Expand Down
10 changes: 10 additions & 0 deletions tests/compliance/literal.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@
"comment": "Can escape the single quote",
"expression": "'foo\\'bar'",
"result": "foo'bar"
},
{
"comment": "Backslash not followed by single quote is treated as any other character",
"expression": "'\\z'",
"result": "\\z"
},
{
"comment": "Backslash not followed by single quote is treated as any other character",
"expression": "'\\\\'",
"result": "\\\\"
}
]
}
Expand Down
14 changes: 14 additions & 0 deletions tests/compliance/syntax.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"expression": "foo.bar",
"result": null
},
{
"expression": "foo",
"result": null
},
{
"expression": "foo.1",
"error": "syntax"
Expand Down Expand Up @@ -416,6 +420,16 @@
"expression": "a.{foo}",
"error": "syntax"
},
{
"comment": "Missing value",
"expression": "a.{foo:}",
"error": "syntax"
},
{
"comment": "Missing value with trailing comma",
"expression": "a.{foo: ,}",
"error": "syntax"
},
{
"comment": "Valid multi-select hash extraction",
"expression": "a.{foo: bar}",
Expand Down

0 comments on commit ebad302

Please sign in to comment.