|
| 1 | +package no_sparse_arrays |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/fixtures" |
| 7 | + "github.com/web-infra-dev/rslint/internal/rule_tester" |
| 8 | +) |
| 9 | + |
| 10 | +func TestNoSparseArraysRule(t *testing.T) { |
| 11 | + rule_tester.RunRuleTester( |
| 12 | + fixtures.GetRootDir(), |
| 13 | + "tsconfig.json", |
| 14 | + t, |
| 15 | + &NoSparseArraysRule, |
| 16 | + // Valid cases - ported from ESLint |
| 17 | + []rule_tester.ValidTestCase{ |
| 18 | + {Code: `var a = [ 1, 2, ]`}, |
| 19 | + }, |
| 20 | + // Invalid cases - ported from ESLint |
| 21 | + []rule_tester.InvalidTestCase{ |
| 22 | + { |
| 23 | + Code: `var a = [,];`, |
| 24 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 25 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 9}, |
| 26 | + }, |
| 27 | + }, |
| 28 | + { |
| 29 | + Code: `var a = [ 1,, 2];`, |
| 30 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 31 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 9}, |
| 32 | + }, |
| 33 | + }, |
| 34 | + // This test case is commented out because it produces a TypeScript compilation error: |
| 35 | + // error creating TS program for /tsconfig.json: found 5 syntactic errors. [Invalid character. [\r\n\t/* comment */,\n// comment\n ,]; Invalid character. [\r\n\t/* comment */,\n// comment\n ,]; Invalid character. [\r\n\t/* comment */,\n// comment\n ,]; Invalid character. [\r\n\t/* comment */,\n// comment\n ,]; ']' expected. [\r\n\t/* comment */,\n// comment\n ,];] |
| 36 | + //{ |
| 37 | + // Code: `[\r\n\t/* comment */,\n// comment\n ,];`, |
| 38 | + // Errors: []rule_tester.InvalidTestCaseError{ |
| 39 | + // {MessageId: "unexpectedSparseArray", Line: 1, Column: 9}, |
| 40 | + // }, |
| 41 | + //}, |
| 42 | + { |
| 43 | + Code: `[(( [a,] )),,,];`, |
| 44 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 45 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 1}, |
| 46 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 1}, |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + Code: `[,(( [a,] )),,];`, |
| 51 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 52 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 1}, |
| 53 | + {MessageId: "unexpectedSparseArray", Line: 1, Column: 1}, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + ) |
| 58 | +} |
0 commit comments