forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
fixImportNonExportedMember
Signed-off-by: Richard Lynch <rlynch79@bloomberg.net>
- Loading branch information
Richard Lynch
committed
Jun 16, 2022
1 parent
f3ec897
commit c68ae3b
Showing
7 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 };`, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
}`, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 };`, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }`, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
tests/cases/fourslash/codeFixImportNonExportedMember_all.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }`, | ||
}, | ||
}); |