Skip to content

Commit

Permalink
add failing test
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Moreno <[email protected]>
  • Loading branch information
joaomoreno committed Apr 29, 2022
1 parent aefa0dd commit d466161
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/query_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ describe("Query", () => {
{ pattern: 0, captures: [{ name: "element", text: "g" }] },
]);
});

it("finds optional nodes even when using #eq? predicate", () => {
const tree = parser.parse(`
{ one: true };
{ one: true, two: true };
`);
const query = new Query(JavaScript, `
(
(object (pair key: (property_identifier) @a) (pair key: (property_identifier) @b)?)
(#eq? @a one)
(#eq? @b two)
)
`);
const matches = query.matches(tree.rootNode);
assert.deepEqual(formatMatches(tree, matches), [
{ pattern: 0, captures: [{ name: 'a', text: 'one' }] },
{ pattern: 0, captures: [{ name: 'a', text: 'one' }, { name: 'b', text: 'two' }] },
]);
});
});

describe(".captures", () => {
Expand Down

0 comments on commit d466161

Please sign in to comment.