Skip to content

Commit

Permalink
test(linter): import test cases for no-empty-character-class
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Sep 22, 2024
1 parent d75ddbd commit 8789eb1
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_empty_character_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ fn test() {
("var foo = /[\\]]/s;", None),
("var foo = /[\\]]/d;", None),
("var foo = /\\[]/", None),
// ES2024
("var foo = /[[^]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[\\]]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[\\[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a--b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a&&b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[a][b]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[\\q{}]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[^]--\\p{ASCII}]/v;", None), // { "ecmaVersion": 2024 }
];

let fail = vec![
Expand All @@ -143,6 +152,16 @@ fn test() {
("var foo = /[]]/d;", None),
("var foo = /[[][]]/v;", None),
("var foo = /[[]]|[]/v;", None),
("var foo = /[(]\\u{0}*[]/u;", None), // { "ecmaVersion": 2015 }
// ES2024
("var foo = /[]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[a][]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a[[b[]c]]d]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a--[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]--b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a&&[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]&&b]/v;", None), // { "ecmaVersion": 2024 }
];

Tester::new(NoEmptyCharacterClass::NAME, pass, fail).test_and_snapshot();
Expand Down
63 changes: 63 additions & 0 deletions crates/oxc_linter/src/snapshots/no_empty_character_class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,66 @@ source: crates/oxc_linter/src/tester.rs
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:21]
1 │ var foo = /[(]\u{0}*[]/u;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:12]
1 │ var foo = /[]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[[a][]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:17]
1 │ var foo = /[a[[b[]c]]d]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[a--[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]--b]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[a&&[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]&&b]/v;
· ──
╰────
help: Remove the empty character class: `[]`

0 comments on commit 8789eb1

Please sign in to comment.