-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathex_json_path_test.exs
More file actions
723 lines (538 loc) · 19.2 KB
/
ex_json_path_test.exs
File metadata and controls
723 lines (538 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
#
# This file is part of ExJSONPath.
#
# Copyright 2019,2020 Ispirata Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
defmodule ExJSONPathTest do
use ExUnit.Case
doctest ExJSONPath
alias ExJSONPath.ParsingError
test "eval $.hello.world" do
map = %{"hello" => %{"world" => "test"}}
path = "$.hello.world"
assert ExJSONPath.eval(map, path) == {:ok, ["test"]}
end
test "eval $.hello.world.this.is.missing doesn't match" do
map = %{"hello" => %{"world" => "test"}}
path = "$.hello.world.this.is.missing"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
# there are two Goessner's implementations, one returns [[]], while the other returns [{}]
# most other implementations return [{}].
# This implementation will return [{}]
test "eval $.foo.bar with empty obj. 'bar' returns {}" do
map = %{"foo" => %{"bar" => %{}}}
path = "$.foo.bar"
assert ExJSONPath.eval(map, path) == {:ok, [%{}]}
end
test "eval $.hello[0] on an object doesn't match" do
map = %{"hello" => %{"world" => "test"}}
path = "$.hello[0]"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $.hello.world[0] on a string doesn't match" do
map = %{"hello" => %{"world" => "test"}}
path = "$.hello.world[0]"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
# goessner's implementation (and others) return [["test"]] here.
# Few other implementations will return ["test"].
# Here we behave like goessner's one.
test "eval $.hello.world returns a single value array" do
map = %{"hello" => %{"world" => ["test"]}}
path = "$.hello.world"
assert ExJSONPath.eval(map, path) == {:ok, [["test"]]}
end
test "eval $.data.values[1] returns an array item" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = "$.data.values[1]"
assert ExJSONPath.eval(map, path) == {:ok, [-1]}
end
# Goessner's implementation supports this syntax.
# Also this is required for consistency reasons with .. operator.
test "eval $.data.values.1 returns an array item" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = "$.data.values.1"
assert ExJSONPath.eval(map, path) == {:ok, [-1]}
end
test "eval $.data.values[4] which causes an out of bonds access" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = "$.data.values[4]"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $.data.missing[0] on missing key doesn't match" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = "$.data.missing[0]"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $.data.values.missing doesn't match" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = "$.data.values.missing"
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $[0] on array root item" do
array = [10, 11, 12, 13]
path = "$[0]"
assert ExJSONPath.eval(array, path) == {:ok, [10]}
end
test "eval $.data.values[1].value" do
map = %{"data" => %{"values" => [%{"value" => 0.1}, %{"value" => 0.2}, %{"value" => 0.3}]}}
path = "$.data.values[1].value"
assert ExJSONPath.eval(map, path) == {:ok, [0.2]}
end
test ~s{eval $.data[0].values[?(@.name == "test")].value filters an array of objects} do
map = %{
"data" => [
%{
"values" => [
%{"value" => 0.1, "name" => "foo"},
%{"value" => 0.2, "name" => "bar"},
%{"value" => 0.3, "name" => "test"}
]
}
]
}
path = ~s{$.data[0].values[?(@.name == "test")].value}
assert ExJSONPath.eval(map, path) == {:ok, [0.3]}
end
test ~s{eval $.data[0].values[?(@.name == "test")].value filters an array with missing keys} do
map = %{
"data" => [
%{
"values" => [
%{"value" => 0.0, "name" => "test"},
%{"name" => "foo"},
%{"value" => 0.2},
%{"value" => 0.3, "name" => "test"},
%{"value" => 0.4, "name" => "bar"}
]
}
]
}
path = ~s{$.data[0].values[?(@.name == "test")].value}
assert ExJSONPath.eval(map, path) == {:ok, [0.0, 0.3]}
end
test ~s{eval $.data[0].values[?(@.k == "a")].v filters an objects array with array values} do
map = %{
"data" => [
%{
"values" => [
%{"v" => [0.0], "k" => "a"},
%{"k" => "c"},
%{"v" => [0.2]},
%{"v" => [0.3], "k" => "a"},
%{"v" => [0.4], "k" => "b"}
]
}
]
}
path = ~s{$.data[0].values[?(@.k == "a")].v}
assert ExJSONPath.eval(map, path) == {:ok, [[0.0], [0.3]]}
end
test ~s{eval $.data[0].values[?(@.name == "test")].value filters a map} do
map = %{
"data" => [
%{
"values" => %{
"a" => %{"value" => 0.1, "name" => "foo"},
"b" => %{"value" => 0.2, "name" => "bar"},
"c" => %{"value" => 0.3, "name" => "test"}
}
}
]
}
path = ~s{$.data[0].values[?(@.name == "test")].value}
assert ExJSONPath.eval(map, path) == {:ok, [0.3]}
end
test ~s{eval $.data[0].values[?(@.name == "test")].value filters a map and returns 2 items} do
map = %{
"data" => [
%{
"values" => %{
"a" => %{"value" => 0.1, "name" => "test"},
"b" => %{"value" => 0.2, "name" => "bar"},
"c" => %{"value" => 0.3, "name" => "test"}
}
}
]
}
path = ~s{$.data[0].values[?(@.name == "test")].value}
assert ExJSONPath.eval(map, path) == {:ok, [0.1, 0.3]}
end
# This is not described [here](https://goessner.net/articles/JsonPath/)
# but his implementation supports it, and nearly every other implementation.
test "eval hello" do
map = %{"hello" => %{"world" => "test"}}
path = "hello"
assert ExJSONPath.eval(map, path) == {:ok, [%{"world" => "test"}]}
end
# This is not described [here](https://goessner.net/articles/JsonPath/)
# but his implementation supports it, and nearly every other implementation.
test "eval hello.world" do
map = %{"hello" => %{"world" => "test"}}
path = "hello.world"
assert ExJSONPath.eval(map, path) == {:ok, ["test"]}
end
# This shortcut is supported by fewer implementations, however I think it must be supported
# for consistency reasons: "keyname" shortcut is already supported for objects, thefore [index]
# is a reasonable extension.
# Goessner's implementation does not support it.
test "eval [3]" do
array = [10, 11, 12, 13]
path = "[3]"
assert ExJSONPath.eval(array, path) == {:ok, [13]}
end
# This is supported by Goessner's implementation and some others.
test "eval 3" do
array = [10, 11, 12, 13]
path = "3"
assert ExJSONPath.eval(array, path) == {:ok, [13]}
end
# This is supported by Goessner's implementation and some others.
test "eval 1.name" do
array = [%{"name" => "zero"}, %{"name" => "one"}, %{"name" => "two"}]
path = "1.name"
assert ExJSONPath.eval(array, path) == {:ok, ["one"]}
end
# The majority of implementations do not support this, however this is a side effect
# of adding support to "[index]" with minimum changes to our grammar.
# One notable implementation which supports this syntax is the kubectl JSONPath implementation,
# hence I think also a lot of people is used to this syntax,
# which doesn't cause any relevant drawback
test "eval .key" do
map = %{"key" => 42}
path = ".key"
assert ExJSONPath.eval(map, path) == {:ok, [42]}
end
# This is just supported for consistency reasons, since we already support .key
test "eval .1" do
map = [0, 10, 20, 30]
path = ".1"
assert ExJSONPath.eval(map, path) == {:ok, [10]}
end
# Goessner's implementation (and others) do not allow any kind of match on bare values
test "eval $.test on bare values doesn't match" do
value = 5
path = "$.test"
assert ExJSONPath.eval(value, path) == {:ok, []}
end
# Goessner's implementation (and others) do not allow any kind of match on bare values
test "eval $[0] on bare values doesn't match" do
value = true
path = "$[0]"
assert ExJSONPath.eval(value, path) == {:ok, []}
end
# Goessner was not supporting this, however this is handy and supported by most implementations
# https://cburgmer.github.io/json-path-comparison/results/root.html
test "eval $" do
map = %{"a" => %{"b" => 42}}
path = ~s{$}
assert ExJSONPath.eval(map, path) == {:ok, [map]}
end
describe ".. operator" do
test "eval $..a on a nested object" do
map = %{
"a" => 0,
"b" => %{
"a" => 1,
"b" => %{
"a" => 2,
"b" => %{
"a" => 3,
"b" => %{
"a" => 4,
"b" => %{}
}
}
}
}
}
path = ~s{$..a}
assert ExJSONPath.eval(map, path) == {:ok, [0, 1, 2, 3, 4]}
end
test "eval $..missing on a nested object" do
map = %{
"a" => 0,
"b" => %{
"a" => 1,
"b" => %{
"a" => 2,
"b" => %{
"a" => 3,
"b" => %{
"a" => 4,
"b" => %{}
}
}
}
}
}
path = ~s{$..missing}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $..b on a nested object" do
map = %{"a" => 0, "b" => %{"a" => 1, "b" => %{"a" => 2, "b" => %{}}}}
path = ~s{$..b}
assert ExJSONPath.eval(map, path) ==
{:ok, [%{"a" => 1, "b" => %{"a" => 2, "b" => %{}}}, %{"a" => 2, "b" => %{}}, %{}]}
end
test "eval $..k on an array" do
array = [%{"k" => "a"}, %{"k" => "c"}, %{"k" => "b"}]
path = ~s{$..k}
assert ExJSONPath.eval(array, path) == {:ok, ["a", "c", "b"]}
end
test "eval $..k on an empty array" do
array = []
path = ~s{$..k}
assert ExJSONPath.eval(array, path) == {:ok, []}
end
test "eval $..k on an empty object" do
map = %{}
path = ~s{$..k}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test "eval $..2" do
map = %{
"a" => [0, 1, 2],
"b" => %{"c" => [3], "d" => [4, 5, "6"], "e" => %{"f" => [7, 8, [], 10]}}
}
path = ~s{$..2}
assert ExJSONPath.eval(map, path) == {:ok, [2, "6", []]}
end
test "eval $..2 on a nested array" do
array = [1, 2, [5, 6, [7, 8, 9]]]
path = ~s{$..2}
assert ExJSONPath.eval(array, path) == {:ok, [[5, 6, [7, 8, 9]], [7, 8, 9], 9]}
end
test "eval $..1.x on a nested array" do
array = [0, [1, [2, %{"x" => "computer"}]]]
path = ~s{$..1.x}
assert ExJSONPath.eval(array, path) == {:ok, ["computer"]}
end
test "eval $..1.x on a nested array with an array leaf" do
array = [0, [1, [2, %{"x" => ["test", -1]}]]]
path = ~s{$..1.x}
assert ExJSONPath.eval(array, path) == {:ok, [["test", -1]]}
end
end
describe "wildcard operator" do
test "eval $.*" do
map = %{"data" => %{"values" => [0, -1, 1, -2]}}
path = ~s{$.*}
assert ExJSONPath.eval(map, path) == {:ok, [%{"values" => [0, -1, 1, -2]}]}
end
test "eval $.*.values.* on an object" do
map = %{"data" => %{"values" => [%{"a" => 1}, %{"b" => 2}]}}
path = ~s{$.*.values.*}
assert ExJSONPath.eval(map, path) == {:ok, [%{"a" => 1}, %{"b" => 2}]}
end
test "eval $.* on an array" do
array = [%{"a" => 1}, %{"b" => 2}]
path = ~s{$.*}
assert ExJSONPath.eval(array, path) == {:ok, [%{"a" => 1}, %{"b" => 2}]}
end
test "eval $.*.*.* on an array" do
array = [%{"a" => %{"x" => 1, "y" => -1}}, %{"b" => %{"x" => -2, "y" => -3, "z" => 0}}]
path = ~s{$.*.*.*}
assert ExJSONPath.eval(array, path) == {:ok, [1, -1, -2, -3, 0]}
end
end
describe "union operator" do
test ~s{eval $.test["a","b","c"]} do
map = %{"test" => %{"a" => 4, "b" => "hello", "c" => 2}}
path = ~s{$.test["a","b","c"]}
assert ExJSONPath.eval(map, path) == {:ok, [4, "hello", 2]}
end
test ~s{eval $.test["c","b","a"]} do
map = %{"test" => %{"a" => 4, "b" => "hello", "c" => 2}}
path = ~s{$.test["c","b","a"]}
assert ExJSONPath.eval(map, path) == {:ok, [2, "hello", 4]}
end
test ~s{eval $.test["c","c","a"]} do
map = %{"test" => %{"a" => 4, "b" => "hello", "c" => 2}}
path = ~s{$.test["c","c","a"]}
assert ExJSONPath.eval(map, path) == {:ok, [2, 2, 4]}
end
test ~s{eval $.test[4,2,0]} do
map = %{"test" => ["0", "1", "2", "3", "4", "5"]}
path = ~s{$.test[4,2,0]}
assert ExJSONPath.eval(map, path) == {:ok, ["4", "2", "0"]}
end
test ~s{eval $.test[0,0,?(@.a == "ok")]} do
map = %{"test" => [%{"b" => "test"}, %{"a" => "foo"}, %{"a" => "ok"}]}
path = ~s{$.test[0,0,?(@.a == "ok")]}
assert ExJSONPath.eval(map, path) ==
{:ok, [%{"b" => "test"}, %{"b" => "test"}, %{"a" => "ok"}]}
end
test ~s{eval $.test[0,100,?(@.a == "ok")]} do
map = %{"test" => [%{"b" => "test"}, %{"a" => "foo"}, %{"a" => "ok"}]}
path = ~s{$.test[0,100,?(@.a == "ok")]}
assert ExJSONPath.eval(map, path) == {:ok, [%{"b" => "test"}, %{"a" => "ok"}]}
end
test ~s{eval $.test[0,0,?(@.a == "ok")].a} do
map = %{"test" => [%{"b" => "test"}, %{"a" => "foo"}, %{"a" => "ok"}]}
path = ~s{$.test[0,0,?(@.a == "ok")].a}
assert ExJSONPath.eval(map, path) == {:ok, ["ok"]}
end
test ~s{eval $.test[0,0,?(@.a == "ok")].z} do
map = %{"test" => [%{"b" => "test"}, %{"a" => "foo"}, %{"a" => "ok"}]}
path = ~s{$.test[0,0,?(@.a == "ok")].z}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
end
describe "slice operator" do
test ~s{eval $.data[0:5]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[0:5]}
assert ExJSONPath.eval(map, path) == {:ok, [0, -1, 2, -3, 4]}
end
# https://cburgmer.github.io/json-path-comparison/results/array_slice_with_range_of_0.html
test ~s{eval $.data[0:0] does not return results} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[0:0]}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test ~s{eval $.data[5:5] does not return results} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[5:5]}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test ~s{eval $.data[0:1]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[0:1]}
assert ExJSONPath.eval(map, path) == {:ok, [0]}
end
# https://cburgmer.github.io/json-path-comparison/results/array_slice_with_range_of_-1.html
test ~s{eval $.data[5:1]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[5:1]}
assert ExJSONPath.eval(map, path) == {:ok, []}
end
test ~s{eval $.data[:5]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[:5]}
assert ExJSONPath.eval(map, path) == {:ok, [0, -1, 2, -3, 4]}
end
test ~s{eval $.data[::2]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[::2]}
assert ExJSONPath.eval(map, path) == {:ok, [0, 2, 4, 6, 8]}
end
test ~s{eval $.data[1::2]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[1::2]}
assert ExJSONPath.eval(map, path) == {:ok, [-1, -3, -5, -7]}
end
test ~s{eval $.data[1:3]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[1:3]}
assert ExJSONPath.eval(map, path) == {:ok, [-1, 2]}
end
test ~s{eval $.data[0:2,7:9]} do
map = %{"data" => [0, -1, 2, -3, 4, -5, 6, -7, 8]}
path = ~s{$.data[0:2,7:9]}
assert ExJSONPath.eval(map, path) == {:ok, [0, -1, -7, 8]}
end
end
describe "eval $[?(@.v OPERATOR 1)] expressions" do
test ~s{with == operator} do
array = [
%{"k" => "a", "v" => 0},
%{"k" => "b", "v" => 1},
%{"k" => "c", "v" => 1},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v == 1)]}
assert ExJSONPath.eval(array, path) ==
{:ok, [%{"k" => "b", "v" => 1}, %{"k" => "c", "v" => 1}]}
end
test ~s{!= operator} do
array = [
%{"k" => "a", "v" => 0},
%{"k" => "b", "v" => 1},
%{"k" => "c", "v" => 1},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v != 1)]}
assert ExJSONPath.eval(array, path) ==
{:ok, [%{"k" => "a", "v" => 0}, %{"k" => "d", "v" => 0}]}
end
test ~s{with > operator} do
array = [
%{"k" => "a", "v" => 0},
%{"k" => "b", "v" => 1},
%{"k" => "c", "v" => 2},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v > 1)]}
assert ExJSONPath.eval(array, path) == {:ok, [%{"k" => "c", "v" => 2}]}
end
test ~s{with >= operator} do
array = [
%{"k" => "a", "v" => 0},
%{"k" => "b", "v" => 1},
%{"k" => "c", "v" => 2},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v >= 1)]}
assert ExJSONPath.eval(array, path) ==
{:ok, [%{"k" => "b", "v" => 1}, %{"k" => "c", "v" => 2}]}
end
test ~s{with < operator} do
array = [
%{"k" => "a", "v" => 0},
%{"k" => "b", "v" => 1},
%{"k" => "c", "v" => 1},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v < 1)]}
assert ExJSONPath.eval(array, path) ==
{:ok, [%{"k" => "a", "v" => 0}, %{"k" => "d", "v" => 0}]}
end
test ~s{with <= operator} do
array = [
%{"k" => "a", "v" => 1},
%{"k" => "b", "v" => 2},
%{"k" => "c", "v" => 3},
%{"k" => "d", "v" => 0}
]
path = ~s{$[?(@.v <= 2)]}
assert ExJSONPath.eval(array, path) ==
{:ok, [%{"v" => 1, "k" => "a"}, %{"k" => "b", "v" => 2}, %{"k" => "d", "v" => 0}]}
end
end
describe "parsing error" do
test ~s{with eval @} do
map = %{"a" => %{"b" => 42}}
path = ~s{@}
assert {:error, %ParsingError{message: "" <> _msg}} = ExJSONPath.eval(map, path)
end
test "with invalid expression" do
map = %{"a" => %{"b" => 42}}
path = ~s{$[?()]}
assert {:error, %ParsingError{message: "" <> _msg}} = ExJSONPath.eval(map, path)
end
test "with unmatched parenthesis" do
map = %{"a" => %{"b" => 42}}
path = ~s{$[?(@.v <= 2]}
assert {:error, %ParsingError{message: "" <> _msg}} = ExJSONPath.eval(map, path)
end
test "with invalid operator" do
array = []
path = ~s{$[?(@.v # 2)]}
assert {:error, %ParsingError{message: "" <> _msg}} = ExJSONPath.eval(array, path)
end
end
end