Skip to content

Commit 12f194e

Browse files
committed
More tests
1 parent e17ce5c commit 12f194e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# JSON Path Reference Implementation
22

3+
**WORK IN PROGRESS**
4+
35
See [cts.yaml](tests/cts.yaml) for the Compliance Test Suite and [grammar.pest](src/grammar.pest) for the Parsing Expression Grammar of the Reference Implementation.

src/matchers.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ pub fn new_dot_child_matcher(name: String) -> DotChild {
4444
impl Matcher for DotChild {
4545
fn select<'a>(&self, node: &'a Value) -> Box<dyn Iterator<Item = &'a Value> + 'a> {
4646
if node.is_object() {
47-
Box::new(iter::once(&node.as_object().unwrap()[&self.name]))
47+
let mapping = node.as_object().unwrap();
48+
if mapping.contains_key(&self.name) {
49+
Box::new(iter::once(&mapping[&self.name]))
50+
} else {
51+
Box::new(iter::empty())
52+
}
4853
} else {
4954
Box::new(iter::empty())
5055
}

tests/cts.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ tests:
77
selector: "$.a"
88
document: {"a" : "A", "b" : "B"}
99
result: ["A"]
10+
- name: dot_child_absent
11+
selector: "$.c"
12+
document: {"a" : "A", "b" : "B"}
13+
result: []
14+
- name: dot_child_of_array
15+
selector: "$.a"
16+
document: ["first", "second"]
17+
result: []
1018
- name: wildcarded_child
1119
selector: "$.*"
1220
document: {"a" : "A", "b" : "B"}
1321
result: ["A", "B"]
22+
- name: wildcarded_child_of_array
23+
selector: "$.*"
24+
document: ["first", "second"]
25+
result: []
26+
- name: wildcarded_child_dot_child
27+
selector: "$.*.a"
28+
document: {"x": {"a" : "Ax", "b" : "Bx"}, "y": {"a" : "Ay", "b" : "By"}}
29+
result: ["Ax", "Ay"]

0 commit comments

Comments
 (0)