Skip to content

Commit ed02dce

Browse files
committed
add additional tests for parent operator
1 parent 88478f5 commit ed02dce

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

tests/parents.rs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#[macro_use]
2+
extern crate serde_json;
3+
4+
use common::{read_json, select_and_then_compare, setup};
5+
6+
mod common;
7+
8+
#[test]
9+
fn parent_of_root() {
10+
setup();
11+
12+
for path in &[r#"$^*"#, r#"$^^*"#, r#"$^*^*", r#"$.first^^*"#] {
13+
select_and_then_compare(
14+
path,
15+
json!({"first":"value"}),
16+
json!([]),
17+
);
18+
}
19+
}
20+
21+
#[test]
22+
fn parent_key() {
23+
setup();
24+
25+
for path in &[r#"$.store^expensive"#, r#"$.store.bicycle^^expensive"#] {
26+
select_and_then_compare(
27+
path,
28+
read_json("./benchmark/example.json"),
29+
json!([10]),
30+
);
31+
}
32+
}
33+
34+
#[test]
35+
fn parent_parent() {
36+
setup();
37+
38+
select_and_then_compare(
39+
r#"$.store.bicycle^^expensive"#,
40+
read_json("./benchmark/example.json"),
41+
json!([
42+
10
43+
])
44+
);
45+
46+
select_and_then_compare(
47+
r#"$.store.book[0].author^^^bicycle"#,
48+
read_json("./benchmark/example.json"),
49+
json!([
50+
{
51+
"color": "red",
52+
"price": 19.95
53+
}
54+
])
55+
);
56+
}
57+
58+
#[test]
59+
fn parent_array() {
60+
setup();
61+
62+
select_and_then_compare(
63+
r#"$.store.book[1]^[0]"#,
64+
read_json("./benchmark/example.json"),
65+
json!([
66+
{
67+
"category": "reference",
68+
"author": "Nigel Rees",
69+
"title": "Sayings of the Century",
70+
"price": 8.95
71+
}
72+
])
73+
);
74+
75+
select_and_then_compare(
76+
r#"$.store.book[*]^[0]"#,
77+
read_json("./benchmark/example.json"),
78+
json!([
79+
{
80+
"category": "reference",
81+
"author": "Nigel Rees",
82+
"title": "Sayings of the Century",
83+
"price": 8.95
84+
},
85+
{
86+
"category": "reference",
87+
"author": "Nigel Rees",
88+
"title": "Sayings of the Century",
89+
"price": 8.95
90+
},
91+
{
92+
"category": "reference",
93+
"author": "Nigel Rees",
94+
"title": "Sayings of the Century",
95+
"price": 8.95
96+
},
97+
{
98+
"category": "reference",
99+
"author": "Nigel Rees",
100+
"title": "Sayings of the Century",
101+
"price": 8.95
102+
}
103+
])
104+
);
105+
}
106+
107+
#[test]
108+
fn parent_all() {
109+
setup();
110+
111+
select_and_then_compare(
112+
r#"$.store.bicycle.color^*"#,
113+
read_json("./benchmark/example.json"),
114+
json!([
115+
"red",
116+
19.95
117+
])
118+
);
119+
120+
select_and_then_compare(
121+
r#"$.store.book[0].category^^*.author"#,
122+
read_json("./benchmark/example.json"),
123+
json!([
124+
"Nigel Rees",
125+
"Evelyn Waugh",
126+
"Herman Melville",
127+
"J. R. R. Tolkien"
128+
])
129+
);
130+
}
131+
132+
#[test]
133+
fn parent_after_leaves() {
134+
setup();
135+
136+
select_and_then_compare(
137+
r#"$..author^title"#,
138+
read_json("./benchmark/example.json"),
139+
json!([
140+
"Sayings of the Century",
141+
"Sword of Honour",
142+
"Moby Dick",
143+
"The Lord of the Rings"
144+
])
145+
);
146+
}
147+
148+
#[test]
149+
fn parent_after_filter() {
150+
setup();
151+
152+
select_and_then_compare(
153+
"$.store.book[?(@.price == 12.99)]^^bicycle",
154+
read_json("./benchmark/example.json"),
155+
json!([
156+
{
157+
"color": "red",
158+
"price": 19.95
159+
}
160+
])
161+
);
162+
}

0 commit comments

Comments
 (0)