Skip to content

Commit 4bf7aa2

Browse files
committed
add test
Signed-off-by: tison <wander4096@gmail.com>
1 parent 03f7126 commit 4bf7aa2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spath/tests/spec.rs

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use googletest::matchers::none;
2323
use googletest::prelude::eq;
2424
use googletest::prelude::some;
2525
use insta::assert_compact_json_snapshot;
26+
use serde_json::json;
2627
use spath::NodeList;
2728
use spath::SPath;
2829

@@ -231,5 +232,25 @@ fn test_basic_null_semantic() {
231232

232233
#[test]
233234
fn test_filters() {
235+
// §2.3.5.3 Table 12: Filter Selector Examples
236+
let value = json! {{
237+
"a": [3, 5, 1, 2, 4, 6,
238+
{"b": "j"},
239+
{"b": "k"},
240+
{"b": {}},
241+
{"b": "kilo"}
242+
],
243+
"o": {"p": 1, "q": 2, "r": 3, "s": 5, "t": {"u": 6}},
244+
"e": "f"
245+
}};
234246

247+
let result = eval_spath(r#"$.a[?@.b == 'kilo']"#, &value).unwrap();
248+
let result = result.exactly_one().unwrap();
249+
assert_compact_json_snapshot!(result, @r#"{"b": "kilo"}"#);
250+
let result = eval_spath(r#"$.a[?(@.b == 'kilo')]"#, &value).unwrap();
251+
let result = result.exactly_one().unwrap();
252+
assert_compact_json_snapshot!(result, @r#"{"b": "kilo"}"#);
253+
let result = eval_spath(r#"$.a[?@>3.5]"#, &value).unwrap();
254+
let result = result.all();
255+
assert_compact_json_snapshot!(result, @r#"[5, 4, 6, {"b": "j"}, {"b": "k"}, {"b": {}}, {"b": "kilo"}]"#);
235256
}

0 commit comments

Comments
 (0)