query: allow repetition operator to be used on non-terminal nodes
This commit is contained in:
parent
f170d292e0
commit
b5483c67ab
2 changed files with 87 additions and 33 deletions
|
|
@ -518,7 +518,7 @@ fn test_query_with_immediate_siblings() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_repeated_nodes() {
|
||||
fn test_query_matches_with_repeated_leaf_nodes() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
|
||||
|
|
@ -584,6 +584,40 @@ fn test_query_matches_with_repeated_nodes() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_repeated_internal_nodes() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
let mut cursor = QueryCursor::new();
|
||||
|
||||
let query = Query::new(
|
||||
language,
|
||||
"
|
||||
(*
|
||||
(method_definition
|
||||
(decorator (identifier) @deco)+
|
||||
name: (property_identifier) @name))
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
let source = "
|
||||
class A {
|
||||
@c
|
||||
@d
|
||||
e() {}
|
||||
}
|
||||
";
|
||||
let tree = parser.parse(source, None).unwrap();
|
||||
let matches = cursor.matches(&query, tree.root_node(), to_callback(source));
|
||||
assert_eq!(
|
||||
collect_matches(matches, &query, source),
|
||||
&[(0, vec![("deco", "c"), ("deco", "d"), ("name", "e")]),]
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_in_language_with_simple_aliases() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue