Allow queries to match on supertypes
Co-authored-by: Ayman Nadeem <aymannadeem@github.com>
This commit is contained in:
parent
f10a8448ed
commit
b5a9adb555
8 changed files with 155 additions and 20 deletions
|
|
@ -701,7 +701,6 @@ fn test_query_matches_with_immediate_siblings() {
|
|||
(2, vec![("last-stmt", "g()")]),
|
||||
],
|
||||
);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1395,6 +1394,45 @@ fn test_query_matches_with_anonymous_tokens() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_supertypes() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("python");
|
||||
let query = Query::new(
|
||||
language,
|
||||
r#"
|
||||
((_simple_statement) @before . (_simple_statement) @after)
|
||||
|
||||
(assignment
|
||||
left: (left_hand_side (identifier) @def))
|
||||
|
||||
(_primary_expression/identifier) @ref
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_query_matches(
|
||||
language,
|
||||
&query,
|
||||
"
|
||||
a = b
|
||||
print c
|
||||
if d: print e.f; print g.h.i
|
||||
",
|
||||
&[
|
||||
(1, vec![("def", "a")]),
|
||||
(2, vec![("ref", "b")]),
|
||||
(0, vec![("before", "a = b"), ("after", "print c")]),
|
||||
(2, vec![("ref", "c")]),
|
||||
(2, vec![("ref", "d")]),
|
||||
(2, vec![("ref", "e")]),
|
||||
(0, vec![("before", "print e.f"), ("after", "print g.h.i")]),
|
||||
(2, vec![("ref", "g")]),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_within_byte_range() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue