-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprefer-question-quantifier.ts
55 lines (53 loc) · 1.19 KB
/
prefer-question-quantifier.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { SnapshotRuleTester } from "eslint-snapshot-rule-tester"
import rule from "../../../lib/rules/prefer-question-quantifier"
const tester = new SnapshotRuleTester({
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
})
tester.run("prefer-question-quantifier", rule as any, {
valid: [
"/a?/",
"/a??/",
"/(a?)/",
"/(a??)/",
"/[a{0,1}]/",
"/a{0,}/",
"/(?:a|b)/",
"/a(?:|a)/",
"/(?:abc||def)/",
"/(?:)/",
"/(?:||)/",
"/(?:abc|def|)+/",
"/(?:abc|def|)??/",
],
invalid: [
"/a{0,1}/",
"/a{0,1}?/",
"/(a){0,1}/",
"/(a){0,1}/v",
"/(a){0,1}?/",
"/(?:abc|)/",
"/(?:abc|def|)/",
"/(?:abc||def|)/",
"/(?:abc|def||)/",
"/(?:abc|def|)?/",
`
const s = "a{0,1}"
new RegExp(s)
`,
`
const s = "a{0,"+"1}"
new RegExp(s)
`,
`
const s = "(?:abc|def|)"
new RegExp(s)
`,
`
const s = "(?:abc|"+"def|)"
new RegExp(s)
`,
],
})