fix: Handle quantified predicates on web-tree-sitter properly
Test cases for all new predicates added in #2532
This commit is contained in:
parent
016d8c2499
commit
24e41d2bb7
2 changed files with 128 additions and 33 deletions
|
|
@ -259,6 +259,89 @@ describe("Query", () => {
|
|||
const captures = query.captures(tree.rootNode, null, null, {matchLimit: 32});
|
||||
assert.ok(query.didExceedMatchLimit());
|
||||
});
|
||||
|
||||
it("handles quantified captures properly", () => {
|
||||
let captures;
|
||||
|
||||
tree = parser.parse(`
|
||||
/// foo
|
||||
/// bar
|
||||
/// baz
|
||||
`);
|
||||
|
||||
query = JavaScript.query(`
|
||||
(
|
||||
(comment)+ @foo
|
||||
(#any-eq? @foo "/// foo")
|
||||
)
|
||||
`);
|
||||
|
||||
let expectCount = (tree, queryText, expectedCount) => {
|
||||
query = JavaScript.query(queryText);
|
||||
captures = query.captures(tree.rootNode, null, null);
|
||||
assert.equal(captures.length, expectedCount);
|
||||
};
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#any-eq? @foo "/// foo") ) `,
|
||||
3
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#eq? @foo "/// foo") ) `,
|
||||
0
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#any-not-eq? @foo "/// foo") ) `,
|
||||
3
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#not-eq? @foo "/// foo") ) `,
|
||||
0
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#match? @foo "^/// foo") ) `,
|
||||
0
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#any-match? @foo "^/// foo") ) `,
|
||||
3
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#not-match? @foo "^/// foo") ) `,
|
||||
0
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#not-match? @foo "fsdfsdafdfs") ) `,
|
||||
3
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#any-not-match? @foo "^///") ) `,
|
||||
0
|
||||
);
|
||||
|
||||
expectCount(
|
||||
tree,
|
||||
` ( (comment)+ @foo (#any-not-match? @foo "^/// foo") ) `,
|
||||
3
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
describe(".predicatesForPattern(index)", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue