|
1 |
| - |
2 | 1 | const fs = require('fs')
|
3 | 2 | const vm = require('vm')
|
4 | 3 |
|
@@ -29,17 +28,14 @@ describe('compiler', () => {
|
29 | 28 | expect(lex4.next()).toMatchObject({type: 'err', text: 'nope!'})
|
30 | 29 | })
|
31 | 30 |
|
32 |
| - test("warns for /g, /y, /i, /m, /u", () => { |
| 31 | + test("warns for /g, /y, /i, /m", () => { |
33 | 32 | expect(() => compile({ word: /foo/ })).not.toThrow()
|
34 | 33 | expect(() => compile({ word: /foo/g })).toThrow('implied')
|
35 | 34 | expect(() => compile({ word: /foo/i })).toThrow('not allowed')
|
36 | 35 | expect(() => compile({ word: /foo/y })).toThrow('implied')
|
37 | 36 | expect(() => compile({ word: /foo/m })).toThrow('implied')
|
38 |
| - expect(() => compile({ word: /foo/u })).toThrow('not allowed') |
39 | 37 | })
|
40 | 38 |
|
41 |
| - // TODO warns if no lineBreaks: true |
42 |
| - |
43 | 39 | test('warns about missing states', () => {
|
44 | 40 | const rules = [
|
45 | 41 | {match: '=', next: 'missing'},
|
@@ -1186,3 +1182,32 @@ describe('include', () => {
|
1186 | 1182 | ])
|
1187 | 1183 | })
|
1188 | 1184 | })
|
| 1185 | + |
| 1186 | + |
| 1187 | +describe("unicode flag", () => { |
| 1188 | + |
| 1189 | + test("allows all rules to be /u", () => { |
| 1190 | + expect(() => compile({ a: /foo/u, b: /bar/u, c: "quxx" })).not.toThrow() |
| 1191 | + expect(() => compile({ a: /foo/u, b: /bar/, c: "quxx" })).toThrow("If one rule is /u then all must be") |
| 1192 | + expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one rule is /u then all must be") |
| 1193 | + }) |
| 1194 | + |
| 1195 | + test("supports unicode", () => { |
| 1196 | + const lexer = compile({ |
| 1197 | + a: /[𝌆]/u, |
| 1198 | + }) |
| 1199 | + lexer.reset("𝌆") |
| 1200 | + expect(lexer.next()).toMatchObject({value: "𝌆"}) |
| 1201 | + lexer.reset("𝌆".charCodeAt(0)) |
| 1202 | + expect(() => lexer.next()).toThrow() |
| 1203 | + |
| 1204 | + const lexer2 = compile({ |
| 1205 | + a: /\u{1D356}/u, |
| 1206 | + }) |
| 1207 | + lexer2.reset("𝍖") |
| 1208 | + expect(lexer2.next()).toMatchObject({value: "𝍖"}) |
| 1209 | + lexer2.reset("\\u{1D356}") |
| 1210 | + expect(() => lexer2.next()).toThrow() |
| 1211 | + }) |
| 1212 | + |
| 1213 | +}) |
0 commit comments