diff --git a/test/test.js b/test/test.js index eda3016..b7b9011 100644 --- a/test/test.js +++ b/test/test.js @@ -1184,7 +1184,7 @@ describe('include', () => { }) -describe('RegExp flags', () => { +describe('ignoreCase flag', () => { test("allows all rules to be /i", () => { expect(() => compile({ a: /foo/i, b: /bar/i })).not.toThrow() @@ -1237,22 +1237,6 @@ describe('RegExp flags', () => { })).not.toThrow() }) - test("allows all rules to be /u", () => { - expect(() => compile({ a: /foo/u, b: /bar/u, c: "quxx" })).not.toThrow() - expect(() => compile({ a: /foo/u, b: /bar/, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must") - expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must") - }) - - test("allows all rules to be /ui", () => { - expect(() => compile({ a: /foo/ui, b: /bar/ui })).not.toThrow() - expect(() => compile({ a: /foo/u, b: /bar/i })).toThrow("If one rule ignores case then all must") - expect(() => compile({ a: /foo/i, b: /bar/u })).toThrow("If one rule ignores case then all must") - expect(() => compile({ a: /foo/ui, b: /bar/i })).toThrow("If one RegExp sets the unicode flag then all must") - expect(() => compile({ a: /foo/ui, b: /bar/u })).toThrow("If one rule ignores case then all must") - expect(() => compile({ a: /foo/i, b: /bar/ui })).toThrow("If one RegExp sets the unicode flag then all must") - expect(() => compile({ a: /foo/u, b: /bar/ui })).toThrow("If one rule ignores case then all must") - }) - test("supports ignoreCase for everything", () => { const lexer = compile({ a: /foo/i, @@ -1278,3 +1262,42 @@ describe('RegExp flags', () => { }) }) + + +describe("unicode flag", () => { + + test("allows all rules to be /u", () => { + expect(() => compile({ a: /foo/u, b: /bar/u, c: "quxx" })).not.toThrow() + expect(() => compile({ a: /foo/u, b: /bar/, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must") + expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must") + }) + + test("allows all rules to be /ui", () => { + expect(() => compile({ a: /foo/ui, b: /bar/ui })).not.toThrow() + expect(() => compile({ a: /foo/u, b: /bar/i })).toThrow("If one rule ignores case then all must") + expect(() => compile({ a: /foo/i, b: /bar/u })).toThrow("If one rule ignores case then all must") + expect(() => compile({ a: /foo/ui, b: /bar/i })).toThrow("If one RegExp sets the unicode flag then all must") + expect(() => compile({ a: /foo/ui, b: /bar/u })).toThrow("If one rule ignores case then all must") + expect(() => compile({ a: /foo/i, b: /bar/ui })).toThrow("If one RegExp sets the unicode flag then all must") + expect(() => compile({ a: /foo/u, b: /bar/ui })).toThrow("If one rule ignores case then all must") + }) + + test("supports unicode", () => { + const lexer = compile({ + a: /[𝌆]/u, + }) + lexer.reset("𝌆") + expect(lexer.next()).toMatchObject({value: "𝌆"}) + lexer.reset("𝌆".charCodeAt(0)) + expect(() => lexer.next()).toThrow() + + const lexer2 = compile({ + a: /\u{1D356}/u, + }) + lexer2.reset("𝍖") + expect(lexer2.next()).toMatchObject({value: "𝍖"}) + lexer2.reset("\\u{1D356}") + expect(() => lexer2.next()).toThrow() + }) + +})