Skip to content

Commit 95cdb39

Browse files
committed
Separate compliance tests utilizing quoteless literals
To support JEP 11 all the of existing compliance tests that used string literals have been moved out to a tests/legacy/ directory. All the existing tests were updated to use the `"foo"` form. Once JEP 11 is implemented, these can just be updated to the preferred 'foo' form.
1 parent 397da7f commit 95cdb39

File tree

7 files changed

+134
-96
lines changed

7 files changed

+134
-96
lines changed

jmespath/lexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def _token_literal(self, value, start, end):
113113
# don't have to be quoted. This is only true if the
114114
# string doesn't start with chars that could start a valid
115115
# JSON value.
116-
return loads(potential_value)
116+
value = loads(potential_value)
117+
return value
117118
except ValueError:
118119
raise LexerError(lexer_position=start,
119120
lexer_value=value,

tests/compliance/filters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cases": [
55
{
66
"comment": "Matching a literal",
7-
"expression": "foo[?name == `a`]",
7+
"expression": "foo[?name == `\"a\"`]",
88
"result": [{"name": "a"}]
99
}
1010
]
@@ -86,7 +86,7 @@
8686
"cases": [
8787
{
8888
"comment": "Filter with subexpression",
89-
"expression": "foo[?top.name == `a`]",
89+
"expression": "foo[?top.name == `\"a\"`]",
9090
"result": [{"top": {"name": "a"}}]
9191
}
9292
]

tests/compliance/functions.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"error": "invalid-type"
6969
},
7070
{
71-
"expression": "avg(`abc`)",
71+
"expression": "avg(`\"abc\"`)",
7272
"error": "invalid-type"
7373
},
7474
{
@@ -100,23 +100,23 @@
100100
"result": -1
101101
},
102102
{
103-
"expression": "ceil(`string`)",
103+
"expression": "ceil(`\"string\"`)",
104104
"error": "invalid-type"
105105
},
106106
{
107-
"expression": "contains(`abc`, `a`)",
107+
"expression": "contains(`\"abc\"`, `\"a\"`)",
108108
"result": true
109109
},
110110
{
111-
"expression": "contains(`abc`, `d`)",
111+
"expression": "contains(`\"abc\"`, `\"d\"`)",
112112
"result": false
113113
},
114114
{
115-
"expression": "contains(`false`, `d`)",
115+
"expression": "contains(`false`, `\"d\"`)",
116116
"error": "invalid-type"
117117
},
118118
{
119-
"expression": "contains(strings, `a`)",
119+
"expression": "contains(strings, `\"a\"`)",
120120
"result": true
121121
},
122122
{
@@ -128,23 +128,23 @@
128128
"result": false
129129
},
130130
{
131-
"expression": "ends_with(str, `r`)",
131+
"expression": "ends_with(str, `\"r\"`)",
132132
"result": true
133133
},
134134
{
135-
"expression": "ends_with(str, `tr`)",
135+
"expression": "ends_with(str, `\"tr\"`)",
136136
"result": true
137137
},
138138
{
139-
"expression": "ends_with(str, `Str`)",
139+
"expression": "ends_with(str, `\"Str\"`)",
140140
"result": true
141141
},
142142
{
143-
"expression": "ends_with(str, `SStr`)",
143+
"expression": "ends_with(str, `\"SStr\"`)",
144144
"result": false
145145
},
146146
{
147-
"expression": "ends_with(str, `foo`)",
147+
"expression": "ends_with(str, `\"foo\"`)",
148148
"result": false
149149
},
150150
{
@@ -156,7 +156,7 @@
156156
"result": 1
157157
},
158158
{
159-
"expression": "floor(`string`)",
159+
"expression": "floor(`\"string\"`)",
160160
"error": "invalid-type"
161161
},
162162
{
@@ -172,7 +172,7 @@
172172
"error": "invalid-type"
173173
},
174174
{
175-
"expression": "length(`abc`)",
175+
"expression": "length(`\"abc\"`)",
176176
"result": 3
177177
},
178178
{
@@ -288,7 +288,7 @@
288288
"result": "a"
289289
},
290290
{
291-
"expression": "type(`abc`)",
291+
"expression": "type(`\"abc\"`)",
292292
"result": "string"
293293
},
294294
{
@@ -356,39 +356,39 @@
356356
"result": "a, b, c"
357357
},
358358
{
359-
"expression": "join(`, `, strings)",
359+
"expression": "join(`\", \"`, strings)",
360360
"result": "a, b, c"
361361
},
362362
{
363-
"expression": "join(`,`, `[\"a\", \"b\"]`)",
363+
"expression": "join(`\",\"`, `[\"a\", \"b\"]`)",
364364
"result": "a,b"
365365
},
366366
{
367-
"expression": "join(`,`, `[\"a\", 0]`)",
367+
"expression": "join(`\",\"`, `[\"a\", 0]`)",
368368
"error": "invalid-type"
369369
},
370370
{
371-
"expression": "join(`, `, str)",
371+
"expression": "join(`\", \"`, str)",
372372
"error": "invalid-type"
373373
},
374374
{
375-
"expression": "join(`|`, strings)",
375+
"expression": "join(`\"|\"`, strings)",
376376
"result": "a|b|c"
377377
},
378378
{
379379
"expression": "join(`2`, strings)",
380380
"error": "invalid-type"
381381
},
382382
{
383-
"expression": "join(`|`, decimals)",
383+
"expression": "join(`\"|\"`, decimals)",
384384
"error": "invalid-type"
385385
},
386386
{
387-
"expression": "join(`|`, decimals[].to_string(@))",
387+
"expression": "join(`\"|\"`, decimals[].to_string(@))",
388388
"result": "1.01|1.2|-1.5"
389389
},
390390
{
391-
"expression": "join(`|`, empty_list)",
391+
"expression": "join(`\"|\"`, empty_list)",
392392
"result": ""
393393
},
394394
{
@@ -404,27 +404,27 @@
404404
"result": []
405405
},
406406
{
407-
"expression": "reverse(``)",
407+
"expression": "reverse(`\"\"`)",
408408
"result": ""
409409
},
410410
{
411-
"expression": "reverse(`hello world`)",
411+
"expression": "reverse(`\"hello world\"`)",
412412
"result": "dlrow olleh"
413413
},
414414
{
415-
"expression": "starts_with(str, `S`)",
415+
"expression": "starts_with(str, `\"S\"`)",
416416
"result": true
417417
},
418418
{
419-
"expression": "starts_with(str, `St`)",
419+
"expression": "starts_with(str, `\"St\"`)",
420420
"result": true
421421
},
422422
{
423-
"expression": "starts_with(str, `Str`)",
423+
"expression": "starts_with(str, `\"Str\"`)",
424424
"result": true
425425
},
426426
{
427-
"expression": "starts_with(str, `String`)",
427+
"expression": "starts_with(str, `\"String\"`)",
428428
"result": false
429429
},
430430
{
@@ -452,7 +452,7 @@
452452
"result": 0
453453
},
454454
{
455-
"expression": "to_array(`foo`)",
455+
"expression": "to_array(`\"foo\"`)",
456456
"result": ["foo"]
457457
},
458458
{
@@ -472,7 +472,7 @@
472472
"result": [false]
473473
},
474474
{
475-
"expression": "to_string(`foo`)",
475+
"expression": "to_string(`\"foo\"`)",
476476
"result": "foo"
477477
},
478478
{

tests/compliance/literal.json

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@
55
"bar": {"baz": "qux"}
66
},
77
"cases": [
8-
{
9-
"expression": "`foo`",
10-
"result": "foo"
11-
},
128
{
139
"expression": "`\"foo\"`",
1410
"result": "foo"
1511
},
1612
{
17-
"comment": "Double quotes must be escaped.",
18-
"expression": "`foo\\\"quote`",
19-
"result": "foo\"quote"
20-
},
21-
{
22-
"expression": "`✓`",
13+
"expression": "`\"\"`",
2314
"result": ""
2415
},
2516
{
@@ -82,28 +73,23 @@
8273
"expression": "`9`",
8374
"result": 9
8475
},
85-
{
86-
"comment": "Escaping a backtick",
87-
"expression": "`foo\\`bar`",
88-
"result": "foo`bar"
89-
},
9076
{
9177
"comment": "Escaping a backtick in quotes",
9278
"expression": "`\"foo\\`bar\"`",
9379
"result": "foo`bar"
9480
},
9581
{
9682
"comment": "Double quote in literal",
97-
"expression": "`foo\\\"bar`",
83+
"expression": "`\"foo\\\"bar\"`",
9884
"result": "foo\"bar"
9985
},
10086
{
101-
"expression": "`1\\``",
87+
"expression": "`\"1\\`\"`",
10288
"result": "1`"
10389
},
10490
{
10591
"comment": "Multiple literal expressions with escapes",
106-
"expression": "`\\\\`.{a:`b`}",
92+
"expression": "`\"\\\\\"`.{a:`\"b\"`}",
10793
"result": {"a": "b"}
10894
},
10995
{
@@ -122,5 +108,26 @@
122108
"result": 1
123109
}
124110
]
111+
},
112+
{
113+
"comment": "Literals",
114+
"given": {"type": "object"},
115+
"cases": [
116+
{
117+
"comment": "Literal with leading whitespace",
118+
"expression": "` {\"foo\": true}`",
119+
"result": {"foo": true}
120+
},
121+
{
122+
"comment": "Literal with trailing whitespace",
123+
"expression": "`{\"foo\": true} `",
124+
"result": {"foo": true}
125+
},
126+
{
127+
"comment": "Literal on RHS of subexpr not allowed",
128+
"expression": "foo.`\"bar\"`",
129+
"error": "syntax"
130+
}
131+
]
125132
}
126133
]

0 commit comments

Comments
 (0)