Skip to content

Commit

Permalink
Merge pull request #125 from moranje/unicode-checks
Browse files Browse the repository at this point in the history
Fix unicode checks for fallbacks with test
  • Loading branch information
tjvr authored Apr 25, 2019
2 parents c376dab + aabe6b1 commit cf9b14f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions moo.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@

if (unicodeFlag === null) {
unicodeFlag = obj.unicode
} else if (unicodeFlag !== obj.unicode) {
throw new Error("If one rule is /u then all must be")
} else if (unicodeFlag !== obj.unicode && options.fallback === false) {
throw new Error('If one rule is /u then all must be')
}
}

Expand Down
20 changes: 14 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1217,13 +1217,21 @@ describe('include', () => {
})
})

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 rule is /u then all must be'
)
expect(() => compile({a: /foo/, b: /bar/u, c: 'quxx'})).toThrow(
'If one rule is /u then all must be'
)
})

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 rule is /u then all must be")
expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one rule is /u then all must be")
test('unicode rules work with fallback token', () => {
expect(() =>
compile({a: moo.fallback, b: /bar/u, c: /quxx/u})
).not.toThrow()
})

test("supports unicode", () => {
Expand Down

0 comments on commit cf9b14f

Please sign in to comment.