Skip to content

Commit 4f04768

Browse files
committed
Merged compliance tests from jmespath.py.
1 parent d6c74a4 commit 4f04768

11 files changed

+759
-3
lines changed

tests/arithmetic.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"given": {
4+
"a": {
5+
"b": 1
6+
},
7+
"c": {
8+
"d": 2
9+
}
10+
},
11+
"cases": [
12+
{
13+
"expression": "`1` + `2`",
14+
"result": 3.0
15+
},
16+
{
17+
"expression": "`1` - `2`",
18+
"result": -1.0
19+
},
20+
{
21+
"expression": "`2` * `4`",
22+
"result": 8.0
23+
},
24+
{
25+
"expression": "`2` × `4`",
26+
"result": 8.0
27+
},
28+
{
29+
"expression": "`2` / `3`",
30+
"result": 0.6666666666666666
31+
},
32+
{
33+
"expression": "`2` ÷ `3`",
34+
"result": 0.6666666666666666
35+
},
36+
{
37+
"expression": "`10` % `3`",
38+
"result": 1.0
39+
},
40+
{
41+
"expression": "`10` // `3`",
42+
"result": 3.0
43+
},
44+
{
45+
"expression": "-`1` - + `2`",
46+
"result": -3.0
47+
},
48+
{
49+
"expression": "{ ab: a.b, cd: c.d } | ab + cd",
50+
"result": 3.0
51+
},
52+
{
53+
"expression": "{ ab: a.b, cd: c.d } | ab + cd × cd",
54+
"result": 5.0
55+
},
56+
{
57+
"expression": "{ ab: a.b, cd: c.d } | (ab + cd) × cd",
58+
"result": 6.0
59+
}
60+
]
61+
}
62+
]

tests/benchmarks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,31 @@
4242
{
4343
"comment": "simple field",
4444
"expression": "b",
45+
"result": true,
4546
"bench": "full"
4647
},
4748
{
4849
"comment": "simple subexpression",
4950
"expression": "c.d",
51+
"result": true,
5052
"bench": "full"
5153
},
5254
{
5355
"comment": "deep field selection no match",
5456
"expression": "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s",
57+
"result": null,
5558
"bench": "full"
5659
},
5760
{
5861
"comment": "deep field selection",
5962
"expression": "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p",
63+
"result": true,
6064
"bench": "full"
6165
},
6266
{
6367
"comment": "simple or",
6468
"expression": "not_there || b",
69+
"result": true,
6570
"bench": "full"
6671
}
6772
]
@@ -76,26 +81,31 @@
7681
{
7782
"comment": "deep ands",
7883
"expression": "a && b && c && d && e && f && g && h && i && j && k && l && m && n && o && p && q && r && s && t && u && v && w && x && y && z",
84+
"result": 25,
7985
"bench": "full"
8086
},
8187
{
8288
"comment": "deep ors",
8389
"expression": "z || y || x || w || v || u || t || s || r || q || p || o || n || m || l || k || j || i || h || g || f || e || d || c || b || a",
90+
"result": 25,
8491
"bench": "full"
8592
},
8693
{
8794
"comment": "lots of summing",
8895
"expression": "sum([z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a])",
96+
"result": 325,
8997
"bench": "full"
9098
},
9199
{
92100
"comment": "lots of function application",
93101
"expression": "sum([z, sum([y, sum([x, sum([w, sum([v, sum([u, sum([t, sum([s, sum([r, sum([q, sum([p, sum([o, sum([n, sum([m, sum([l, sum([k, sum([j, sum([i, sum([h, sum([g, sum([f, sum([e, sum([d, sum([c, sum([b, a])])])])])])])])])])])])])])])])])])])])])])])])])",
102+
"result": 325,
94103
"bench": "full"
95104
},
96105
{
97106
"comment": "lots of multi list",
98107
"expression": "[z, y, x, w, v, u, t, s, r, q, p, o, n, m, l, k, j, i, h, g, f, e, d, c, b, a]",
108+
"result": [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0],
99109
"bench": "full"
100110
}
101111
]

tests/boolean.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"False": false,
7777
"Number": 5,
7878
"EmptyList": [],
79-
"Zero": 0
79+
"Zero": 0,
80+
"ZeroFloat": 0.0
8081
},
8182
"cases": [
8283
{
@@ -187,6 +188,10 @@
187188
"expression": "!False && !EmptyList",
188189
"result": true
189190
},
191+
{
192+
"expression": "!True && False",
193+
"result": false
194+
},
190195
{
191196
"expression": "!(True && False)",
192197
"result": true
@@ -198,6 +203,14 @@
198203
{
199204
"expression": "!!Zero",
200205
"result": true
206+
},
207+
{
208+
"expression": "Zero || Number",
209+
"result": 0
210+
},
211+
{
212+
"expression": "ZeroFloat || Number",
213+
"result": 0.0
201214
}
202215
]
203216
},

tests/filters.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,50 @@
8080
}
8181
]
8282
},
83+
{
84+
"given": {"foo": [{"weight": 33.3},
85+
{"weight": 44.4},
86+
{"weight": 55.5}]},
87+
"cases": [
88+
{
89+
"comment": "Greater than with a number",
90+
"expression": "foo[?weight > `44.4`]",
91+
"result": [{"weight": 55.5}]
92+
},
93+
{
94+
"expression": "foo[?weight >= `44.4`]",
95+
"result": [{"weight": 44.4}, {"weight": 55.5}]
96+
},
97+
{
98+
"comment": "Greater than with a number",
99+
"expression": "foo[?weight > `55.5`]",
100+
"result": []
101+
},
102+
{
103+
"comment": "Greater than with a number",
104+
"expression": "foo[?weight < `44.4`]",
105+
"result": [{"weight": 33.3}]
106+
},
107+
{
108+
"comment": "Greater than with a number",
109+
"expression": "foo[?weight <= `44.4`]",
110+
"result": [{"weight": 33.3}, {"weight": 44.4}]
111+
},
112+
{
113+
"comment": "Greater than with a number",
114+
"expression": "foo[?weight < `33.3`]",
115+
"result": []
116+
},
117+
{
118+
"expression": "foo[?weight == `33.3`]",
119+
"result": [{"weight": 33.3}]
120+
},
121+
{
122+
"expression": "foo[?weight != `33.3`]",
123+
"result": [{"weight": 44.4}, {"weight": 55.5}]
124+
}
125+
]
126+
},
83127
{
84128
"given": {"foo": [{"top": {"name": "a"}},
85129
{"top": {"name": "b"}}]},
@@ -265,6 +309,88 @@
265309
}
266310
]
267311
},
312+
{
313+
"given": {"foo": [
314+
{"key": true},
315+
{"key": false},
316+
{"key": 0},
317+
{"key": 0.0},
318+
{"key": 1},
319+
{"key": 1.0},
320+
{"key": [0]},
321+
{"key": null},
322+
{"key": [1]},
323+
{"key": []},
324+
{"key": {}},
325+
{"key": {"a":2}}
326+
]},
327+
"cases": [
328+
{
329+
"expression": "foo[?key == `true`]",
330+
"result": [{"key": true}]
331+
},
332+
{
333+
"expression": "foo[?key == `false`]",
334+
"result": [{"key": false}]
335+
},
336+
{
337+
"expression": "foo[?key]",
338+
"result": [
339+
{"key": true},
340+
{"key": 0},
341+
{"key": 0.0},
342+
{"key": 1},
343+
{"key": 1.0},
344+
{"key": [0]},
345+
{"key": [1]},
346+
{"key": {"a": 2}}
347+
]
348+
},
349+
{
350+
"expression": "foo[? !key]",
351+
"result": [
352+
{"key": false},
353+
{"key": null},
354+
{"key": []},
355+
{"key": {}}
356+
]
357+
},
358+
{
359+
"expression": "foo[? !!key]",
360+
"result": [
361+
{"key": true},
362+
{"key": 0},
363+
{"key": 0.0},
364+
{"key": 1},
365+
{"key": 1.0},
366+
{"key": [0]},
367+
{"key": [1]},
368+
{"key": {"a": 2}}
369+
]
370+
},
371+
{
372+
"expression": "foo[? `true`]",
373+
"result": [
374+
{"key": true},
375+
{"key": false},
376+
{"key": 0},
377+
{"key": 0.0},
378+
{"key": 1},
379+
{"key": 1.0},
380+
{"key": [0]},
381+
{"key": null},
382+
{"key": [1]},
383+
{"key": []},
384+
{"key": {}},
385+
{"key": {"a":2}}
386+
]
387+
},
388+
{
389+
"expression": "foo[? `false`]",
390+
"result": []
391+
}
392+
]
393+
},
268394
{
269395
"given": {"reservations": [
270396
{"instances": [

tests/functions.json

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"empty_list": [],
1313
"empty_hash": {},
1414
"objects": {"foo": "bar", "bar": "baz"},
15+
"items": [["a", "first"], ["b", "second"], ["c", "third"]],
1516
"null_key": null
1617
},
1718
"cases": [
@@ -175,6 +176,22 @@
175176
"expression": "floor(str)",
176177
"error": "invalid-type"
177178
},
179+
{
180+
"expression": "sort_by(items(objects), &[0])",
181+
"result": [["bar", "baz"], ["foo", "bar"]]
182+
},
183+
{
184+
"expression": "items(empty_hash)",
185+
"result": []
186+
},
187+
{
188+
"expression": "items(numbers)",
189+
"error": "invalid-type"
190+
},
191+
{
192+
"expression": "from_items(items)",
193+
"result": {"a": "first", "b": "second", "c": "third"}
194+
},
178195
{
179196
"expression": "length('abc')",
180197
"result": 3
@@ -189,7 +206,7 @@
189206
},
190207
{
191208
"expression": "length(@)",
192-
"result": 12
209+
"result": 13
193210
},
194211
{
195212
"expression": "length(strings[0])",
@@ -495,6 +512,10 @@
495512
"expression": "to_number('1.0')",
496513
"result": 1.0
497514
},
515+
{
516+
"expression": "to_number('1e21')",
517+
"result": 1e21
518+
},
498519
{
499520
"expression": "to_number('1.1')",
500521
"result": 1.1
@@ -584,6 +605,18 @@
584605
"comment": "function projection on single arg function",
585606
"expression": "array[].to_number(@)",
586607
"result": [-1, 3, 4, 5, 100]
608+
},
609+
{
610+
"expression": "zip(strings, numbers)",
611+
"result": [["a", -1], ["b", 3], ["c", 4]]
612+
},
613+
{
614+
"expression": "zip(strings, numbers, decimals)",
615+
"result": [["a", -1, 1.01], ["b", 3, 1.2], ["c", 4, -1.5]]
616+
},
617+
{
618+
"expression": "zip(str)",
619+
"error": "invalid-type"
587620
}
588621
]
589622
}, {
@@ -697,6 +730,10 @@
697730
"expression": "max_by(people, &to_number(age_str))",
698731
"result": {"age": 50, "age_str": "50", "bool": false, "name": "d"}
699732
},
733+
{
734+
"expression": "max_by(`[]`, &age)",
735+
"result": null
736+
},
700737
{
701738
"expression": "min_by(people, &age)",
702739
"result": {"age": 10, "age_str": "10", "bool": true, "name": 3}
@@ -716,6 +753,10 @@
716753
{
717754
"expression": "min_by(people, &to_number(age_str))",
718755
"result": {"age": 10, "age_str": "10", "bool": true, "name": 3}
756+
},
757+
{
758+
"expression": "min_by(`[]`, &age)",
759+
"result": null
719760
}
720761
]
721762
}, {

0 commit comments

Comments
 (0)