From dc78d3314f15ab5ac23007488d19ba2b011791e3 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Wed, 8 Feb 2017 15:44:54 -0800 Subject: [PATCH] Add test --- src/harness/fourslash.ts | 12 ++++++++---- tests/cases/fourslash/fourslash.ts | 2 +- tests/cases/fourslash/unusedImports2FS.ts | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c7f455bd753..ad81ace4d53 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2108,7 +2108,7 @@ namespace FourSlash { * Because codefixes are only applied on the working file, it is unsafe * to apply this more than once (consider a refactoring across files). */ - public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number) { + public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean) { const ranges = this.getRanges(); if (ranges.length !== 1) { this.raiseError("Exactly one range should be specified in the testfile."); @@ -2120,7 +2120,11 @@ namespace FourSlash { const actualText = this.rangeText(ranges[0]); - if (this.removeWhitespace(actualText) !== this.removeWhitespace(expectedText)) { + const result = includeWhiteSpace + ? actualText === expectedText + : this.removeWhitespace(actualText) === this.removeWhitespace(expectedText) + + if (!result) { this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`); } } @@ -3509,8 +3513,8 @@ namespace FourSlashInterface { this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true); } - public rangeAfterCodeFix(expectedText: string, errorCode?: number): void { - this.state.verifyRangeAfterCodeFix(expectedText, errorCode); + public rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void { + this.state.verifyRangeAfterCodeFix(expectedText, errorCode, includeWhiteSpace); } public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index c613204f539..661d7cba6a4 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -225,7 +225,7 @@ declare namespace FourSlashInterface { noMatchingBracePositionInCurrentFile(bracePosition: number): void; DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void; noDocCommentTemplate(): void; - rangeAfterCodeFix(expectedText: string, errorCode?: number): void; + rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void; importFixAtPosition(expectedTextArray: string[], errorCode?: number): void; navigationBar(json: any): void; diff --git a/tests/cases/fourslash/unusedImports2FS.ts b/tests/cases/fourslash/unusedImports2FS.ts index d2062fc4958..53875693362 100644 --- a/tests/cases/fourslash/unusedImports2FS.ts +++ b/tests/cases/fourslash/unusedImports2FS.ts @@ -2,8 +2,8 @@ // @noUnusedLocals: true // @Filename: file2.ts -//// [|import {Calculator} from "./file1" -//// import {test} from "./file1"|] +//// [|import {test} from "./file1" +//// import {Calculator} from "./file1"|] //// var x = new Calculator(); //// x.handleChar(); @@ -16,4 +16,4 @@ //// //// } -verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`); +verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`, /*errorCode*/ undefined, /*includeWhiteSpace*/ true);