query: Fix last child operator with multiple children

Fixes #806
This commit is contained in:
Max Brunsfeld 2021-03-09 13:40:15 -08:00
parent 24785cdb39
commit 9dc88061d5
2 changed files with 46 additions and 2 deletions

View file

@ -119,6 +119,19 @@ fn test_query_errors_on_invalid_syntax() {
.join("\n")
);
// Need at least one child node for a child anchor
assert_eq!(
Query::new(language, r#"(statement_block .)"#)
.unwrap_err()
.message,
[
//
r#"(statement_block .)"#,
r#" ^"#
]
.join("\n")
);
// tree-sitter/tree-sitter/issues/968
assert_eq!(
Query::new(get_language("c"), r#"(parameter_list [ ")" @foo)"#)
@ -855,6 +868,32 @@ fn test_query_matches_with_immediate_siblings() {
});
}
#[test]
fn test_query_matches_with_last_named_child() {
allocations::record(|| {
let language = get_language("c");
let query = Query::new(
language,
"(compound_statement
(_)
(_)
(expression_statement
(identifier) @last_id) .)",
)
.unwrap();
assert_query_matches(
language,
&query,
"
void one() { a; b; c; }
void two() { d; e; }
void three() { f; g; h; i; }
",
&[(0, vec![("last_id", "c")]), (0, vec![("last_id", "i")])],
);
});
}
#[test]
fn test_query_matches_with_repeated_leaf_nodes() {
allocations::record(|| {