Skip to content

Commit e7b4015

Browse files
committed
Add supports unicode test
1 parent 74d26e7 commit e7b4015

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

test/test.js

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ describe('include', () => {
11841184
})
11851185

11861186

1187-
describe('RegExp flags', () => {
1187+
describe('ignoreCase flag', () => {
11881188

11891189
test("allows all rules to be /i", () => {
11901190
expect(() => compile({ a: /foo/i, b: /bar/i })).not.toThrow()
@@ -1237,22 +1237,6 @@ describe('RegExp flags', () => {
12371237
})).not.toThrow()
12381238
})
12391239

1240-
test("allows all rules to be /u", () => {
1241-
expect(() => compile({ a: /foo/u, b: /bar/u, c: "quxx" })).not.toThrow()
1242-
expect(() => compile({ a: /foo/u, b: /bar/, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must")
1243-
expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must")
1244-
})
1245-
1246-
test("allows all rules to be /ui", () => {
1247-
expect(() => compile({ a: /foo/ui, b: /bar/ui })).not.toThrow()
1248-
expect(() => compile({ a: /foo/u, b: /bar/i })).toThrow("If one rule ignores case then all must")
1249-
expect(() => compile({ a: /foo/i, b: /bar/u })).toThrow("If one rule ignores case then all must")
1250-
expect(() => compile({ a: /foo/ui, b: /bar/i })).toThrow("If one RegExp sets the unicode flag then all must")
1251-
expect(() => compile({ a: /foo/ui, b: /bar/u })).toThrow("If one rule ignores case then all must")
1252-
expect(() => compile({ a: /foo/i, b: /bar/ui })).toThrow("If one RegExp sets the unicode flag then all must")
1253-
expect(() => compile({ a: /foo/u, b: /bar/ui })).toThrow("If one rule ignores case then all must")
1254-
})
1255-
12561240
test("supports ignoreCase for everything", () => {
12571241
const lexer = compile({
12581242
a: /foo/i,
@@ -1278,3 +1262,42 @@ describe('RegExp flags', () => {
12781262
})
12791263

12801264
})
1265+
1266+
1267+
describe("unicode flag", () => {
1268+
1269+
test("allows all rules to be /u", () => {
1270+
expect(() => compile({ a: /foo/u, b: /bar/u, c: "quxx" })).not.toThrow()
1271+
expect(() => compile({ a: /foo/u, b: /bar/, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must")
1272+
expect(() => compile({ a: /foo/, b: /bar/u, c: "quxx" })).toThrow("If one RegExp sets the unicode flag then all must")
1273+
})
1274+
1275+
test("allows all rules to be /ui", () => {
1276+
expect(() => compile({ a: /foo/ui, b: /bar/ui })).not.toThrow()
1277+
expect(() => compile({ a: /foo/u, b: /bar/i })).toThrow("If one rule ignores case then all must")
1278+
expect(() => compile({ a: /foo/i, b: /bar/u })).toThrow("If one rule ignores case then all must")
1279+
expect(() => compile({ a: /foo/ui, b: /bar/i })).toThrow("If one RegExp sets the unicode flag then all must")
1280+
expect(() => compile({ a: /foo/ui, b: /bar/u })).toThrow("If one rule ignores case then all must")
1281+
expect(() => compile({ a: /foo/i, b: /bar/ui })).toThrow("If one RegExp sets the unicode flag then all must")
1282+
expect(() => compile({ a: /foo/u, b: /bar/ui })).toThrow("If one rule ignores case then all must")
1283+
})
1284+
1285+
test("supports unicode", () => {
1286+
const lexer = compile({
1287+
a: /[𝌆]/u,
1288+
})
1289+
lexer.reset("𝌆")
1290+
expect(lexer.next()).toMatchObject({value: "𝌆"})
1291+
lexer.reset("𝌆".charCodeAt(0))
1292+
expect(() => lexer.next()).toThrow()
1293+
1294+
const lexer2 = compile({
1295+
a: /\u{1D356}/u,
1296+
})
1297+
lexer2.reset("𝍖")
1298+
expect(lexer2.next()).toMatchObject({value: "𝍖"})
1299+
lexer2.reset("\\u{1D356}")
1300+
expect(() => lexer2.next()).toThrow()
1301+
})
1302+
1303+
})

0 commit comments

Comments
 (0)