From caa66f64133a5b72b51c47c74e9531d2948a67e7 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 11 Jun 2019 17:50:36 -0700 Subject: [PATCH] Add regression test --- src/harness/fourslash.ts | 18 ++++++++++++++++++ tests/cases/fourslash/fourslash.ts | 1 + .../fourslash/outliningHintSpansForFunction.ts | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/cases/fourslash/outliningHintSpansForFunction.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index bdcb3e082d2ed..345709ca550df 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2238,6 +2238,20 @@ Actual: ${stringify(fullActual)}`); }); } + public verifyOutliningHintSpans(spans: Range[]) { + const actual = this.languageService.getOutliningSpans(this.activeFile.fileName); + + if (actual.length !== spans.length) { + this.raiseError(`verifyOutliningHintSpans failed - expected total spans to be ${spans.length}, but was ${actual.length}`); + } + + ts.zipWith(spans, actual, (expectedSpan, actualSpan, i) => { + if (expectedSpan.pos !== actualSpan.hintSpan.start || expectedSpan.end !== ts.textSpanEnd(actualSpan.hintSpan)) { + return this.raiseError(`verifyOutliningSpans failed - span ${(i + 1)} expected: (${expectedSpan.pos},${expectedSpan.end}), actual: (${actualSpan.hintSpan.start},${ts.textSpanEnd(actualSpan.hintSpan)})`); + } + }); + } + public verifyTodoComments(descriptors: string[], spans: Range[]) { const actual = this.languageService.getTodoComments(this.activeFile.fileName, descriptors.map(d => { return { text: d, priority: 0 }; })); @@ -4005,6 +4019,10 @@ namespace FourSlashInterface { this.state.verifyOutliningSpans(spans, kind); } + public outliningHintSpansInCurrentFile(spans: FourSlash.Range[]) { + this.state.verifyOutliningHintSpans(spans); + } + public todoCommentsInCurrentFile(descriptors: string[]) { this.state.verifyTodoComments(descriptors, this.state.getRanges()); } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index b3253bcd59fff..b471817b4044f 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -247,6 +247,7 @@ declare namespace FourSlashInterface { baselineSmartSelection(): void; nameOrDottedNameSpanTextIs(text: string): void; outliningSpansInCurrentFile(spans: Range[]): void; + outliningHintSpansInCurrentFile(spans: Range[]): void; todoCommentsInCurrentFile(descriptors: string[]): void; matchingBracePositionInCurrentFile(bracePosition: number, expectedMatchPosition: number): void; noMatchingBracePositionInCurrentFile(bracePosition: number): void; diff --git a/tests/cases/fourslash/outliningHintSpansForFunction.ts b/tests/cases/fourslash/outliningHintSpansForFunction.ts new file mode 100644 index 0000000000000..49f94ae80758c --- /dev/null +++ b/tests/cases/fourslash/outliningHintSpansForFunction.ts @@ -0,0 +1,16 @@ +/// + +////[|namespace NS { +//// [|function f(x: number, y: number) { +//// return x + y; +//// }|] +//// +//// [|function g( +//// x: number, +//// y: number, +//// ): number { +//// return x + y; +//// }|] +////}|] + +verify.outliningHintSpansInCurrentFile(test.ranges());