Rename and simplify fourslash interface

This commit is contained in:
Arthur Ozga
2016-11-02 12:39:55 -07:00
parent 1b60a97bed
commit e5279fd828
37 changed files with 67 additions and 80 deletions
+26 -24
View File
@@ -92,11 +92,14 @@ namespace FourSlash {
end: number;
}
export interface ErrorIdentifier {
export interface CodeFixIdentifier {
/**
* Error code to search over for codefix.
*/
code: number;
/**
* In a file where there is more than one error with code `code`, `count` refers
* to which 0-indexed error, sorted by order of occurence, to consider.
* to which 0-indexed codefix, sorted by order of occurence, to consider.
*/
count: number;
}
@@ -2022,14 +2025,14 @@ 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 verifyCodeFixAtPosition(expectedText: string, errorCode?: number) {
public verifyRangeAfterCodeFix(expectedText: string, codeFixIdentifier?: CodeFixIdentifier) {
const ranges = this.getRanges();
if (ranges.length !== 1) {
this.raiseError("Exactly one range should be specified in the testfile.");
}
const fileName = this.activeFile.fileName;
const codeFix: ts.CodeAction = this.getCodeFix(fileName, errorCode ? { code: errorCode, count: 0 } : undefined);
const codeFix: ts.CodeAction = this.getCodeFix(fileName, codeFixIdentifier);
if (!codeFix) {
this.raiseError("Should find exactly one codefix.");
@@ -2052,6 +2055,8 @@ namespace FourSlash {
* Applies fixes for the errors in fileName and compares the results to
* expectedContents after all fixes have been applied.
*
* It is safe to apply this multiple times in a single test.
*
* Note: applying one codefix may generate another (eg: remove duplicate implements
* may generate an extends -> interface conversion fix).
* @param expectedContents The contents of the file after the fixes are applied.
@@ -2059,30 +2064,27 @@ namespace FourSlash {
* @param errorsToFix An array of errors for which quickfixes will be applied. If not
* supplied, all codefixes in the file are applied until none are left, starting from
* the first available codefix.
*
*
*/
public verifyFileAfterCodeFix(expectedContents: string, fileName?: string, errorsToFix?: ErrorIdentifier[]) {
public verifyFileAfterCodeFix(expectedContents: string, fileName?: string, codeFixIdentifier?: CodeFixIdentifier) {
fileName = fileName ? fileName : this.activeFile.fileName;
if (errorsToFix) {
for (const error of errorsToFix) {
const fix = this.getCodeFix(fileName, error);
if (fix === undefined) {
this.raiseError(`Couldn't find the ${error.count}'th error with code ${error.code}.`);
}
this.applyCodeAction(fix);
const codeFix = this.getCodeFix(fileName, codeFixIdentifier);
if (codeFix === undefined) {
if (codeFixIdentifier) {
this.raiseError(`Couldn't find the ${codeFixIdentifier.count}'th error with code ${codeFixIdentifier.code}.`);
}
}
else {
let fix: ts.CodeAction;
while (fix = this.getCodeFix(fileName)) {
this.applyCodeAction(fix);
else {
this.raiseError("No code fix could be found.");
}
}
this.applyCodeAction(codeFix);
const actualContents: string = this.getFileContent(fileName);
if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) {
this.raiseError(`Actual text doesn't match expected text. Actual:\n${actualContents}\n\nExpected:\n${expectedContents}`);
this.raiseError(`Actual text doesn't match expected text. Actual:\n${actualContents}\n\nExpected:\n\n${expectedContents}`);
}
}
@@ -2093,7 +2095,7 @@ namespace FourSlash {
*
* If undefined, we get the first codefix available.
*/
private getCodeFix(fileName: string, error?: ErrorIdentifier): ts.CodeAction | undefined {
private getCodeFix(fileName: string, error?: CodeFixIdentifier): ts.CodeAction | undefined {
const diagnostics: ts.Diagnostic[] = this.getDiagnostics(fileName);
const errorCount = error ? error.count : 0;
@@ -3364,12 +3366,12 @@ namespace FourSlashInterface {
this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true);
}
public codeFixAtPosition(expectedText: string, errorCode?: number): void {
this.state.verifyCodeFixAtPosition(expectedText, errorCode);
public rangeAfterCodeFix(expectedText: string, codeFixidentifier?: FourSlash.CodeFixIdentifier): void {
this.state.verifyRangeAfterCodeFix(expectedText, codeFixidentifier);
}
public fileAfterCodeFixes(expectedContents: string, fileName?: string, errorsToFix?: FourSlash.ErrorIdentifier[]): void {
this.state.verifyFileAfterCodeFix(expectedContents, fileName, errorsToFix);
public fileAfterCodeFix(expectedContents: string, fileName?: string, codeFixidentifier?: FourSlash.CodeFixIdentifier): void {
this.state.verifyFileAfterCodeFix(expectedContents, fileName, codeFixidentifier);
}
public navigationBar(json: any) {
+1 -1
View File
@@ -7,4 +7,4 @@
//// }
////}
verify.codeFixAtPosition('super();');
verify.rangeAfterCodeFix('super();');
@@ -3,4 +3,4 @@
//// interface I1 {}
//// [|class c1 extends I1|]{}
verify.codeFixAtPosition("class c1 implements I1");
verify.rangeAfterCodeFix("class c1 implements I1");
@@ -3,4 +3,4 @@
////interface I1 {}
////[|class c1<T extends string , U> extends I1|]{}
verify.codeFixAtPosition("class c1<T extends string , U> implements I1");
verify.rangeAfterCodeFix("class c1<T extends string , U> implements I1");
@@ -7,7 +7,7 @@
//// class C extends A {[|
//// |]}
verify.codeFixAtPosition(`f(){
verify.rangeAfterCodeFix(`f(){
throw new Error('Method not Implemented');
}
`);
@@ -7,6 +7,6 @@
//// class C extends A {[|
//// |]}
verify.codeFixAtPosition(`
verify.rangeAfterCodeFix(`
abstract x: number;
`);
@@ -7,6 +7,6 @@
//// class C extends A {[|
//// |]}
verify.codeFixAtPosition(`
verify.rangeAfterCodeFix(`
protected abstract x: number;
`);
@@ -7,6 +7,6 @@
//// class C extends A {[|
//// |]}
verify.codeFixAtPosition(`
verify.rangeAfterCodeFix(`
public abstract x: number;
`);
@@ -1,14 +1,9 @@
/// <reference path='fourslash.ts' />
//// interface I1 { }
//// class C1 extends I1 { }
//// interface I2 { }
//// class C2 extends I2 { }
//// interface I { }
//// class C extends I { }
// verify.codeFixAvailable();
verify.fileAfterCodeFixes(`
interface I1 { }
class C1 implements I1 { }
interface I2 { }
class C2 implements I2 { }
verify.fileAfterCodeFix(`
interface I { }
class C implements I { }
`);
+1 -1
View File
@@ -10,4 +10,4 @@
//// }
////}
verify.codeFixAtPosition("super(); this.a = 12;");
verify.rangeAfterCodeFix("super(); this.a = 12;");
@@ -14,7 +14,7 @@
////
//// |]}
verify.codeFixAtPosition(`f1<T extends number>(){
verify.rangeAfterCodeFix(`f1<T extends number>(){
throw new Error('Method not Implemented');
}
`);
@@ -14,7 +14,7 @@
////
//// |]}
verify.codeFixAtPosition(`f1<T extends number>(){
verify.rangeAfterCodeFix(`f1<T extends number>(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`f1():string{
verify.rangeAfterCodeFix(`f1():string{
throw new Error('Method not Implemented');
}
`);
@@ -8,7 +8,7 @@
////
//// |]}
verify.codeFixAtPosition(`f1<T extends number>(){
verify.rangeAfterCodeFix(`f1<T extends number>(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// |]f2(){}
//// }
verify.codeFixAtPosition(`f1<T extends number>(){
verify.rangeAfterCodeFix(`f1<T extends number>(){
throw new Error('Method not Implemented');
}
`);
@@ -10,7 +10,7 @@
////
//// |]}
verify.codeFixAtPosition(`f1<T extends number>(){
verify.rangeAfterCodeFix(`f1<T extends number>(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// |]f2(){}
//// }
verify.codeFixAtPosition(`f1<T>(){
verify.rangeAfterCodeFix(`f1<T>(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// |]f2(){}
//// }
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -11,7 +11,7 @@
//// class C1 implements I2 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -8,7 +8,7 @@
//// |]f2(){}
//// }
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// |]f2(){}
//// }
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -11,7 +11,7 @@
//// class C1 implements I2 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -13,7 +13,7 @@
//// class C1 implements I3 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -13,7 +13,7 @@
//// class C1 implements I3 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -13,7 +13,7 @@
//// class C1 implements I3 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -9,7 +9,7 @@
//// class C1 implements I1 {[|
//// |]}
verify.codeFixAtPosition(`f1<T extends string>(x: number,y: C2){
verify.rangeAfterCodeFix(`f1<T extends string>(x: number,y: C2){
throw new Error('Method not Implemented');
}
`);
@@ -9,7 +9,7 @@
//// class C1 implements I1 {[|
//// |]}
verify.codeFixAtPosition(`f1<T>(x: number,y: C2){
verify.rangeAfterCodeFix(`f1<T>(x: number,y: C2){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
`);
@@ -12,7 +12,7 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`f1(x: number,y: string){
verify.rangeAfterCodeFix(`f1(x: number,y: string){
throw new Error('Method not Implemented');
}
`);
@@ -9,7 +9,7 @@
//// class C1 implements I1 {[|
//// |]}
verify.codeFixAtPosition(`f1(x: number,y: T){
verify.rangeAfterCodeFix(`f1(x: number,y: T){
throw new Error('Method not Implemented');
}
`);
@@ -12,5 +12,5 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`x: number;
verify.rangeAfterCodeFix(`x: number;
`);
@@ -12,5 +12,5 @@
//// class C1 implements N1.I1 {[|
//// |]}
verify.codeFixAtPosition(`x: number;
verify.rangeAfterCodeFix(`x: number;
`);
@@ -13,7 +13,7 @@
//// class C3 implements I1 {[|
//// |]}
verify.codeFixAtPosition(`f1(){
verify.rangeAfterCodeFix(`f1(){
throw new Error('Method not Implemented');
}
f2(){
@@ -52,7 +52,7 @@
*/
verify.codeFixAtPosition(
verify.rangeAfterCodeFix(
`
e: number;
f: number;
+3 -3
View File
@@ -98,7 +98,7 @@ declare namespace FourSlashInterface {
start: number;
end: number;
}
interface ErrorIdentifier {
interface CodeFixIdentifier {
code: number;
count: number
}
@@ -213,8 +213,8 @@ declare namespace FourSlashInterface {
noMatchingBracePositionInCurrentFile(bracePosition: number): void;
DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void;
noDocCommentTemplate(): void;
codeFixAtPosition(expectedText: string, errorCode?: number): void;
fileAfterCodeFixes(expectedContents: string, fileName?: string, errorsToFix?: ErrorIdentifier[]): void;
rangeAfterCodeFix(expectedText: string, CodeFixIdentifier?: CodeFixIdentifier): void;
fileAfterCodeFix(expectedContents: string, fileName?: string, CodeFixIdentifier?: CodeFixIdentifier): void;
navigationBar(json: any): void;
navigationTree(json: any): void;
@@ -1,10 +0,0 @@
/// <reference path='fourslash.ts' />
////class Base{
////}
////class C extends Base{
//// constructor() {[| |]
//// }
////}
verify.codeFixAtPosition('super();');