|
| 1 | +package no_template_curly_in_string |
| 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 TestNoTemplateCurlyInString(t *testing.T) { |
| 11 | + rule_tester.RunRuleTester( |
| 12 | + fixtures.GetRootDir(), |
| 13 | + "tsconfig.json", |
| 14 | + t, |
| 15 | + &NoTemplateCurlyInString, |
| 16 | + // Valid cases - ported from ESLint |
| 17 | + []rule_tester.ValidTestCase{ |
| 18 | + {Code: "`Hello, ${name}`;"}, |
| 19 | + {Code: "templateFunction`Hello, ${name}`;"}, |
| 20 | + {Code: "`Hello, name`;"}, |
| 21 | + {Code: "'Hello, name';"}, |
| 22 | + {Code: "'Hello, ' + name;"}, |
| 23 | + {Code: "`Hello, ${index + 1}`"}, |
| 24 | + {Code: "`Hello, ${name + \" foo\"}`"}, |
| 25 | + {Code: "`Hello, ${name || \"foo\"}`"}, |
| 26 | + {Code: "`Hello, ${{foo: \"bar\"}.foo}`"}, |
| 27 | + {Code: "'$2'"}, |
| 28 | + {Code: "'${'"}, |
| 29 | + {Code: "'$}'"}, |
| 30 | + {Code: "'{foo}'"}, |
| 31 | + {Code: `'{foo: \"bar\"}'`}, |
| 32 | + {Code: "const number = 3"}, |
| 33 | + }, |
| 34 | + // Invalid cases - ported from ESLint |
| 35 | + []rule_tester.InvalidTestCase{ |
| 36 | + { |
| 37 | + Code: "'Hello, ${name}'", |
| 38 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 39 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 40 | + }, |
| 41 | + }, |
| 42 | + { |
| 43 | + Code: "'${greeting}, ${name}'", |
| 44 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 45 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + Code: "'Hello, ${index + 1}'", |
| 50 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 51 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + Code: "'Hello, ${name + \\\" foo\\\"}'", |
| 56 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 57 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 58 | + }, |
| 59 | + }, |
| 60 | + { |
| 61 | + Code: "'Hello, ${name || \\\"foo\\\"}'", |
| 62 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 63 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 64 | + }, |
| 65 | + }, |
| 66 | + { |
| 67 | + Code: "'Hello, ${{foo: \\\"bar\\\"}.foo}'", |
| 68 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 69 | + {MessageId: "unexpectedTemplateExpression", Line: 1, Column: 1}, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + ) |
| 74 | +} |
0 commit comments