-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgrammar.test.js
28 lines (24 loc) · 1.15 KB
/
grammar.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Grammar from "../src/grammar/index.js";
import assert from "node:assert/strict";
describe("Grammar", function() {
describe("constructor", function() {
it("validates productions", function() {
assert.throws(function() { new Grammar({ a: "1" }); });
assert.throws(function() { new Grammar([{ a: "1" }]); });
assert.throws(function() { new Grammar([[123]]); });
assert.throws(function() { new Grammar([["A", "Grammar.END"]]); });
assert.throws(function() { new Grammar([["A", ""]]); });
assert.throws(function() { new Grammar([[]]); });
assert.throws(function() { new Grammar([]); });
assert.doesNotThrow(function() { new Grammar([["A"]]); });
assert.doesNotThrow(function() { new Grammar([["A", "a"]]); });
});
});
describe("calculations", function() {
it("returns an object with memoized calculation getters", function() {
const grammar = new Grammar([["A", "a"]]);
assert.deepStrictEqual(grammar.calculations.symbols, new Set(["A", "a"]));
assert.deepStrictEqual(Object.getOwnPropertyDescriptor(grammar.calculations, "symbols").value, new Set(["A", "a"]));
});
});
});