Skip to content

Commit dc78d33

Browse files
committed
Add test
1 parent bb71dcd commit dc78d33

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/harness/fourslash.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ namespace FourSlash {
21082108
* Because codefixes are only applied on the working file, it is unsafe
21092109
* to apply this more than once (consider a refactoring across files).
21102110
*/
2111-
public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number) {
2111+
public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean) {
21122112
const ranges = this.getRanges();
21132113
if (ranges.length !== 1) {
21142114
this.raiseError("Exactly one range should be specified in the testfile.");
@@ -2120,7 +2120,11 @@ namespace FourSlash {
21202120

21212121
const actualText = this.rangeText(ranges[0]);
21222122

2123-
if (this.removeWhitespace(actualText) !== this.removeWhitespace(expectedText)) {
2123+
const result = includeWhiteSpace
2124+
? actualText === expectedText
2125+
: this.removeWhitespace(actualText) === this.removeWhitespace(expectedText)
2126+
2127+
if (!result) {
21242128
this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`);
21252129
}
21262130
}
@@ -3509,8 +3513,8 @@ namespace FourSlashInterface {
35093513
this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true);
35103514
}
35113515

3512-
public rangeAfterCodeFix(expectedText: string, errorCode?: number): void {
3513-
this.state.verifyRangeAfterCodeFix(expectedText, errorCode);
3516+
public rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void {
3517+
this.state.verifyRangeAfterCodeFix(expectedText, errorCode, includeWhiteSpace);
35143518
}
35153519

35163520
public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void {

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ declare namespace FourSlashInterface {
225225
noMatchingBracePositionInCurrentFile(bracePosition: number): void;
226226
DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void;
227227
noDocCommentTemplate(): void;
228-
rangeAfterCodeFix(expectedText: string, errorCode?: number): void;
228+
rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void;
229229
importFixAtPosition(expectedTextArray: string[], errorCode?: number): void;
230230

231231
navigationBar(json: any): void;

tests/cases/fourslash/unusedImports2FS.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// @noUnusedLocals: true
44
// @Filename: file2.ts
5-
//// [|import {Calculator} from "./file1"
6-
//// import {test} from "./file1"|]
5+
//// [|import {test} from "./file1"
6+
//// import {Calculator} from "./file1"|]
77

88
//// var x = new Calculator();
99
//// x.handleChar();
@@ -16,4 +16,4 @@
1616
////
1717
//// }
1818

19-
verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`);
19+
verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`, /*errorCode*/ undefined, /*includeWhiteSpace*/ true);

0 commit comments

Comments
 (0)