Fix false positive query match bug, introduced in #2085

This commit is contained in:
Max Brunsfeld 2023-06-26 17:18:05 -07:00 committed by Amaan Qureshi
parent 3504aa3260
commit 356f68293a
3 changed files with 81 additions and 45 deletions

View file

@ -318,8 +318,8 @@ pub fn assert_query_matches(
let tree = parser.parse(source, None).unwrap();
let mut cursor = QueryCursor::new();
let matches = cursor.matches(&query, tree.root_node(), source.as_bytes());
assert_eq!(collect_matches(matches, &query, source), expected);
assert_eq!(cursor.did_exceed_match_limit(), false);
pretty_assertions::assert_eq!(collect_matches(matches, &query, source), expected);
pretty_assertions::assert_eq!(cursor.did_exceed_match_limit(), false);
}
pub fn collect_matches<'a>(

View file

@ -853,6 +853,33 @@ fn test_query_matches_with_wildcard_at_the_root() {
});
}
#[test]
fn test_query_matches_with_wildcard_within_wildcard() {
allocations::record(|| {
let language = get_language("javascript");
let query = Query::new(
language,
"
(_ (_) @child) @parent
",
)
.unwrap();
assert_query_matches(
language,
&query,
"/* a */ b; c;",
&[
(0, vec![("parent", "/* a */ b; c;"), ("child", "/* a */")]),
(0, vec![("parent", "/* a */ b; c;"), ("child", "b;")]),
(0, vec![("parent", "b;"), ("child", "b")]),
(0, vec![("parent", "/* a */ b; c;"), ("child", "c;")]),
(0, vec![("parent", "c;"), ("child", "c")]),
],
);
});
}
#[test]
fn test_query_matches_with_immediate_siblings() {
allocations::record(|| {
@ -1166,11 +1193,20 @@ fn test_query_matches_with_non_terminal_repetitions_within_root() {
language,
&query,
r#"
function f() {
d;
e;
f;
g;
}
a;
b;
c;
"#,
&[(0, vec![("id", "a"), ("id", "b"), ("id", "c")])],
&[
(0, vec![("id", "d"), ("id", "e"), ("id", "f"), ("id", "g")]),
(0, vec![("id", "a"), ("id", "b"), ("id", "c")]),
],
);
});
}