Add test_query_max_start_depth_more
This commit is contained in:
parent
41ec8b4166
commit
7b01d8ee05
1 changed files with 72 additions and 0 deletions
|
|
@ -4723,3 +4723,75 @@ fn test_consecutive_zero_or_modifiers() {
|
|||
assert_eq!(len_1, test.contains("???"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_max_start_depth_more() {
|
||||
struct Row {
|
||||
depth: u32,
|
||||
matches: &'static [(usize, &'static [(&'static str, &'static str)])],
|
||||
}
|
||||
|
||||
let source = indoc! {"
|
||||
{
|
||||
{ }
|
||||
{
|
||||
{ }
|
||||
}
|
||||
}
|
||||
"};
|
||||
|
||||
#[rustfmt::skip]
|
||||
let rows = &[
|
||||
Row {
|
||||
depth: 0,
|
||||
matches: &[
|
||||
(0, &[("capture", "{\n { }\n {\n { }\n }\n}")])
|
||||
]
|
||||
},
|
||||
Row {
|
||||
depth: 1,
|
||||
matches: &[
|
||||
(0, &[("capture", "{\n { }\n {\n { }\n }\n}")]),
|
||||
(0, &[("capture", "{ }")]),
|
||||
(0, &[("capture", "{\n { }\n }")])
|
||||
]
|
||||
},
|
||||
Row {
|
||||
depth: 2,
|
||||
matches: &[
|
||||
(0, &[("capture", "{\n { }\n {\n { }\n }\n}")]),
|
||||
(0, &[("capture", "{ }")]),
|
||||
(0, &[("capture", "{\n { }\n }")]),
|
||||
(0, &[("capture", "{ }")]),
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
allocations::record(|| {
|
||||
let language = get_language("c");
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
let tree = parser.parse(source, None).unwrap();
|
||||
let mut cursor = QueryCursor::new();
|
||||
let query = Query::new(language, "(compound_statement) @capture").unwrap();
|
||||
|
||||
let mut matches = cursor.matches(&query, tree.root_node(), source.as_bytes());
|
||||
let node = matches.next().unwrap().captures[0].node;
|
||||
assert_eq!(node.kind(), "compound_statement");
|
||||
|
||||
for row in rows.iter() {
|
||||
eprintln!(" depth: {}", row.depth);
|
||||
|
||||
cursor.set_max_start_depth(row.depth);
|
||||
|
||||
let matches = cursor.matches(&query, node, source.as_bytes());
|
||||
let expected = row
|
||||
.matches
|
||||
.iter()
|
||||
.map(|x| (x.0, x.1.to_vec()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(collect_matches(matches, &query, source), expected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue