This commit is contained in:
Eric Vergnaud 2021-02-13 02:29:55 +08:00
parent 64d49cc4d8
commit 25196001d7
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import antlr4 from "../antlr4/index.js";
it("merges interval sets properly", () => {
const s1 = new antlr4.IntervalSet();
s1.addOne(10);
expect(s1.toString()).toEqual("10");
const s2 = new antlr4.IntervalSet();
s2.addOne(12);
expect(s2.toString()).toEqual("12");
const merged = new antlr4.IntervalSet();
merged.addSet(s1);
expect(merged.toString()).toEqual("10");
merged.addSet(s2);
expect(merged.toString()).toEqual("{10, 12}");
let s3 = new antlr4.IntervalSet();
s3.addOne(10);
merged.addSet(s3);
expect(merged.toString()).toEqual("{10, 12}");
s3 = new antlr4.IntervalSet();
s3.addOne(11);
merged.addSet(s3);
expect(merged.toString()).toEqual("10..12");
s3 = new antlr4.IntervalSet();
s3.addOne(12);
merged.addSet(s3);
expect(merged.toString()).toEqual("10..12");
});