Skip to content

Commit

Permalink
Add tests for fixImportNonExportedMember
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Lynch <[email protected]>
  • Loading branch information
Richard Lynch committed Jun 16, 2022
1 parent f3ec897 commit c68ae3b
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////declare function zoo(): any;
////export { zoo };

// @Filename: /b.ts
////declare function foo(): any;
////function bar(): any;
////export { foo };

// @Filename: /c.ts
////import { zoo } from "./a";
////import { bar } from "./b";

goTo.file("/c.ts");
verify.codeFixAvailable([
{ description: `Export 'bar' from module './b'` },
{ description: `Remove import from './a'` },
{ description: `Remove import from './b'` },
]);
verify.codeFix({
index: 0,
description: `Export 'bar' from module './b'`,
newFileContent: {
"/b.ts": `declare function foo(): any;
export function bar(): any;
export { foo };`,
},
});
45 changes: 45 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// <reference path='fourslash.ts' />

// @Filename: /a.ts
////let a = 1, b = 2, c = 3;
////export function whatever() {
////}

// @Filename: /b.ts
////let d = 4;
////export function whatever2() {
////}

// @Filename: /c.ts
////import { a } from "./a"
////import { d } from "./b"

goTo.file("/c.ts");
verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Export 'd' from module './b'` },
{ description: `Remove import from './a'` },
{ description: `Remove import from './b'` },
]);
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
newFileContent: {
"/a.ts": `let a = 1, b = 2, c = 3;
export function whatever() {
}
export { a };
`,
},
});

verify.codeFix({
index: 1,
description: `Export 'd' from module './b'`,
newFileContent: {
"/b.ts": `export let d = 4;
export function whatever2() {
}`,
},
});
27 changes: 27 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////let a = 1, b = 2, c = 3;
////let d = 4;
////export function whatever() {
////}
////export { d }

// @Filename: /b.ts
////import { a, d } from "./a"

goTo.file("/b.ts");
verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Remove import from './a'` },
]);
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
newFileContent: {
"/a.ts": `let a = 1, b = 2, c = 3;
let d = 4;
export function whatever() {
}
export { a, d };`,
},
});
9 changes: 9 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
// @Filename: /node_modules/foo/index.d.ts
////let a = 0
////module.exports = 0;

// @Filename: /a.ts
////import { a } from "foo";

verify.not.codeFixAvailable();
29 changes: 29 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
/////**
//// * hello
//// */
////function a() {
////}
////export { d }

// @Filename: /b.ts
////import { a, d } from "./a"

goTo.file("/b.ts");
verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Remove import from './a'` },
]);
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
newFileContent: {
"/a.ts": `/**
* hello
*/
export function a() {
}
export { d }`,
},
});
27 changes: 27 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember6.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////let a = 1, b = 2, c = 3;
////let d = 4;
////export function whatever() {
////}
////export { a }

// @Filename: /b.ts
////import { a, b } from "./a"

goTo.file("/b.ts");
verify.codeFixAvailable([
{ description: `Export 'b' from module './a'` },
{ description: `Remove import from './a'` },
]);
verify.codeFix({
index: 0,
description: `Export 'b' from module './a'`,
newFileContent: {
"/a.ts": `let a = 1, b = 2, c = 3;
let d = 4;
export function whatever() {
}
export { a, b };`,
},
});
22 changes: 22 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember_all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />

// @Filename: /a.ts
////declare function foo(): any;
////declare function bar(): any;
////declare function zoo(): any;
////export { zoo }

// @Filename: /b.ts
////import { foo, bar } from "./a";

goTo.file("/b.ts");
verify.codeFixAll({
fixId: "importNonExportedMember",
fixAllDescription: ts.Diagnostics.Add_all_missing_exports.message,
newFileContent: {
"/a.ts": `export declare function foo(): any;
export declare function bar(): any;
declare function zoo(): any;
export { zoo }`,
},
});

0 comments on commit c68ae3b

Please sign in to comment.