|
5 | 5 |
|
6 | 6 | "github.com/microsoft/TypeScript/tsc/internal/fourslash" |
7 | 7 | . "github.com/microsoft/TypeScript/tsc/internal/fourslash/tests/util" |
| 8 | + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" |
8 | 9 | "github.com/microsoft/TypeScript/tsc/internal/testutil" |
9 | 10 | ) |
10 | 11 |
|
@@ -73,3 +74,155 @@ export const x = 0; |
73 | 74 | }, |
74 | 75 | }) |
75 | 76 | } |
| 77 | + |
| 78 | +func TestPathCompletionEscaping(t *testing.T) { |
| 79 | + t.Parallel() |
| 80 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 81 | + const content = `// @Filename: /src/main.ts |
| 82 | +import "./[|a/*double*/|]"; |
| 83 | +import './[|a/*single*/|]'; |
| 84 | +// @Filename: /src/a"b.ts |
| 85 | +export {}; |
| 86 | +// @Filename: /src/a'b.ts |
| 87 | +export {}; |
| 88 | +` |
| 89 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 90 | + defer done() |
| 91 | + for i, test := range []struct { |
| 92 | + marker string |
| 93 | + label string |
| 94 | + insertText string |
| 95 | + newText string |
| 96 | + }{ |
| 97 | + {"double", `a"b`, `a\"b`, `a\"b`}, |
| 98 | + {"single", `a'b`, `a\'b`, `a\'b`}, |
| 99 | + } { |
| 100 | + item := &lsproto.CompletionItem{ |
| 101 | + Label: test.label, |
| 102 | + Detail: new(test.label + ".ts"), |
| 103 | + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ |
| 104 | + TextEdit: &lsproto.TextEdit{NewText: test.newText, Range: f.Ranges()[i].LSRange}, |
| 105 | + }, |
| 106 | + } |
| 107 | + if test.insertText != "" { |
| 108 | + item.InsertText = &test.insertText |
| 109 | + } |
| 110 | + f.VerifyCompletions(t, test.marker, &fourslash.CompletionsExpectedList{ |
| 111 | + IsIncomplete: false, |
| 112 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 113 | + CommitCharacters: &[]string{}, |
| 114 | + EditRange: Ignored, |
| 115 | + }, |
| 116 | + Items: &fourslash.CompletionsExpectedItems{Includes: []fourslash.CompletionsExpectedItem{item}}, |
| 117 | + }) |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +func TestPathCompletionEscapedDirectory(t *testing.T) { |
| 122 | + t.Parallel() |
| 123 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 124 | + const content = `// @Filename: /src/main.ts |
| 125 | +import "./a\"b/c/*escaped*/"; |
| 126 | +import "./\u0061\x2fc/*escapedSeparator*/"; |
| 127 | +// @Filename: /src/a"b/cd.ts |
| 128 | +export {}; |
| 129 | +// @Filename: /src/a/cd.ts |
| 130 | +export {}; |
| 131 | +` |
| 132 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 133 | + defer done() |
| 134 | + for _, test := range []struct { |
| 135 | + marker string |
| 136 | + // Character offset of the replaced text; the "c" is at 15 and 20 respectively. |
| 137 | + character uint32 |
| 138 | + }{ |
| 139 | + {"escaped", 15}, |
| 140 | + {"escapedSeparator", 20}, |
| 141 | + } { |
| 142 | + line := f.MarkerByName(t, test.marker).LSPos().Line |
| 143 | + f.VerifyCompletions(t, test.marker, &fourslash.CompletionsExpectedList{ |
| 144 | + IsIncomplete: false, |
| 145 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 146 | + CommitCharacters: &[]string{}, |
| 147 | + EditRange: Ignored, |
| 148 | + }, |
| 149 | + Items: &fourslash.CompletionsExpectedItems{ |
| 150 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 151 | + &lsproto.CompletionItem{ |
| 152 | + Label: "cd", |
| 153 | + Detail: new("cd.ts"), |
| 154 | + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ |
| 155 | + TextEdit: &lsproto.TextEdit{ |
| 156 | + NewText: "cd", |
| 157 | + Range: lsproto.Range{ |
| 158 | + Start: lsproto.Position{Line: line, Character: test.character}, |
| 159 | + End: lsproto.Position{Line: line, Character: test.character + 1}, |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | + }, |
| 164 | + }, |
| 165 | + }, |
| 166 | + }) |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | +func TestTripleSlashReferenceCompletionQuotes(t *testing.T) { |
| 171 | + t.Parallel() |
| 172 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 173 | + const content = `// @Filename: /src/main.ts |
| 174 | +/// <reference path="./a/*reference*/" /> |
| 175 | +// @Filename: /src/a"b.ts |
| 176 | +export {}; |
| 177 | +// @Filename: /src/a'b.ts |
| 178 | +export {}; |
| 179 | +` |
| 180 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 181 | + defer done() |
| 182 | + f.VerifyCompletions(t, "reference", &fourslash.CompletionsExpectedList{ |
| 183 | + IsIncomplete: false, |
| 184 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 185 | + CommitCharacters: &[]string{}, |
| 186 | + EditRange: Ignored, |
| 187 | + }, |
| 188 | + Items: &fourslash.CompletionsExpectedItems{ |
| 189 | + Includes: []fourslash.CompletionsExpectedItem{"a'b.ts"}, |
| 190 | + Excludes: []string{`a"b.ts`}, |
| 191 | + }, |
| 192 | + }) |
| 193 | +} |
| 194 | + |
| 195 | +func TestPathCompletionEscapedTemplate(t *testing.T) { |
| 196 | + t.Parallel() |
| 197 | + defer testutil.RecoverAndFail(t, "Panic on fourslash test") |
| 198 | + const content = "// @Filename: /src/main.ts\n" + |
| 199 | + "import(`./\\x61/c/*template*/`);\n" + |
| 200 | + "// @Filename: /src/a/cd.ts\n" + |
| 201 | + "export {};\n" |
| 202 | + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) |
| 203 | + defer done() |
| 204 | + f.VerifyCompletions(t, "template", &fourslash.CompletionsExpectedList{ |
| 205 | + IsIncomplete: false, |
| 206 | + ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ |
| 207 | + CommitCharacters: &[]string{}, |
| 208 | + EditRange: Ignored, |
| 209 | + }, |
| 210 | + Items: &fourslash.CompletionsExpectedItems{ |
| 211 | + Includes: []fourslash.CompletionsExpectedItem{ |
| 212 | + &lsproto.CompletionItem{ |
| 213 | + Label: "cd", |
| 214 | + Detail: new("cd.ts"), |
| 215 | + TextEdit: &lsproto.TextEditOrInsertReplaceEdit{ |
| 216 | + TextEdit: &lsproto.TextEdit{ |
| 217 | + NewText: "cd", |
| 218 | + Range: lsproto.Range{ |
| 219 | + Start: lsproto.Position{Line: 0, Character: 15}, |
| 220 | + End: lsproto.Position{Line: 0, Character: 16}, |
| 221 | + }, |
| 222 | + }, |
| 223 | + }, |
| 224 | + }, |
| 225 | + }, |
| 226 | + }, |
| 227 | + }) |
| 228 | +} |
0 commit comments