Skip to content

Commit

Permalink
Add supports unicode test
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed Feb 24, 2019
1 parent 74d26e7 commit e7b4015
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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()
})

})

0 comments on commit e7b4015

Please sign in to comment.