parent
e710a14244
commit
41e9af2456
2 changed files with 32 additions and 4 deletions
|
|
@ -81,6 +81,32 @@ describe("Query", () => {
|
|||
{ pattern: 0, captures: [{ name: "element", text: "g" }] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("handles predicates that compare the text of capture to literal strings", () => {
|
||||
tree = parser.parse(`
|
||||
giraffe(1, 2, []);
|
||||
helment([false]);
|
||||
goat(false);
|
||||
gross(3, []);
|
||||
hiccup([]);
|
||||
gaff(5);
|
||||
`);
|
||||
|
||||
// Find all calls to functions beginning with 'g', where one argument
|
||||
// is an array literal.
|
||||
query = JavaScript.query(`
|
||||
(call_expression
|
||||
function: (identifier) @name
|
||||
arguments: (arguments (array))
|
||||
(#match? @name "^g"))
|
||||
`);
|
||||
|
||||
const matches = query.matches(tree.rootNode);
|
||||
assert.deepEqual(formatMatches(matches), [
|
||||
{ pattern: 0, captures: [{name: "name", text: "giraffe" }] },
|
||||
{ pattern: 0, captures: [{name: "name", text: "gross" }] },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".captures", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue