Skip to content

Commit 4df3ba5

Browse files
committed
Segment test cases.
1 parent 785068d commit 4df3ba5

1 file changed

Lines changed: 96 additions & 4 deletions

File tree

‎tests/test_ietf.py‎

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,104 @@ class Case:
180180
want=[1, {"b": "k"}],
181181
),
182182
# Case(
183-
# description="filter selector - ",
184-
# path="",
183+
# description="filter selector - Array value regular expression match",
184+
# path='$.a[?match(@.b, "[jk]")]',
185185
# data=FILTER_SELECTOR_DATA,
186-
# want=[],
186+
# want=[{"b": "j"}, {"b": "k"}],
187187
# ),
188-
# TODO: child segment examples
188+
# Case(
189+
# description="filter selector - Array value regular expression search",
190+
# path='$.a[?search(@.b, "[jk]")]',
191+
# data=FILTER_SELECTOR_DATA,
192+
# want=[{"b": "j"}, {"b": "k"}, {"b": "kilo"}],
193+
# ),
194+
# Case(
195+
# description="filter selector - Object value logical AND",
196+
# path="$.o[?(@>1 && @<4)]",
197+
# data=FILTER_SELECTOR_DATA,
198+
# want=[2, 3],
199+
# ),
200+
# Case(
201+
# description="filter selector - Object value logical OR",
202+
# path="$.o[?(@.u || @.x)]",
203+
# data=FILTER_SELECTOR_DATA,
204+
# want=[{"u": 6}],
205+
# ),
206+
# Case(
207+
# description="filter selector - Comparison of queries with no values",
208+
# path="$.a[?(@.b == $.x)]",
209+
# data=FILTER_SELECTOR_DATA,
210+
# want=[3, 5, 1, 2, 4, 6],
211+
# ),
212+
Case(
213+
description=(
214+
"filter selector - Comparisons of primitive and of structured values"
215+
),
216+
path="$.a[?(@ == @)]",
217+
data=FILTER_SELECTOR_DATA,
218+
want=[3, 5, 1, 2, 4, 6, {"b": "j"}, {"b": "k"}, {"b": {}}, {"b": "kilo"}],
219+
),
220+
Case(
221+
description=("child segment - Indices"),
222+
path="$[0, 3]",
223+
data=["a", "b", "c", "d", "e", "f", "g"],
224+
want=["a", "d"],
225+
),
226+
Case(
227+
description=("child segment - Slice and index"),
228+
path="$[0:2, 5]",
229+
data=["a", "b", "c", "d", "e", "f", "g"],
230+
want=["a", "b", "f"],
231+
),
232+
Case(
233+
description=("child segment - Duplicated entries"),
234+
path="$[0, 0]",
235+
data=["a", "b", "c", "d", "e", "f", "g"],
236+
want=["a", "a"],
237+
),
238+
Case(
239+
description=("descendant segment - Object values"),
240+
path="$..j",
241+
data={"o": {"j": 1, "k": 2}, "a": [5, 3, [{"j": 4}, {"k": 6}]]},
242+
want=[1, 4],
243+
),
244+
Case(
245+
description=("descendant segment - Array values"),
246+
path="$..[0]",
247+
data={"o": {"j": 1, "k": 2}, "a": [5, 3, [{"j": 4}, {"k": 6}]]},
248+
want=[5, {"j": 4}],
249+
),
250+
Case(
251+
description=("descendant segment - All values"),
252+
path="$..[*]",
253+
data={"o": {"j": 1, "k": 2}, "a": [5, 3, [{"j": 4}, {"k": 6}]]},
254+
want=[
255+
{"j": 1, "k": 2},
256+
[5, 3, [{"j": 4}, {"k": 6}]],
257+
1,
258+
2,
259+
5,
260+
3,
261+
[{"j": 4}, {"k": 6}],
262+
{"j": 4},
263+
{"k": 6},
264+
4,
265+
6,
266+
],
267+
),
268+
Case(
269+
description=("descendant segment - Input value is visited"),
270+
path="$..o",
271+
data={"o": {"j": 1, "k": 2}, "a": [5, 3, [{"j": 4}, {"k": 6}]]},
272+
want=[{"j": 1, "k": 2}],
273+
),
274+
Case(
275+
description=("descendant segment - Multiple segments"),
276+
path="$.a..[0, 1]",
277+
data={"o": {"j": 1, "k": 2}, "a": [5, 3, [{"j": 4}, {"k": 6}]]},
278+
want=[5, {"j": 4}, 3, {"k": 6}],
279+
),
280+
# TODO: semantics of null
189281
]
190282

191283

0 commit comments

Comments
 (0)