Skip to content

Commit 15c0291

Browse files
author
Arthur Ozga
committed
testing
1 parent 420279b commit 15c0291

File tree

5 files changed

+68
-21
lines changed

5 files changed

+68
-21
lines changed

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,6 @@ namespace ts {
25222522
getNonNullableType(type: Type): Type;
25232523

25242524
/** Note that the resulting nodes cannot be checked. */
2525-
25262525
typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode;
25272526
/** Note that the resulting nodes cannot be checked. */
25282527
signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): SignatureDeclaration;

src/harness/fourslash.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,34 +2276,46 @@ namespace FourSlash {
22762276
}
22772277

22782278
/**
2279-
* Compares expected text to the text that would be in the sole range
2280-
* (ie: [|...|]) in the file after applying the codefix sole codefix
2281-
* in the source file.
2282-
*
2283-
* Because codefixes are only applied on the working file, it is unsafe
2284-
* to apply this more than once (consider a refactoring across files).
2279+
* Finds and applies a code action corresponding to the supplied parameters.
2280+
* If index is undefined, applies the unique code action available.
2281+
* @param errorCode The error code that generated the code action.
2282+
* @param index The nth (0-index-based) codeaction available generated by errorCode.
22852283
*/
2286-
public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) {
2284+
public getAndApplyCodeActions(errorCode?: number, index?: number) {
2285+
const fileName = this.activeFile.fileName;
2286+
this.applyCodeActions(fileName, this.getCodeFixActions(fileName, errorCode), index);
2287+
}
2288+
2289+
public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) {
22872290
const ranges = this.getRanges();
22882291
if (ranges.length !== 1) {
22892292
this.raiseError("Exactly one range should be specified in the testfile.");
22902293
}
22912294

2292-
const fileName = this.activeFile.fileName;
2293-
2294-
this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index);
2295-
2296-
const actualText = this.rangeText(ranges[0]);
2295+
const actualText = this.normalizeNewlines(this.rangeText(ranges[0]));
22972296

22982297
const result = includeWhiteSpace
2299-
? normalizeNewLines(actualText) === normalizeNewLines(expectedText)
2298+
? actualText === this.normalizeNewlines(expectedText)
23002299
: this.removeWhitespace(actualText) === this.removeWhitespace(expectedText);
23012300

23022301
if (!result) {
23032302
this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`);
23042303
}
23052304
}
23062305

2306+
/**
2307+
* Compares expected text to the text that would be in the sole range
2308+
* (ie: [|...|]) in the file after applying the codefix sole codefix
2309+
* in the source file.
2310+
*
2311+
* Because codefixes are only applied on the working file, it is unsafe
2312+
* to apply this more than once (consider a refactoring across files).
2313+
*/
2314+
public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) {
2315+
this.getAndApplyCodeActions(errorCode, index);
2316+
this.verifyRangeIs(expectedText, includeWhiteSpace);
2317+
}
2318+
23072319
/**
23082320
* Applies fixes for the errors in fileName and compares the results to
23092321
* expectedContents after all fixes have been applied.
@@ -2316,7 +2328,7 @@ namespace FourSlash {
23162328
public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) {
23172329
fileName = fileName ? fileName : this.activeFile.fileName;
23182330

2319-
this.applyCodeAction(fileName, this.getCodeFixActions(fileName));
2331+
this.applyCodeActions(fileName, this.getCodeFixActions(fileName));
23202332

23212333
const actualContents: string = this.getFileContent(fileName);
23222334
if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) {
@@ -2354,11 +2366,10 @@ namespace FourSlash {
23542366
return actions;
23552367
}
23562368

2357-
private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void {
2369+
private applyCodeActions(fileName: string, actions: ts.CodeAction[], index?: number): void {
23582370
if (index === undefined) {
23592371
if (!(actions && actions.length === 1)) {
2360-
const actionText = (actions && actions.length) ? JSON.stringify(actions) : "none";
2361-
this.raiseError(`Should find exactly one codefix, but found ${actionText}`);
2372+
this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`);
23622373
}
23632374
index = 0;
23642375
}
@@ -2758,7 +2769,7 @@ namespace FourSlash {
27582769

27592770
const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply);
27602771

2761-
this.applyCodeAction(this.activeFile.fileName, codeActions);
2772+
this.applyCodeActions(this.activeFile.fileName, codeActions);
27622773
const actualContent = this.getFileContent(this.activeFile.fileName);
27632774

27642775
if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) {
@@ -3805,6 +3816,14 @@ namespace FourSlashInterface {
38053816
this.state.verifyFileAfterApplyingRefactorAtMarker(markerName, expectedContent, refactorNameToApply, formattingOptions);
38063817
}
38073818

3819+
public rangeIs(expectedText: string, includeWhiteSpace?: boolean): void {
3820+
this.state.verifyRangeIs(expectedText, includeWhiteSpace);
3821+
}
3822+
3823+
public applyCodeFix(errorCode?: number, index?: number): void {
3824+
this.state.getAndApplyCodeActions(errorCode, index);
3825+
}
3826+
38083827
public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void {
38093828
this.state.verifyImportFixAtPosition(expectedTextArray, errorCode);
38103829
}

src/services/codefixes/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace ts.codefix {
177177
parameters,
178178
/*type*/ undefined,
179179
createStubbedMethodBody()
180-
)
180+
);
181181

182182
return newMethod;
183183
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// class A {[|
4+
//// |]constructor() {
5+
//// this.foo1(1,2,3);
6+
//// // 7 type args
7+
//// this.foo2<1,2,3,4,5,6,7>();
8+
//// // 8 type args
9+
//// this.foo3<1,2,3,4,5,6,7,8>();
10+
//// }
11+
//// }
12+
13+
verify.applyCodeFix(/*errorCode*/undefined, 0);
14+
verify.applyCodeFix(/*errorCode*/undefined, 0);
15+
verify.applyCodeFix(/*errorCode*/undefined, 0);
16+
17+
verify.rangeIs(`
18+
foo3<T0, T1, T2, T3, T4, T5, T6, T7>() {
19+
throw new Error("Method not implemented.");
20+
}
21+
foo2<T, U, V, W, X, Y, Z>() {
22+
throw new Error("Method not implemented.");
23+
}
24+
foo1(arg0: any, arg1: any, arg2: any) {
25+
throw new Error("Method not implemented.");
26+
}
27+
`);

tests/cases/fourslash/fourslash.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ declare namespace FourSlashInterface {
236236
noMatchingBracePositionInCurrentFile(bracePosition: number): void;
237237
DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void;
238238
noDocCommentTemplate(): void;
239-
rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void;
239+
rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void
240+
applyCodeFix(errorCode?: number, index?: number): void;
241+
rangeIs(expectedText: string, includeWhiteSpace?: boolean): void;
240242
fileAfterApplyingRefactorAtMarker(markerName: string, expectedContent: string, refactorNameToApply: string, formattingOptions?: FormatCodeOptions): void;
241243
importFixAtPosition(expectedTextArray: string[], errorCode?: number): void;
242244

0 commit comments

Comments
 (0)