Skip to content

Commit 184831f

Browse files
authored
Add test cases fro v flag (#641)
1 parent ae1897a commit 184831f

9 files changed

+130
-11
lines changed

tests/lib/rules/confusing-quantifier.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/confusing-quantifier"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -15,6 +15,7 @@ tester.run("confusing-quantifier", rule as any, {
1515
String.raw`/(a|b?)*/`,
1616
String.raw`/(a?){0,3}/`,
1717
String.raw`/(a|\b)+/`,
18+
String.raw`/[\q{a|b}]+/v`,
1819
],
1920
invalid: [
2021
{
@@ -39,5 +40,16 @@ tester.run("confusing-quantifier", rule as any, {
3940
},
4041
],
4142
},
43+
{
44+
code: String.raw`/[\q{a|}]+/v`,
45+
errors: [
46+
{
47+
message:
48+
"This quantifier is confusing because its minimum is 1 but it can match the empty string. Maybe replace it with `*` to reflect that it can match the empty string?",
49+
line: 1,
50+
column: 10,
51+
},
52+
],
53+
},
4254
],
4355
})

tests/lib/rules/control-character-escape.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/control-character-escape"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -16,6 +16,7 @@ tester.run("control-character-escape", rule as any, {
1616
String.raw`RegExp("\\0\\t\\n\\v\\f\\r", "i")`,
1717
"/\\t/",
1818
"new RegExp('\t')",
19+
String.raw`/[\q{\0\t\n\v\f\r}]/v`,
1920
],
2021
invalid: [
2122
{
@@ -115,5 +116,12 @@ tester.run("control-character-escape", rule as any, {
115116
"Unexpected control character escape '\t' (U+0009). Use '\\t' instead.",
116117
],
117118
},
119+
{
120+
code: String.raw`/[\q{\x00}]/v`,
121+
output: String.raw`/[\q{\0}]/v`,
122+
errors: [
123+
"Unexpected control character escape '\\x00' (U+0000). Use '\\0' instead.",
124+
],
125+
},
118126
],
119127
})

tests/lib/rules/hexadecimal-escape.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/hexadecimal-escape"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -29,6 +29,14 @@ tester.run("hexadecimal-escape", rule as any, {
2929
options: ["never"],
3030
},
3131
String.raw`/\cA \cB \cM/`,
32+
{
33+
code: String.raw`/[\q{\x0a}]/v`,
34+
options: ["always"],
35+
},
36+
{
37+
code: String.raw`/[\q{\u000a}]/v`,
38+
options: ["never"],
39+
},
3240
],
3341
invalid: [
3442
{
@@ -98,5 +106,23 @@ tester.run("hexadecimal-escape", rule as any, {
98106
},
99107
],
100108
},
109+
{
110+
code: String.raw`/[\q{\u000a \u{00000a}}]/v`,
111+
output: String.raw`/[\q{\x0a \x0a}]/v`,
112+
options: ["always"],
113+
errors: [
114+
"Expected hexadecimal escape ('\\x0a'), but unicode escape ('\\u000a') is used.",
115+
"Expected hexadecimal escape ('\\x0a'), but unicode code point escape ('\\u{00000a}') is used.",
116+
],
117+
},
118+
{
119+
code: String.raw`/[\q{\x0f \xff}]/v`,
120+
output: String.raw`/[\q{\u000f \u00ff}]/v`,
121+
options: ["never"],
122+
errors: [
123+
"Unexpected hexadecimal escape ('\\x0f').",
124+
"Unexpected hexadecimal escape ('\\xff').",
125+
],
126+
},
101127
],
102128
})

tests/lib/rules/letter-case.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/letter-case"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -49,6 +49,19 @@ tester.run("letter-case", rule as any, {
4949
code: `/[A-z]/i`,
5050
options: [{ caseInsensitive: "ignore" }],
5151
},
52+
String.raw`/[\q{ab}]/iv`,
53+
{
54+
code: String.raw`/[\q{ab}]/iv`,
55+
options: [{ caseInsensitive: "lowercase" }],
56+
},
57+
{
58+
code: String.raw`/[\q{AB}]/iv`,
59+
options: [{ caseInsensitive: "uppercase" }],
60+
},
61+
{
62+
code: String.raw`/[\q{Ab}]/iv`,
63+
options: [{ caseInsensitive: "ignore" }],
64+
},
5265
String.raw`/\u000a/`,
5366
{
5467
code: String.raw`/\u000a/`,
@@ -266,5 +279,22 @@ tester.run("letter-case", rule as any, {
266279
options: [{ unicodeEscape: "lowercase" }],
267280
errors: [String.raw`'\u000A' is not in lowercase`],
268281
},
282+
{
283+
code: String.raw`/[\q{Ab}]/iv`,
284+
output: String.raw`/[\q{ab}]/iv`,
285+
errors: ["'A' is not in lowercase"],
286+
},
287+
{
288+
code: String.raw`/[\q{Ab}]/iv`,
289+
output: String.raw`/[\q{ab}]/iv`,
290+
options: [{ caseInsensitive: "lowercase" }],
291+
errors: ["'A' is not in lowercase"],
292+
},
293+
{
294+
code: String.raw`/[\q{Ab}]/iv`,
295+
output: String.raw`/[\q{AB}]/iv`,
296+
options: [{ caseInsensitive: "uppercase" }],
297+
errors: ["'b' is not in uppercase"],
298+
},
269299
],
270300
})

tests/lib/rules/no-control-character.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/no-control-character"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -102,5 +102,9 @@ tester.run("no-control-character", rule as any, {
102102
},
103103
],
104104
},
105+
{
106+
code: String.raw`/[\q{\x1f}]/v`,
107+
errors: [{ messageId: "unexpected", suggestions: [] }],
108+
},
105109
],
106110
})

tests/lib/rules/no-empty-group.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import rule from "../../../lib/rules/no-empty-group"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
1010

1111
tester.run("no-empty-group", rule as any, {
12-
valid: ["/(a)/", "/(a|)/", "/(?:a|)/"],
12+
valid: ["/(a)/", "/(a|)/", "/(?:a|)/", String.raw`/(?:a|[\q{}])/v`],
1313
invalid: [
1414
{
1515
code: "/()/",

tests/lib/rules/no-empty-lookarounds-assertion.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/no-empty-lookarounds-assertion"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -20,6 +20,7 @@ tester.run("no-empty-lookarounds-assertion", rule as any, {
2020
"/(?=$|a)/",
2121
"/(?=\\ba*\\b)/",
2222
'/b?r(#*)"(?:[^"]|"(?!\\1))*"\\1/',
23+
String.raw`/x(?=[\q{a}])/v`,
2324
],
2425
invalid: [
2526
{
@@ -174,5 +175,14 @@ tester.run("no-empty-lookarounds-assertion", rule as any, {
174175
},
175176
],
176177
},
178+
{
179+
code: String.raw`/x(?=[\q{}])/v`,
180+
errors: [
181+
{
182+
message:
183+
"Unexpected empty lookahead. It will trivially accept all inputs.",
184+
},
185+
],
186+
},
177187
],
178188
})

tests/lib/rules/no-escape-backspace.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import rule from "../../../lib/rules/no-escape-backspace"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
1010

1111
tester.run("no-escape-backspace", rule as any, {
12-
valid: ["/\\b/", "/\\u0008/", "/\\ch/", "/\\cH/"],
12+
valid: [
13+
"/\\b/",
14+
"/\\u0008/",
15+
"/\\ch/",
16+
"/\\cH/",
17+
String.raw`/[\q{\u0008}]/v`,
18+
],
1319
invalid: [
1420
{
1521
code: "/[\\b]/",
@@ -22,5 +28,16 @@ tester.run("no-escape-backspace", rule as any, {
2228
},
2329
],
2430
},
31+
{
32+
code: String.raw`/[\q{\b}]/v`,
33+
errors: [
34+
{
35+
message: "Unexpected '[\\b]'. Use '\\u0008' instead.",
36+
column: 6,
37+
endColumn: 8,
38+
suggestions: [{ output: String.raw`/[\q{\u0008}]/v` }],
39+
},
40+
],
41+
},
2542
],
2643
})

tests/lib/rules/no-extra-lookaround-assertions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/no-extra-lookaround-assertions"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -12,6 +12,7 @@ tester.run("no-extra-lookaround-assertions", rule as any, {
1212
valid: [
1313
`console.log('JavaScript'.replace(/Java(?=Script)/u, 'Type'))`,
1414
`console.log('JavaScript'.replace(/(?<=Java)Script/u, ''))`,
15+
String.raw`console.log('JavaScript'.replace(/(?<=[\q{Java}])Script/v, ''))`,
1516
],
1617
invalid: [
1718
{
@@ -125,5 +126,16 @@ tester.run("no-extra-lookaround-assertions", rule as any, {
125126
},
126127
],
127128
},
129+
{
130+
code: String.raw`console.log('JavaScript'.replace(/Java(?=Scrip(?=[\q{t}]))/v, 'Type'))`,
131+
output: String.raw`console.log('JavaScript'.replace(/Java(?=Scrip[\q{t}])/v, 'Type'))`,
132+
errors: [
133+
{
134+
message:
135+
"This lookahead assertion is useless and can be inlined.",
136+
column: 47,
137+
},
138+
],
139+
},
128140
],
129141
})

0 commit comments

Comments
 (0)