Fix handling of single-node patterns in tree queries

This commit is contained in:
Max Brunsfeld 2019-09-11 14:44:49 -07:00
parent ad3f21b0e5
commit beb5eec7d9
2 changed files with 33 additions and 1 deletions

View file

@ -311,6 +311,37 @@ fn test_query_exec_too_many_match_permutations_to_track() {
});
}
#[test]
fn test_query_exec_with_anonymous_tokens() {
allocations::record(|| {
let language = get_language("javascript");
let query = Query::new(
language,
r#"
";" @ punctuation
"&&" @ operator
"#,
)
.unwrap();
let source = "foo(a && b);";
let mut parser = Parser::new();
parser.set_language(language).unwrap();
let tree = parser.parse(&source, None).unwrap();
let context = query.context();
let matches = context.exec(tree.root_node());
assert_eq!(
collect_matches(matches, &query, source),
&[
(1, vec![("operator", "&&")]),
(0, vec![("punctuation", ";")]),
]
);
});
}
#[test]
fn test_query_capture_names() {
allocations::record(|| {