Skip to content

Commit

Permalink
Sync compliance tests with JEP 12 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Apr 20, 2015
1 parent 2726291 commit 2c579ba
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 98 deletions.
21 changes: 19 additions & 2 deletions tests/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cases": [
{
"comment": "Matching a literal",
"expression": "foo[?name == `a`]",
"expression": "foo[?name == 'a']",
"result": [{"name": "a"}]
}
]
Expand Down Expand Up @@ -86,7 +86,7 @@
"cases": [
{
"comment": "Filter with subexpression",
"expression": "foo[?top.name == `a`]",
"expression": "foo[?top.name == 'a']",
"result": [{"top": {"name": "a"}}]
}
]
Expand Down Expand Up @@ -294,5 +294,22 @@
"result": []
}
]
},
{
"given": {
"foo": [
{"a": 1, "b": {"c": "x"}},
{"a": 1, "b": {"c": "y"}},
{"a": 1, "b": {"c": "z"}},
{"a": 2, "b": {"c": "z"}},
{"a": 1, "baz": 2}
]
},
"cases": [
{
"expression": "foo[?a==`1`].b.c",
"result": ["x", "y", "z"]
}
]
}
]
120 changes: 82 additions & 38 deletions tests/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"error": "invalid-type"
},
{
"expression": "avg(`abc`)",
"expression": "avg('abc')",
"error": "invalid-type"
},
{
Expand Down Expand Up @@ -100,23 +100,23 @@
"result": -1
},
{
"expression": "ceil(`string`)",
"expression": "ceil('string')",
"error": "invalid-type"
},
{
"expression": "contains(`abc`, `a`)",
"expression": "contains('abc', 'a')",
"result": true
},
{
"expression": "contains(`abc`, `d`)",
"expression": "contains('abc', 'd')",
"result": false
},
{
"expression": "contains(`false`, `d`)",
"expression": "contains(`false`, 'd')",
"error": "invalid-type"
},
{
"expression": "contains(strings, `a`)",
"expression": "contains(strings, 'a')",
"result": true
},
{
Expand All @@ -128,23 +128,23 @@
"result": false
},
{
"expression": "ends_with(str, `r`)",
"expression": "ends_with(str, 'r')",
"result": true
},
{
"expression": "ends_with(str, `tr`)",
"expression": "ends_with(str, 'tr')",
"result": true
},
{
"expression": "ends_with(str, `Str`)",
"expression": "ends_with(str, 'Str')",
"result": true
},
{
"expression": "ends_with(str, `SStr`)",
"expression": "ends_with(str, 'SStr')",
"result": false
},
{
"expression": "ends_with(str, `foo`)",
"expression": "ends_with(str, 'foo')",
"result": false
},
{
Expand All @@ -156,7 +156,7 @@
"result": 1
},
{
"expression": "floor(`string`)",
"expression": "floor('string')",
"error": "invalid-type"
},
{
Expand All @@ -172,11 +172,11 @@
"error": "invalid-type"
},
{
"expression": "length(`abc`)",
"expression": "length('abc')",
"result": 3
},
{
"expression": "length(`\"\"`)",
"expression": "length('')",
"result": 0
},
{
Expand Down Expand Up @@ -239,6 +239,26 @@
"expression": "max(empty_list)",
"result": null
},
{
"expression": "merge(`{}`)",
"result": {}
},
{
"expression": "merge(`{}`, `{}`)",
"result": {}
},
{
"expression": "merge(`{\"a\": 1}`, `{\"b\": 2}`)",
"result": {"a": 1, "b": 2}
},
{
"expression": "merge(`{\"a\": 1}`, `{\"a\": 2}`)",
"result": {"a": 2}
},
{
"expression": "merge(`{\"a\": 1, \"b\": 2}`, `{\"a\": 2, \"c\": 3}`, `{\"d\": 4}`)",
"result": {"a": 2, "b": 2, "c": 3, "d": 4}
},
{
"expression": "min(numbers)",
"result": -1
Expand Down Expand Up @@ -268,7 +288,7 @@
"result": "a"
},
{
"expression": "type(`abc`)",
"expression": "type('abc')",
"result": "string"
},
{
Expand Down Expand Up @@ -332,43 +352,43 @@
"error": "invalid-type"
},
{
"expression": "join(`\", \"`, strings)",
"expression": "join(', ', strings)",
"result": "a, b, c"
},
{
"expression": "join(`, `, strings)",
"expression": "join(', ', strings)",
"result": "a, b, c"
},
{
"expression": "join(`,`, `[\"a\", \"b\"]`)",
"expression": "join(',', `[\"a\", \"b\"]`)",
"result": "a,b"
},
{
"expression": "join(`,`, `[\"a\", 0]`)",
"expression": "join(',', `[\"a\", 0]`)",
"error": "invalid-type"
},
{
"expression": "join(`, `, str)",
"expression": "join(', ', str)",
"error": "invalid-type"
},
{
"expression": "join(`|`, strings)",
"expression": "join('|', strings)",
"result": "a|b|c"
},
{
"expression": "join(`2`, strings)",
"error": "invalid-type"
},
{
"expression": "join(`|`, decimals)",
"expression": "join('|', decimals)",
"error": "invalid-type"
},
{
"expression": "join(`|`, decimals[].to_string(@))",
"expression": "join('|', decimals[].to_string(@))",
"result": "1.01|1.2|-1.5"
},
{
"expression": "join(`|`, empty_list)",
"expression": "join('|', empty_list)",
"result": ""
},
{
Expand All @@ -384,27 +404,27 @@
"result": []
},
{
"expression": "reverse(``)",
"expression": "reverse('')",
"result": ""
},
{
"expression": "reverse(`hello world`)",
"expression": "reverse('hello world')",
"result": "dlrow olleh"
},
{
"expression": "starts_with(str, `S`)",
"expression": "starts_with(str, 'S')",
"result": true
},
{
"expression": "starts_with(str, `St`)",
"expression": "starts_with(str, 'St')",
"result": true
},
{
"expression": "starts_with(str, `Str`)",
"expression": "starts_with(str, 'Str')",
"result": true
},
{
"expression": "starts_with(str, `String`)",
"expression": "starts_with(str, 'String')",
"result": false
},
{
Expand Down Expand Up @@ -432,7 +452,27 @@
"result": 0
},
{
"expression": "to_string(`foo`)",
"expression": "to_array('foo')",
"result": ["foo"]
},
{
"expression": "to_array(`0`)",
"result": [0]
},
{
"expression": "to_array(objects)",
"result": [{"foo": "bar", "bar": "baz"}]
},
{
"expression": "to_array(`[1, 2, 3]`)",
"result": [1, 2, 3]
},
{
"expression": "to_array(false)",
"result": [false]
},
{
"expression": "to_string('foo')",
"result": "foo"
},
{
Expand All @@ -444,19 +484,19 @@
"result": "[0,1]"
},
{
"expression": "to_number(`\"1.0\"`)",
"expression": "to_number('1.0')",
"result": 1.0
},
{
"expression": "to_number(`\"1.1\"`)",
"expression": "to_number('1.1')",
"result": 1.1
},
{
"expression": "to_number(`\"4\"`)",
"expression": "to_number('4')",
"result": 4
},
{
"expression": "to_number(`\"notanumber\"`)",
"expression": "to_number('notanumber')",
"result": null
},
{
Expand Down Expand Up @@ -569,7 +609,7 @@
},
"cases": [
{
"description": "function projection on variadic function",
"description": "sort by field expression",
"expression": "sort_by(people, &age)",
"result": [
{"age": 10, "age_str": "10", "bool": true, "name": 3},
Expand All @@ -580,7 +620,7 @@
]
},
{
"description": "function projection on variadic function",
"description": "sort by function expression",
"expression": "sort_by(people, &to_number(age_str))",
"result": [
{"age": 10, "age_str": "10", "bool": true, "name": 3},
Expand All @@ -591,7 +631,7 @@
]
},
{
"description": "function projection on variadic function",
"description": "function projection on sort_by function",
"expression": "sort_by(people, &age)[].name",
"result": [3, "a", "c", "b", "d"]
},
Expand All @@ -615,6 +655,10 @@
"expression": "sort_by(people, &age)[].extra",
"result": ["foo", "bar"]
},
{
"expression": "sort_by(`[]`, &age)",
"result": []
},
{
"expression": "max_by(people, &age)",
"result": {"age": 50, "age_str": "50", "bool": false, "name": "d"}
Expand Down
Loading

0 comments on commit 2c579ba

Please sign in to comment.