Add wasm tests for lookahead iterator

This commit is contained in:
Daumantas Kavolis 2023-06-16 11:33:00 +03:00
parent ab788619ca
commit e2094ef202
2 changed files with 40 additions and 2 deletions

View file

@ -1013,7 +1013,7 @@ class LookaheadIterable {
}
reset(language, stateId) {
if (C._ts_lookahead_iterator_reset(this[0], language, stateId)) {
if (C._ts_lookahead_iterator_reset(this[0], language[0], stateId)) {
this.language = language;
return true;
}
@ -1028,7 +1028,7 @@ class LookaheadIterable {
if (C._ts_lookahead_iterator_advance(self[0])) {
return { done: false, value: self.currentType };
}
return { done: true, value: "" };
}
};

View file

@ -42,3 +42,41 @@ describe("Language", () => {
});
});
});
describe("Lookahead iterator", () => {
let lookahead;
let state;
before(async () => {
let Parser;
({ JavaScript, Parser } = await require("./helper"));
const parser = new Parser().setLanguage(JavaScript);
const tree = parser.parse("function fn() {}");
const cursor = tree.walk();
cursor.gotoFirstChild();
cursor.gotoFirstChild();
state = cursor.currentNode().nextParseState;
lookahead = JavaScript.lookaheadIterator(state);
assert.exists(lookahead);
});
const expected = ["identifier", "comment", "(", "*", "formal_parameters"];
it("should iterate over valid symbols in the state", () => {
const symbols = Array.from(lookahead);
assert.includeMembers(symbols, expected);
assert.lengthOf(symbols, expected.length);
});
it("should reset to the initial state", () => {
assert(lookahead.resetState(state));
const symbols = Array.from(lookahead);
assert.includeMembers(symbols, expected);
assert.lengthOf(symbols, expected.length);
});
it("should reset", () => {
assert(lookahead.reset(JavaScript, state));
const symbols = Array.from(lookahead);
assert.includeMembers(symbols, expected);
assert.lengthOf(symbols, expected.length);
});
});