From c125f080a43a60706cff8dec6a6b548014480d43 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 31 May 2017 17:18:36 -0700 Subject: [PATCH] add tests --- .../codeFixUndeclaredAcrossFiles1.ts | 34 ++++++++++++++ .../codeFixUndeclaredAcrossFiles2.ts | 40 +++++++++++++++++ .../codeFixUndeclaredInStaticMethod.ts | 44 +++++++++++++++++++ .../fourslash/codeFixUndeclaredMethod.ts | 6 +-- .../codeFixUndeclaredPropertyAccesses.ts | 17 +++++++ 5 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts create mode 100644 tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts new file mode 100644 index 00000000000..830259e3ca7 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -0,0 +1,34 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.js +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.ts +//// export class C {[| +//// |]x: number; +//// static y: string; +//// } + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + y: { [x: string]: any; }; + m1(): any { + throw new Error("Method not implemented."); + } + static x: any; + static m0(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts new file mode 100644 index 00000000000..cc01f8d50ee --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -0,0 +1,40 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.ts +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.js +//// [|export class C { +//// x: number; +//// static y: string; +//// constructor() { } +//// }|] + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` +export class C { + m1() { + throw new Error("Method not implemented."); + } + static m0(arg0, arg1, arg2) { + throw new Error("Method not implemented."); + } + x: number; + static y: string; + constructor() { + this.y = undefined; + } +} +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts new file mode 100644 index 00000000000..94ad3f77615 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -0,0 +1,44 @@ +/// + +//// class A {[| +//// |]static foo0() { +//// this.m1(1,2,3); +//// A.m2(1,2); +//// this.prop1 = 10; +//// A.prop2 = "asdf"; +//// } +//// } + +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); +verify.applyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + static prop2: string; + static prop1: number; + static m2(arg0: any, arg1: any): any { + throw new Error("Method not implemented."); + } + static m1(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); + +// class A { +// static prop2: string; +// static prop1: number; +// static m2(arg0: any, arg1: any): any { +// throw new Error("Method not implemented."); +// } +// static m1(arg0: any, arg1: any, arg2: any): any { +// throw new Error("Method not implemented."); +// } +// static foo0() { +// this.m1(1,2,3); +// A.m2(1,2); +// this.prop1 = 10; +// A.prop2 = "asdf"; +// } +// } + diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts index b595a09c6a7..1f842a5bcf1 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -15,13 +15,13 @@ verify.applyCodeFix(/*errorCode*/undefined, 0); verify.applyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` - foo3() { + foo3(): any { throw new Error("Method not implemented."); } - foo2() { + foo2(): any { throw new Error("Method not implemented."); } - foo1(arg0: any, arg1: any, arg2: any) { + foo1(arg0: any, arg1: any, arg2: any): any { throw new Error("Method not implemented."); } `); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts new file mode 100644 index 00000000000..ee05d2c0a9c --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts @@ -0,0 +1,17 @@ +/// + +//// interface I { x: number; } +//// let i: I; +//// i.y; +//// i.foo(); +//// enum E { a,b } +//// let e: typeof E; +//// e.a; +//// e.c; +//// let obj = { a: 1, b: "asdf"}; +//// obj.c; +//// type T = I | U; +//// let t: T; +//// t.x; + +verify.not.codeFixAvailable(); \ No newline at end of file