Skip to content

Commit dd4b938

Browse files
committed
Implement using @set values
1 parent cd5f603 commit dd4b938

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/test/rustdoc-json/nested.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
// @is nested.json "$.index[*][?(@.name=='l1')].kind" \"module\"
88
// @is - "$.index[*][?(@.name=='l1')].inner.is_crate" false
99
// @count - "$.index[*][?(@.name=='l1')].inner.items[*]" 2
10-
// @set l1_id = - "$.index[*][?(@.name=='l1')].id"
1110
pub mod l1 {
1211

1312
// @is nested.json "$.index[*][?(@.name=='l3')].kind" \"module\"
1413
// @is - "$.index[*][?(@.name=='l3')].inner.is_crate" false
1514
// @count - "$.index[*][?(@.name=='l3')].inner.items[*]" 1
1615
// @set l3_id = - "$.index[*][?(@.name=='l3')].id"
16+
// @has - "$.index[*][?(@.name=='l1')].inner.items[*]" $l3_id
1717
pub mod l3 {
1818

1919
// @is nested.json "$.index[*][?(@.name=='L4')].kind" \"struct\"
2020
// @is - "$.index[*][?(@.name=='L4')].inner.struct_type" \"unit\"
2121
// @set l4_id = - "$.index[*][?(@.name=='L4')].id"
22+
// @has - "$.index[*][?(@.name=='l3')].inner.items[*]" $l4_id
2223
pub struct L4;
2324
}
2425
// @is nested.json "$.index[*][?(@.inner.span=='l3::L4')].kind" \"import\"

src/tools/jsondocck/src/main.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,15 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
207207
let val = cache.get_value(&command.args[0])?;
208208
match select(&val, &command.args[1]) {
209209
Ok(results) => {
210-
let pat: Value = serde_json::from_str(&command.args[2]).unwrap();
211-
212-
!results.is_empty() && results.into_iter().any(|val| *val == pat)
210+
// FIXME: Share the pat getting code with the `Is` branch.
211+
let v_holder;
212+
let pat: &Value = if command.args[2].starts_with("$") {
213+
&cache.variables[&command.args[2][1..]]
214+
} else {
215+
v_holder = serde_json::from_str(&command.args[2]).unwrap();
216+
&v_holder
217+
};
218+
!results.is_empty() && results.into_iter().any(|val| val == pat)
213219
}
214220
Err(_) => false,
215221
}
@@ -234,8 +240,14 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
234240
let val = cache.get_value(&command.args[0])?;
235241
match select(&val, &command.args[1]) {
236242
Ok(results) => {
237-
let pat: Value = serde_json::from_str(&command.args[2]).unwrap();
238-
results.len() == 1 && *results[0] == pat
243+
let v_holder;
244+
let pat: &Value = if command.args[2].starts_with("$") {
245+
&cache.variables[&command.args[2][1..]]
246+
} else {
247+
v_holder = serde_json::from_str(&command.args[2]).unwrap();
248+
&v_holder
249+
};
250+
results.len() == 1 && results[0] == pat
239251
}
240252
Err(_) => false,
241253
}

0 commit comments

Comments
 (0)