Merge branch 'master' into tags

This commit is contained in:
Max Brunsfeld 2020-03-11 13:15:26 -07:00
commit 05c1d44e80
2 changed files with 31 additions and 1 deletions

View file

@ -434,6 +434,36 @@ fn test_query_matches_with_named_wildcard() {
});
}
#[test]
fn test_query_matches_with_wildcard_at_the_root() {
allocations::record(|| {
let language = get_language("javascript");
let query = Query::new(
language,
"
(*
(comment) @doc
.
(function_declaration
name: (identifier) @name))
",
)
.unwrap();
let source = "/* one */ var x; /* two */ function y() {} /* three */ class Z {}";
let mut parser = Parser::new();
parser.set_language(language).unwrap();
let tree = parser.parse(source, None).unwrap();
let mut cursor = QueryCursor::new();
let matches = cursor.matches(&query, tree.root_node(), to_callback(source));
assert_eq!(
collect_matches(matches, &query, source),
&[(0, vec![("doc", "/* two */"), ("name", "y")]),]
);
});
}
#[test]
fn test_query_with_immediate_siblings() {
allocations::record(|| {

View file

@ -698,7 +698,7 @@ static TSQueryError ts_query__parse_pattern(
// Parse the wildcard symbol
if (stream->next == '*') {
symbol = NAMED_WILDCARD_SYMBOL;
symbol = depth > 0 ? NAMED_WILDCARD_SYMBOL : WILDCARD_SYMBOL;
stream_advance(stream);
}