-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CI checks for TypeScript bindings #16
Comments
Here is an example test we could do for typescript: import { strict as assert } from "node:assert";
import { test } from "node:test";
import { Grammar, LR1Parser, LALR1Parser } from "../src";
// Example grammar
const exampleGrammar = `
P -> E
E -> E '+' T
E -> E '-' T
E -> T
T -> %num
%num -> /[0-9]+/
`;
// Tests for the Grammar class
test("Grammar class tests", async (t) => {
await t.test(
"Grammar.parse should parse a valid grammar without errors",
() => {
const result = Grammar.parse(exampleGrammar);
assert.ok(result.isOk());
assert.ok(result.value instanceof Grammar);
},
);
await t.test("Grammar methods should execute without errors", () => {
const result = Grammar.parse(exampleGrammar);
assert.ok(result.isOk());
const grammar = result.value;
assert.doesNotThrow(() => {
grammar.getSymbols();
grammar.getConstantTokens();
grammar.getStartSymbol();
grammar.getProductions();
grammar.getRegexTokens();
grammar.stringify();
grammar.clone();
});
});
});
// Tests for the LR1Parser and LALR1Parser classes
test("Parser class tests", async (t) => {
const grammarResult = Grammar.parse(exampleGrammar);
assert.ok(grammarResult.isOk());
const grammar = grammarResult.value;
// LR1Parser tests
await t.test(
"LR1Parser.fromGrammar should create a parser without errors",
() => {
const parserResult = LR1Parser.fromGrammar(grammar);
assert.ok(parserResult.isOk());
assert.ok(parserResult.value instanceof LR1Parser);
},
);
await t.test("LR1Parser methods should execute without errors", () => {
const parserResult = LR1Parser.fromGrammar(grammar);
assert.ok(parserResult.isOk());
const parser = parserResult.value;
assert.doesNotThrow(() => {
parser.parse("3 + 4 - 2");
parser.tokenize("3 + 4 - 2");
parser.trace("3 + 4 - 2");
parser.getActionTable();
parser.getGotoTable();
parser.getParseTables();
parser.getAutomaton();
parser.getFirstTable();
parser.getFollowTable();
});
});
// LALR1Parser tests
await t.test(
"LALR1Parser.fromGrammar should create a parser without errors",
() => {
const parserResult = LALR1Parser.fromGrammar(grammar);
assert.ok(parserResult.isOk());
assert.ok(parserResult.value instanceof LALR1Parser);
},
);
await t.test("LALR1Parser methods should execute without errors", () => {
const parserResult = LALR1Parser.fromGrammar(grammar);
assert.ok(parserResult.isOk());
const parser = parserResult.value;
assert.doesNotThrow(() => {
parser.parse("3 + 4 - 2");
parser.tokenize("3 + 4 - 2");
parser.trace("3 + 4 - 2");
parser.getActionTable();
parser.getGotoTable();
parser.getParseTables();
parser.getAutomaton();
parser.getFirstTable();
parser.getFollowTable();
});
});
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since we officially support TypeScript now, we need to ensure it works with changes.
The text was updated successfully, but these errors were encountered: