Skip to content

Commit

Permalink
Merge pull request #4 from jmespath/sync-tests
Browse files Browse the repository at this point in the history
Update tests to remove hash key order
  • Loading branch information
jamesls committed Aug 5, 2015
2 parents d11f2da + 492f8d0 commit 47fa723
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 54 deletions.
4 changes: 4 additions & 0 deletions tests/filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@
"expression": "reservations[].instances[?bar==`1`]",
"result": [[{"foo": 2, "bar": 1}]]
},
{
"expression": "reservations[*].instances[?bar==`1`]",
"result": [[{"foo": 2, "bar": 1}]]
},
{
"expression": "reservations[].instances[?bar==`1`][]",
"result": [{"foo": 2, "bar": 1}]
Expand Down
16 changes: 13 additions & 3 deletions tests/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@
"result": "object"
},
{
"expression": "keys(objects)",
"result": ["foo", "bar"]
"expression": "sort(keys(objects))",
"result": ["bar", "foo"]
},
{
"expression": "keys(foo)",
Expand All @@ -340,7 +340,7 @@
"error": "invalid-type"
},
{
"expression": "values(objects)",
"expression": "sort(values(objects))",
"result": ["bar", "baz"]
},
{
Expand Down Expand Up @@ -619,6 +619,16 @@
{"age": 50, "age_str": "50", "bool": false, "name": "d"}
]
},
{
"expression": "sort_by(people, &age_str)",
"result": [
{"age": 10, "age_str": "10", "bool": true, "name": 3},
{"age": 20, "age_str": "20", "bool": true, "name": "a", "extra": "foo"},
{"age": 30, "age_str": "30", "bool": true, "name": "c"},
{"age": 40, "age_str": "40", "bool": false, "name": "b", "extra": "bar"},
{"age": 50, "age_str": "50", "bool": false, "name": "d"}
]
},
{
"description": "sort by function expression",
"expression": "sort_by(people, &to_number(age_str))",
Expand Down
48 changes: 35 additions & 13 deletions tests/pipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,69 @@
"given": {
"foo": {
"bar": {
"baz": "one"
"baz": "subkey"
},
"other": {
"baz": "two"
"baz": "subkey"
},
"other2": {
"baz": "three"
"baz": "subkey"
},
"other3": {
"notbaz": ["a", "b", "c"]
},
"other4": {
"notbaz": ["d", "e", "f"]
"notbaz": ["a", "b", "c"]
}
}
},
"cases": [
{
"expression": "foo.*.baz | [0]",
"result": "one"
"result": "subkey"
},
{
"expression": "foo.*.baz | [1]",
"result": "two"
"result": "subkey"
},
{
"expression": "foo.*.baz | [2]",
"result": "three"
"result": "subkey"
},
{
"expression": "foo.bar.* | [0]",
"result": "one"
"result": "subkey"
},
{
"expression": "foo.*.notbaz | [*]",
"result": [["a", "b", "c"], ["d", "e", "f"]]
"result": [["a", "b", "c"], ["a", "b", "c"]]
},
{
"expression": "{\"a\": foo.bar, \"b\": foo.other} | *.baz",
"result": ["subkey", "subkey"]
}
]
}, {
"given": {
"foo": {
"bar": {
"baz": "one"
},
"other": {
"baz": "two"
},
"other2": {
"baz": "three"
},
"other3": {
"notbaz": ["a", "b", "c"]
},
"other4": {
"notbaz": ["d", "e", "f"]
}
}
},
"cases": [
{
"expression": "foo | bar",
"result": {"baz": "one"}
Expand Down Expand Up @@ -71,10 +97,6 @@
"expression": "{\"a\": foo.bar, \"b\": foo.other} | b",
"result": {"baz": "two"}
},
{
"expression": "{\"a\": foo.bar, \"b\": foo.other} | *.baz",
"result": ["one", "two"]
},
{
"expression": "foo.bam || foo.bar | baz",
"result": "one"
Expand Down
84 changes: 46 additions & 38 deletions tests/wildcard.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,82 @@
"given": {
"foo": {
"bar": {
"baz": "one"
"baz": "val"
},
"other": {
"baz": "two"
"baz": "val"
},
"other2": {
"baz": "three"
"baz": "val"
},
"other3": {
"notbaz": ["a", "b", "c"]
},
"other4": {
"notbaz": ["d", "e", "f"]
"notbaz": ["a", "b", "c"]
},
"other5": {
"other": {
"a": 1,
"b": 2,
"c": 3
"b": 1,
"c": 1
}
}
}
},
"cases": [
{
"expression": "foo.*.baz",
"result": ["one", "two", "three"]
"result": ["val", "val", "val"]
},
{
"expression": "foo.bar.*",
"result": ["one"]
"result": ["val"]
},
{
"expression": "foo.*.notbaz",
"result": [["a", "b", "c"], ["d", "e", "f"]]
"result": [["a", "b", "c"], ["a", "b", "c"]]
},
{
"expression": "foo.*.notbaz[0]",
"result": ["a", "d"]
"result": ["a", "a"]
},
{
"expression": "foo.*.notbaz[-1]",
"result": ["c", "f"]
},
"result": ["c", "c"]
}
]
}, {
"given": {
"foo": {
"first-1": {
"second-1": "val"
},
"first-2": {
"second-1": "val"
},
"first-3": {
"second-1": "val"
}
}
},
"cases": [
{
"expression": "foo.*",
"result": [{"baz": "one"}, {"baz": "two"}, {"baz": "three"},
{"notbaz": ["a", "b", "c"]}, {"notbaz": ["d", "e", "f"]},
{"other": {"a": 1, "b": 2, "c": 3}}]
"result": [{"second-1": "val"}, {"second-1": "val"},
{"second-1": "val"}]
},
{
"expression": "foo.*.*",
"result": [["one"], ["two"], ["three"],
[["a", "b", "c"]], [["d", "e", "f"]],
[{"a": 1, "b": 2, "c": 3}]]
"result": [["val"], ["val"], ["val"]]
},
{
"expression": "foo.*.*.*",
"result": [[], [], [], [], [], [[1, 2, 3]]]
"result": [[], [], []]
},
{
"expression": "foo.*.*.*.*",
"result": [[], [], [], [], [], [[]]]
"result": [[], [], []]
}
]
}, {
Expand All @@ -73,7 +86,7 @@
"bar": "one"
},
"other": {
"bar": "two"
"bar": "one"
},
"nomatch": {
"notbar": "three"
Expand All @@ -82,7 +95,7 @@
"cases": [
{
"expression": "*.bar",
"result": ["one", "two"]
"result": ["one", "one"]
}
]
}, {
Expand All @@ -91,37 +104,32 @@
"sub1": {"foo": "one"}
},
"top2": {
"sub1": {"foo": "two"}
},
"top3": {
"sub3": {"notfoo": "notfoo"}
"sub1": {"foo": "one"}
}
},
"cases": [
{
"expression": "*",
"result": [{"sub1": {"foo": "one"}},
{"sub1": {"foo": "two"}},
{ "sub3": {"notfoo": "notfoo"}}]
{"sub1": {"foo": "one"}}]
},
{
"expression": "*.sub1",
"result": [{"foo": "one"},
{"foo": "two"}]
{"foo": "one"}]
},
{
"expression": "*.*",
"result": [[{"foo": "one"}],
[{"foo": "two"}],
[{"notfoo": "notfoo"}]]
[{"foo": "one"}]]
},
{
"expression": "*.*.foo",
"result": [["one"], ["two"], []]
"expression": "*.*.foo[]",
"result": ["one", "one"]
},
{
"expression": "*.sub1.foo",
"result": ["one", "two"]
"result": ["one", "one"]
}
]
},
Expand Down Expand Up @@ -409,7 +417,7 @@
{
"given": {
"string": "string",
"hash": {"foo": "bar", "bar": "baz"},
"hash": {"foo": "val", "bar": "val"},
"number": 23,
"array": [1, 2, 3],
"nullvalue": null
Expand All @@ -421,7 +429,7 @@
},
{
"expression": "hash.*",
"result": ["bar", "baz"]
"result": ["val", "val"]
},
{
"expression": "number.*",
Expand All @@ -440,12 +448,12 @@
{
"given": {
"a": [0, 1, 2],
"b": [3, 4, 5]
"b": [0, 1, 2]
},
"cases": [
{
"expression": "*[0]",
"result": [0, 3]
"result": [0, 0]
}
]
}
Expand Down

0 comments on commit 47fa723

Please sign in to comment.