@zzzen/pyright-internal 1.2.0-dev.20230430 → 1.2.0-dev.20230514
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +4 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +12 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +89 -6
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +14 -15
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +6 -0
- package/dist/analyzer/constructors.js +513 -0
- package/dist/analyzer/constructors.js.map +1 -0
- package/dist/analyzer/dataClasses.js +86 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +1 -1
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.js +62 -8
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +47 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +2 -2
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -6
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +16 -0
- package/dist/analyzer/operations.js +749 -0
- package/dist/analyzer/operations.js.map +1 -0
- package/dist/analyzer/parseTreeUtils.d.ts +4 -2
- package/dist/analyzer/parseTreeUtils.js +32 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +16 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +11 -33
- package/dist/analyzer/program.js +73 -735
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +5 -21
- package/dist/analyzer/service.js +26 -33
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +9 -41
- package/dist/analyzer/sourceFile.js +219 -238
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +3 -9
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -1
- package/dist/analyzer/symbol.js +5 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +460 -1425
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +42 -7
- package/dist/analyzer/typeEvaluatorTypes.js +33 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +2 -8
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +3 -3
- package/dist/analyzer/typePrinter.js +247 -100
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +14 -7
- package/dist/analyzer/typeUtils.js +204 -49
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +6 -7
- package/dist/analyzer/typeVarContext.js +21 -32
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +2 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +7 -4
- package/dist/analyzer/types.js +20 -10
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +16 -0
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/extensibility.d.ts +28 -4
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/logTracker.d.ts +2 -0
- package/dist/common/logTracker.js +8 -1
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/lspUtils.d.ts +4 -1
- package/dist/common/lspUtils.js +38 -1
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/pathUtils.d.ts +11 -11
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +2 -1
- package/dist/common/pythonVersion.js +1 -0
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +8 -8
- package/dist/common/workspaceEditUtils.js +10 -10
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -7
- package/dist/languageServerBase.js +41 -73
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +50 -51
- package/dist/languageService/autoImporter.js +125 -210
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +1 -1
- package/dist/languageService/callHierarchyProvider.js +11 -37
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +39 -81
- package/dist/languageService/completionProvider.js +572 -801
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +1 -1
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +6 -7
- package/dist/languageService/documentSymbolCollector.js +47 -28
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +13 -35
- package/dist/languageService/documentSymbolProvider.js +52 -264
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +5 -6
- package/dist/languageService/hoverProvider.js +40 -132
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +6 -11
- package/dist/languageService/referencesProvider.js +23 -17
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +16 -0
- package/dist/languageService/renameProvider.js +139 -0
- package/dist/languageService/renameProvider.js.map +1 -0
- package/dist/languageService/symbolIndexer.d.ts +31 -0
- package/dist/languageService/symbolIndexer.js +105 -0
- package/dist/languageService/symbolIndexer.js.map +1 -0
- package/dist/languageService/tooltipUtils.d.ts +8 -1
- package/dist/languageService/tooltipUtils.js +102 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.d.ts +17 -0
- package/dist/languageService/workspaceSymbolProvider.js +133 -0
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -0
- package/dist/localization/localize.d.ts +33 -15
- package/dist/localization/localize.js +13 -7
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +14 -7
- package/dist/parser/parser.js +3 -0
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +26 -4
- package/dist/pyright.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +15 -20
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +14 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +11 -236
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +36 -2
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/documentSymbolCollector.test.js +3 -3
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +1 -16
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +4 -4
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +1 -1
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +17 -11
- package/dist/tests/harness/fourslash/testState.js +39 -50
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importResolver.test.js +81 -1
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +1 -1
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +2 -2
- package/dist/tests/testStateUtils.js +38 -8
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +13 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +9 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +25 -9
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +95 -6
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/languageService/importAdder.d.ts +0 -40
- package/dist/languageService/importAdder.js +0 -388
- package/dist/languageService/importAdder.js.map +0 -1
- package/dist/languageService/indentationUtils.d.ts +0 -16
- package/dist/languageService/indentationUtils.js +0 -727
- package/dist/languageService/indentationUtils.js.map +0 -1
- package/dist/languageService/insertionPointUtils.d.ts +0 -9
- package/dist/languageService/insertionPointUtils.js +0 -132
- package/dist/languageService/insertionPointUtils.js.map +0 -1
- package/dist/languageService/renameModuleProvider.d.ts +0 -65
- package/dist/languageService/renameModuleProvider.js +0 -939
- package/dist/languageService/renameModuleProvider.js.map +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.js +0 -81
- package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +0 -1
- package/dist/tests/importAdder.test.d.ts +0 -1
- package/dist/tests/importAdder.test.js +0 -1325
- package/dist/tests/importAdder.test.js.map +0 -1
- package/dist/tests/indentationUtils.ptvs.test.d.ts +0 -1
- package/dist/tests/indentationUtils.ptvs.test.js +0 -324
- package/dist/tests/indentationUtils.ptvs.test.js.map +0 -1
- package/dist/tests/indentationUtils.reindent.test.d.ts +0 -1
- package/dist/tests/indentationUtils.reindent.test.js +0 -372
- package/dist/tests/indentationUtils.reindent.test.js.map +0 -1
- package/dist/tests/indentationUtils.test.d.ts +0 -1
- package/dist/tests/indentationUtils.test.js +0 -502
- package/dist/tests/indentationUtils.test.js.map +0 -1
- package/dist/tests/insertionPointUtils.test.d.ts +0 -1
- package/dist/tests/insertionPointUtils.test.js +0 -154
- package/dist/tests/insertionPointUtils.test.js.map +0 -1
- package/dist/tests/moveSymbol.importAdder.test.d.ts +0 -1
- package/dist/tests/moveSymbol.importAdder.test.js +0 -298
- package/dist/tests/moveSymbol.importAdder.test.js.map +0 -1
- package/dist/tests/moveSymbol.insertion.test.d.ts +0 -1
- package/dist/tests/moveSymbol.insertion.test.js +0 -537
- package/dist/tests/moveSymbol.insertion.test.js.map +0 -1
- package/dist/tests/moveSymbol.misc.test.d.ts +0 -1
- package/dist/tests/moveSymbol.misc.test.js +0 -169
- package/dist/tests/moveSymbol.misc.test.js.map +0 -1
- package/dist/tests/moveSymbol.updateReference.test.d.ts +0 -1
- package/dist/tests/moveSymbol.updateReference.test.js +0 -1071
- package/dist/tests/moveSymbol.updateReference.test.js.map +0 -1
- package/dist/tests/renameModule.folder.test.d.ts +0 -1
- package/dist/tests/renameModule.folder.test.js +0 -229
- package/dist/tests/renameModule.folder.test.js.map +0 -1
- package/dist/tests/renameModule.fromImports.test.d.ts +0 -1
- package/dist/tests/renameModule.fromImports.test.js +0 -790
- package/dist/tests/renameModule.fromImports.test.js.map +0 -1
- package/dist/tests/renameModule.imports.test.d.ts +0 -1
- package/dist/tests/renameModule.imports.test.js +0 -380
- package/dist/tests/renameModule.imports.test.js.map +0 -1
- package/dist/tests/renameModule.misc.test.d.ts +0 -1
- package/dist/tests/renameModule.misc.test.js +0 -615
- package/dist/tests/renameModule.misc.test.js.map +0 -1
- package/dist/tests/renameModule.relativePath.test.d.ts +0 -1
- package/dist/tests/renameModule.relativePath.test.js +0 -231
- package/dist/tests/renameModule.relativePath.test.js.map +0 -1
- package/dist/tests/renameModuleTestUtils.d.ts +0 -4
- package/dist/tests/renameModuleTestUtils.js +0 -76
- package/dist/tests/renameModuleTestUtils.js.map +0 -1
@@ -1,1325 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/*
|
3
|
-
* importAdder.test.ts
|
4
|
-
* Copyright (c) Microsoft Corporation.
|
5
|
-
* Licensed under the MIT license.
|
6
|
-
*
|
7
|
-
* tests for importMover.
|
8
|
-
*/
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
11
|
-
};
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
const assert_1 = __importDefault(require("assert"));
|
14
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
15
|
-
const parseTreeUtils_1 = require("../analyzer/parseTreeUtils");
|
16
|
-
const textEditTracker_1 = require("../common/textEditTracker");
|
17
|
-
const textRange_1 = require("../common/textRange");
|
18
|
-
const importAdder_1 = require("../languageService/importAdder");
|
19
|
-
const testState_1 = require("./harness/fourslash/testState");
|
20
|
-
const testStateUtils_1 = require("./testStateUtils");
|
21
|
-
test('builtin types', () => {
|
22
|
-
const code = `
|
23
|
-
// @filename: test1.py
|
24
|
-
//// [|/*src*/a: str = "hello"
|
25
|
-
//// b: int = 1
|
26
|
-
//// c: True = True
|
27
|
-
//// d: None = None|]
|
28
|
-
|
29
|
-
// @filename: test2.py
|
30
|
-
//// [|/*dest*/|]
|
31
|
-
`;
|
32
|
-
testImportMove(code);
|
33
|
-
});
|
34
|
-
test('intrinsic types', () => {
|
35
|
-
const code = `
|
36
|
-
// @filename: test1.py
|
37
|
-
//// if __name__ == __path__:
|
38
|
-
//// pass
|
39
|
-
////
|
40
|
-
//// [|/*src*/if __name__ === "__main__":
|
41
|
-
//// pass
|
42
|
-
//// b = __path__|]
|
43
|
-
|
44
|
-
// @filename: test2.py
|
45
|
-
//// [|/*dest*/|]
|
46
|
-
`;
|
47
|
-
testImportMove(code);
|
48
|
-
});
|
49
|
-
test('handle variable in range', () => {
|
50
|
-
const code = `
|
51
|
-
// @filename: test1.py
|
52
|
-
//// [|/*src*/variableToMove = 1|]
|
53
|
-
|
54
|
-
// @filename: test2.py
|
55
|
-
//// [|/*dest*/|]
|
56
|
-
`;
|
57
|
-
testImportMove(code);
|
58
|
-
});
|
59
|
-
test('move variable', () => {
|
60
|
-
const code = `
|
61
|
-
// @filename: test1.py
|
62
|
-
//// variableToMove = 1
|
63
|
-
//// [|/*src*/a = variableToMove|]
|
64
|
-
|
65
|
-
// @filename: test2.py
|
66
|
-
//// [|/*dest*/{|"r":"from test1 import variableToMove!n!!n!!n!"|}|]
|
67
|
-
`;
|
68
|
-
testImportMove(code);
|
69
|
-
});
|
70
|
-
test('move multiple variables', () => {
|
71
|
-
const code = `
|
72
|
-
// @filename: test1.py
|
73
|
-
//// variableToMove1 = 1
|
74
|
-
//// variableToMove2 = 2
|
75
|
-
//// [|/*src*/a = variableToMove1
|
76
|
-
//// a = variableToMove2|]
|
77
|
-
|
78
|
-
// @filename: test2.py
|
79
|
-
//// [|/*dest*/{|"r":"from test1 import variableToMove1, variableToMove2!n!!n!!n!"|}|]
|
80
|
-
`;
|
81
|
-
testImportMove(code);
|
82
|
-
});
|
83
|
-
test('handle local variables', () => {
|
84
|
-
const code = `
|
85
|
-
// @filename: test1.py
|
86
|
-
//// def foo():
|
87
|
-
//// variableToMove1 = 1
|
88
|
-
//// variableToMove2 = 2
|
89
|
-
//// [|/*src*/a = variableToMove1
|
90
|
-
//// a = variableToMove2|]
|
91
|
-
|
92
|
-
// @filename: test2.py
|
93
|
-
//// [|/*dest*/|]
|
94
|
-
`;
|
95
|
-
testImportMove(code);
|
96
|
-
});
|
97
|
-
test('handle parameter variable', () => {
|
98
|
-
const code = `
|
99
|
-
// @filename: test1.py
|
100
|
-
//// def foo(p: int):
|
101
|
-
//// [|/*src*/a = p|]
|
102
|
-
|
103
|
-
// @filename: test2.py
|
104
|
-
//// [|/*dest*/|]
|
105
|
-
`;
|
106
|
-
testImportMove(code);
|
107
|
-
});
|
108
|
-
test('move private variable', () => {
|
109
|
-
const code = `
|
110
|
-
// @filename: test1.py
|
111
|
-
//// __private = 1
|
112
|
-
//// [|/*src*/a = __private|]
|
113
|
-
|
114
|
-
// @filename: test2.py
|
115
|
-
//// [|/*dest*/{|"r":"from test1 import __private!n!!n!!n!"|}|]
|
116
|
-
`;
|
117
|
-
testImportMove(code);
|
118
|
-
});
|
119
|
-
test('handle function in range', () => {
|
120
|
-
const code = `
|
121
|
-
// @filename: test1.py
|
122
|
-
//// [|/*src*/def foo():
|
123
|
-
//// pass|]
|
124
|
-
|
125
|
-
// @filename: test2.py
|
126
|
-
//// [|/*dest*/|]
|
127
|
-
`;
|
128
|
-
testImportMove(code);
|
129
|
-
});
|
130
|
-
test('move function', () => {
|
131
|
-
const code = `
|
132
|
-
// @filename: test1.py
|
133
|
-
//// def foo(): pass
|
134
|
-
//// [|/*src*/foo()|]
|
135
|
-
|
136
|
-
// @filename: test2.py
|
137
|
-
//// [|/*dest*/{|"r":"from test1 import foo!n!!n!!n!"|}|]
|
138
|
-
`;
|
139
|
-
testImportMove(code);
|
140
|
-
});
|
141
|
-
test('move multiple functions', () => {
|
142
|
-
const code = `
|
143
|
-
// @filename: test1.py
|
144
|
-
//// def foo(): pass
|
145
|
-
//// def bar(): pass
|
146
|
-
//// [|/*src*/foo()
|
147
|
-
//// bar()|]
|
148
|
-
|
149
|
-
// @filename: test2.py
|
150
|
-
//// [|/*dest*/{|"r":"from test1 import bar, foo!n!!n!!n!"|}|]
|
151
|
-
`;
|
152
|
-
testImportMove(code);
|
153
|
-
});
|
154
|
-
test('handle inner function', () => {
|
155
|
-
const code = `
|
156
|
-
// @filename: test1.py
|
157
|
-
//// def foo():
|
158
|
-
//// def bar(): pass
|
159
|
-
//// [|/*src*/bar()|]
|
160
|
-
|
161
|
-
// @filename: test2.py
|
162
|
-
//// [|/*dest*/|]
|
163
|
-
`;
|
164
|
-
testImportMove(code);
|
165
|
-
});
|
166
|
-
test('move private function', () => {
|
167
|
-
const code = `
|
168
|
-
// @filename: test1.py
|
169
|
-
//// def __private(): pass
|
170
|
-
//// [|/*src*/__private()|]
|
171
|
-
|
172
|
-
// @filename: test2.py
|
173
|
-
//// [|/*dest*/{|"r":"from test1 import __private!n!!n!!n!"|}|]
|
174
|
-
`;
|
175
|
-
testImportMove(code);
|
176
|
-
});
|
177
|
-
test('handle class in range', () => {
|
178
|
-
const code = `
|
179
|
-
// @filename: test1.py
|
180
|
-
//// [|/*src*/class A: pass|]
|
181
|
-
|
182
|
-
// @filename: test2.py
|
183
|
-
//// [|/*dest*/|]
|
184
|
-
`;
|
185
|
-
testImportMove(code);
|
186
|
-
});
|
187
|
-
test('move class', () => {
|
188
|
-
const code = `
|
189
|
-
// @filename: test1.py
|
190
|
-
//// class A: pass
|
191
|
-
//// [|/*src*/a = A()|]
|
192
|
-
|
193
|
-
// @filename: test2.py
|
194
|
-
//// [|/*dest*/{|"r":"from test1 import A!n!!n!!n!"|}|]
|
195
|
-
`;
|
196
|
-
testImportMove(code);
|
197
|
-
});
|
198
|
-
test('move multiple classes', () => {
|
199
|
-
const code = `
|
200
|
-
// @filename: test1.py
|
201
|
-
//// class A: pass
|
202
|
-
//// class B: pass
|
203
|
-
//// [|/*src*/a = A()
|
204
|
-
//// a = B()|]
|
205
|
-
|
206
|
-
// @filename: test2.py
|
207
|
-
//// [|/*dest*/{|"r":"from test1 import A, B!n!!n!!n!"|}|]
|
208
|
-
`;
|
209
|
-
testImportMove(code);
|
210
|
-
});
|
211
|
-
test('handle inner class through self', () => {
|
212
|
-
const code = `
|
213
|
-
// @filename: test1.py
|
214
|
-
//// class A:
|
215
|
-
//// class B: pass
|
216
|
-
//// def foo(self):
|
217
|
-
//// [|/*src*/b = self.B()|]
|
218
|
-
|
219
|
-
// @filename: test2.py
|
220
|
-
//// [|/*dest*/|]
|
221
|
-
`;
|
222
|
-
testImportMove(code);
|
223
|
-
});
|
224
|
-
test('handle inner class through type', () => {
|
225
|
-
const code = `
|
226
|
-
// @filename: test1.py
|
227
|
-
//// class A:
|
228
|
-
//// class B: pass
|
229
|
-
//// def foo(self):
|
230
|
-
//// [|/*src*/b = A.B()|]
|
231
|
-
|
232
|
-
// @filename: test2.py
|
233
|
-
//// [|/*dest*/{|"r":"from test1 import A!n!!n!!n!"|}|]
|
234
|
-
`;
|
235
|
-
testImportMove(code);
|
236
|
-
});
|
237
|
-
test('handle class variable', () => {
|
238
|
-
const code = `
|
239
|
-
// @filename: test1.py
|
240
|
-
//// class A:
|
241
|
-
//// def __init__(self):
|
242
|
-
//// self.a = 1
|
243
|
-
//// c = A();
|
244
|
-
//// [|/*src*/a = c.a|]
|
245
|
-
|
246
|
-
// @filename: test2.py
|
247
|
-
//// [|/*dest*/{|"r":"from test1 import c!n!!n!!n!"|}|]
|
248
|
-
`;
|
249
|
-
testImportMove(code);
|
250
|
-
});
|
251
|
-
test('handle class static variable', () => {
|
252
|
-
const code = `
|
253
|
-
// @filename: test1.py
|
254
|
-
//// class A:
|
255
|
-
//// V = 1
|
256
|
-
//// [|/*src*/a = A.V|]
|
257
|
-
|
258
|
-
// @filename: test2.py
|
259
|
-
//// [|/*dest*/{|"r":"from test1 import A!n!!n!!n!"|}|]
|
260
|
-
`;
|
261
|
-
testImportMove(code);
|
262
|
-
});
|
263
|
-
test('handle class function', () => {
|
264
|
-
const code = `
|
265
|
-
// @filename: test1.py
|
266
|
-
//// class A:
|
267
|
-
//// def __init__(self): pass
|
268
|
-
//// def foo(self): pass
|
269
|
-
//// c = A();
|
270
|
-
//// [|/*src*/a = c.foo()|]
|
271
|
-
|
272
|
-
// @filename: test2.py
|
273
|
-
//// [|/*dest*/{|"r":"from test1 import c!n!!n!!n!"|}|]
|
274
|
-
`;
|
275
|
-
testImportMove(code);
|
276
|
-
});
|
277
|
-
test('handle class static function', () => {
|
278
|
-
const code = `
|
279
|
-
// @filename: test1.py
|
280
|
-
//// class A:
|
281
|
-
//// def Foo(): pass
|
282
|
-
//// [|/*src*/a = A.Foo()|]
|
283
|
-
|
284
|
-
// @filename: test2.py
|
285
|
-
//// [|/*dest*/{|"r":"from test1 import A!n!!n!!n!"|}|]
|
286
|
-
`;
|
287
|
-
testImportMove(code);
|
288
|
-
});
|
289
|
-
test('handle class function parameter', () => {
|
290
|
-
const code = `
|
291
|
-
// @filename: test1.py
|
292
|
-
//// class A:
|
293
|
-
//// def __init__(self):
|
294
|
-
//// [|/*src*/self.a = 1|]
|
295
|
-
|
296
|
-
// @filename: test2.py
|
297
|
-
//// [|/*dest*/|]
|
298
|
-
`;
|
299
|
-
testImportMove(code);
|
300
|
-
});
|
301
|
-
test('move private class', () => {
|
302
|
-
const code = `
|
303
|
-
// @filename: test1.py
|
304
|
-
//// class __A:
|
305
|
-
//// class B: pass
|
306
|
-
//// [|/*src*/a = __A()|]
|
307
|
-
|
308
|
-
// @filename: test2.py
|
309
|
-
//// [|/*dest*/{|"r":"from test1 import __A!n!!n!!n!"|}|]
|
310
|
-
`;
|
311
|
-
testImportMove(code);
|
312
|
-
});
|
313
|
-
test('move simple import statement', () => {
|
314
|
-
const code = `
|
315
|
-
// @filename: test1.py
|
316
|
-
//// import typing
|
317
|
-
////
|
318
|
-
//// [|/*src*/a: typing.Any = 1|]
|
319
|
-
|
320
|
-
// @filename: test2.py
|
321
|
-
//// [|/*dest*/{|"r":"import typing!n!!n!!n!"|}|]
|
322
|
-
////
|
323
|
-
`;
|
324
|
-
testImportMove(code);
|
325
|
-
});
|
326
|
-
test('move import statement with alias', () => {
|
327
|
-
const code = `
|
328
|
-
// @filename: test1.py
|
329
|
-
//// import typing as t
|
330
|
-
////
|
331
|
-
//// [|/*src*/a: t.Any = 1|]
|
332
|
-
|
333
|
-
// @filename: test2.py
|
334
|
-
//// [|/*dest*/{|"r":"import typing as t!n!!n!!n!"|}|]
|
335
|
-
////
|
336
|
-
`;
|
337
|
-
testImportMove(code);
|
338
|
-
});
|
339
|
-
test('move dotted import statement', () => {
|
340
|
-
const code = `
|
341
|
-
// @filename: test1.py
|
342
|
-
//// import json.encoder
|
343
|
-
////
|
344
|
-
//// [|/*src*/a = json.encoder.JSONEncoder()|]
|
345
|
-
|
346
|
-
// @filename: test2.py
|
347
|
-
//// [|/*dest*/{|"r":"import json.encoder!n!!n!!n!"|}|]
|
348
|
-
////
|
349
|
-
`;
|
350
|
-
testImportMove(code);
|
351
|
-
});
|
352
|
-
test('move dotted statement with alias', () => {
|
353
|
-
const code = `
|
354
|
-
// @filename: test1.py
|
355
|
-
//// import json.encoder as j
|
356
|
-
////
|
357
|
-
//// [|/*src*/a = j.JSONEncoder()|]
|
358
|
-
|
359
|
-
// @filename: test2.py
|
360
|
-
//// [|/*dest*/{|"r":"import json.encoder as j!n!!n!!n!"|}|]
|
361
|
-
////
|
362
|
-
`;
|
363
|
-
testImportMove(code);
|
364
|
-
});
|
365
|
-
test('move both dotted import and regular statement', () => {
|
366
|
-
const code = `
|
367
|
-
// @filename: test1.py
|
368
|
-
//// import json
|
369
|
-
//// import json.encoder
|
370
|
-
////
|
371
|
-
//// a = json.encoder.JSONEncoder()
|
372
|
-
//// [|/*src*/b = json.loads("")|]
|
373
|
-
|
374
|
-
// @filename: test2.py
|
375
|
-
//// [|/*dest*/{|"r":"import json!n!!n!!n!"|}|]
|
376
|
-
////
|
377
|
-
`;
|
378
|
-
testImportMove(code);
|
379
|
-
});
|
380
|
-
test('move both dotted import and regular statement with alias', () => {
|
381
|
-
const code = `
|
382
|
-
// @filename: test1.py
|
383
|
-
//// import json as j
|
384
|
-
//// import json.encoder
|
385
|
-
////
|
386
|
-
//// a = json.encoder.JSONEncoder()
|
387
|
-
//// [|/*src*/b = j.loads("")|]
|
388
|
-
|
389
|
-
// @filename: test2.py
|
390
|
-
//// [|/*dest*/{|"r":"import json as j!n!!n!!n!"|}|]
|
391
|
-
////
|
392
|
-
`;
|
393
|
-
testImportMove(code);
|
394
|
-
});
|
395
|
-
test('move multiple import statements', () => {
|
396
|
-
const code = `
|
397
|
-
// @filename: test1.py
|
398
|
-
//// import json
|
399
|
-
//// import json.encoder
|
400
|
-
////
|
401
|
-
//// [|/*src*/a = json.encoder.JSONEncoder()
|
402
|
-
//// b = json.loads("")|]
|
403
|
-
|
404
|
-
// @filename: test2.py
|
405
|
-
//// [|/*dest*/{|"r":"import json!n!import json.encoder!n!!n!!n!"|}|]
|
406
|
-
////
|
407
|
-
`;
|
408
|
-
testImportMove(code);
|
409
|
-
});
|
410
|
-
test('move multiple import statements with alias', () => {
|
411
|
-
const code = `
|
412
|
-
// @filename: test1.py
|
413
|
-
//// import json as j
|
414
|
-
//// import json.encoder as j2
|
415
|
-
////
|
416
|
-
//// [|/*src*/a = j2.JSONEncoder()
|
417
|
-
//// b = j.loads("")|]
|
418
|
-
|
419
|
-
// @filename: test2.py
|
420
|
-
//// [|/*dest*/{|"r":"import json as j!n!import json.encoder as j2!n!!n!!n!"|}|]
|
421
|
-
////
|
422
|
-
`;
|
423
|
-
testImportMove(code);
|
424
|
-
});
|
425
|
-
test('move multiple import statements - nested', () => {
|
426
|
-
const code = `
|
427
|
-
// @filename: test1.py
|
428
|
-
//// def foo():
|
429
|
-
//// import json
|
430
|
-
//// import json.encoder
|
431
|
-
////
|
432
|
-
//// [|/*src*/a = json.encoder.JSONEncoder()
|
433
|
-
//// b = json.loads("")|]
|
434
|
-
|
435
|
-
// @filename: test2.py
|
436
|
-
//// [|/*dest*/{|"r":"import json!n!import json.encoder!n!!n!!n!"|}|]
|
437
|
-
////
|
438
|
-
`;
|
439
|
-
testImportMove(code);
|
440
|
-
});
|
441
|
-
test('move multiple import statements - part of nested body', () => {
|
442
|
-
const code = `
|
443
|
-
// @filename: test1.py
|
444
|
-
//// def foo():
|
445
|
-
//// import json
|
446
|
-
//// import json.encoder
|
447
|
-
////
|
448
|
-
//// [|/*src*/a = json.encoder.JSONEncoder()|]
|
449
|
-
//// b = json.loads("")
|
450
|
-
|
451
|
-
// @filename: test2.py
|
452
|
-
//// [|/*dest*/{|"r":"import json.encoder!n!!n!!n!"|}|]
|
453
|
-
////
|
454
|
-
`;
|
455
|
-
testImportMove(code);
|
456
|
-
});
|
457
|
-
test('move multiple import statements - multi dotted name', () => {
|
458
|
-
const code = `
|
459
|
-
// @filename: nested/__init__.py
|
460
|
-
//// def foo(): pass
|
461
|
-
|
462
|
-
// @filename: nested/nested2/__init__.py
|
463
|
-
//// def foo(): pass
|
464
|
-
|
465
|
-
// @filename: nested/nested2/module.py
|
466
|
-
//// def foo(): pass
|
467
|
-
|
468
|
-
// @filename: test1.py
|
469
|
-
//// import nested
|
470
|
-
//// import nested.nested2
|
471
|
-
//// import nested.nested2.module
|
472
|
-
////
|
473
|
-
//// nested.foo()
|
474
|
-
////
|
475
|
-
//// [|/*src*/nested.nested2.foo()
|
476
|
-
//// nested.nested2.module.foo()|]
|
477
|
-
|
478
|
-
// @filename: test2.py
|
479
|
-
//// [|/*dest*/{|"r":"import nested.nested2!n!import nested.nested2.module!n!!n!!n!"|}|]
|
480
|
-
`;
|
481
|
-
testImportMove(code);
|
482
|
-
});
|
483
|
-
test('move simple from import statement', () => {
|
484
|
-
const code = `
|
485
|
-
// @filename: test1.py
|
486
|
-
//// from typing import Any
|
487
|
-
////
|
488
|
-
//// [|/*src*/a: Any = 1|]
|
489
|
-
|
490
|
-
// @filename: test2.py
|
491
|
-
//// [|/*dest*/{|"r":"from typing import Any!n!!n!!n!"|}|]
|
492
|
-
////
|
493
|
-
`;
|
494
|
-
testImportMove(code);
|
495
|
-
});
|
496
|
-
test('move from import statement with alias', () => {
|
497
|
-
const code = `
|
498
|
-
// @filename: test1.py
|
499
|
-
//// from typing import Any as t
|
500
|
-
////
|
501
|
-
//// [|/*src*/a: t = 1|]
|
502
|
-
|
503
|
-
// @filename: test2.py
|
504
|
-
//// [|/*dest*/{|"r":"from typing import Any as t!n!!n!!n!"|}|]
|
505
|
-
////
|
506
|
-
`;
|
507
|
-
testImportMove(code);
|
508
|
-
});
|
509
|
-
test('move submodule from import statement', () => {
|
510
|
-
const code = `
|
511
|
-
// @filename: test1.py
|
512
|
-
//// from json import encoder
|
513
|
-
////
|
514
|
-
//// [|/*src*/a = encoder.JSONEncoder()|]
|
515
|
-
|
516
|
-
// @filename: test2.py
|
517
|
-
//// [|/*dest*/{|"r":"from json import encoder!n!!n!!n!"|}|]
|
518
|
-
////
|
519
|
-
`;
|
520
|
-
testImportMove(code);
|
521
|
-
});
|
522
|
-
test('move submodule from import statement with alias', () => {
|
523
|
-
const code = `
|
524
|
-
// @filename: test1.py
|
525
|
-
//// from json import encoder as e
|
526
|
-
////
|
527
|
-
//// [|/*src*/a = e.JSONEncoder()|]
|
528
|
-
|
529
|
-
// @filename: test2.py
|
530
|
-
//// [|/*dest*/{|"r":"from json import encoder as e!n!!n!!n!"|}|]
|
531
|
-
////
|
532
|
-
`;
|
533
|
-
testImportMove(code);
|
534
|
-
});
|
535
|
-
test('move dotted from import statement', () => {
|
536
|
-
const code = `
|
537
|
-
// @filename: test1.py
|
538
|
-
//// from json.encoder import JSONEncoder
|
539
|
-
////
|
540
|
-
//// [|/*src*/a = JSONEncoder()|]
|
541
|
-
|
542
|
-
// @filename: test2.py
|
543
|
-
//// [|/*dest*/{|"r":"from json.encoder import JSONEncoder!n!!n!!n!"|}|]
|
544
|
-
////
|
545
|
-
`;
|
546
|
-
testImportMove(code);
|
547
|
-
});
|
548
|
-
test('move dotted from import statement with alias', () => {
|
549
|
-
const code = `
|
550
|
-
// @filename: test1.py
|
551
|
-
//// from json.encoder import JSONEncoder as j
|
552
|
-
////
|
553
|
-
//// [|/*src*/a = j()|]
|
554
|
-
|
555
|
-
// @filename: test2.py
|
556
|
-
//// [|/*dest*/{|"r":"from json.encoder import JSONEncoder as j!n!!n!!n!"|}|]
|
557
|
-
////
|
558
|
-
`;
|
559
|
-
testImportMove(code);
|
560
|
-
});
|
561
|
-
test('move both dotted from import and regular statement', () => {
|
562
|
-
const code = `
|
563
|
-
// @filename: test1.py
|
564
|
-
//// from json import loads
|
565
|
-
//// from json.encoder import JSONEncoder
|
566
|
-
////
|
567
|
-
//// a = JSONEncoder()
|
568
|
-
//// [|/*src*/b = loads("")|]
|
569
|
-
|
570
|
-
// @filename: test2.py
|
571
|
-
//// [|/*dest*/{|"r":"from json import loads!n!!n!!n!"|}|]
|
572
|
-
////
|
573
|
-
`;
|
574
|
-
testImportMove(code);
|
575
|
-
});
|
576
|
-
test('move both dotted from import and regular statement with alias', () => {
|
577
|
-
const code = `
|
578
|
-
// @filename: test1.py
|
579
|
-
//// from json import loads as j
|
580
|
-
//// from json.encoder import JSONEncoder
|
581
|
-
////
|
582
|
-
//// a = JSONEncoder()
|
583
|
-
//// [|/*src*/b = j("")|]
|
584
|
-
|
585
|
-
// @filename: test2.py
|
586
|
-
//// [|/*dest*/{|"r":"from json import loads as j!n!!n!!n!"|}|]
|
587
|
-
////
|
588
|
-
`;
|
589
|
-
testImportMove(code);
|
590
|
-
});
|
591
|
-
test('move multiple from import statements', () => {
|
592
|
-
const code = `
|
593
|
-
// @filename: test1.py
|
594
|
-
//// from json import loads
|
595
|
-
//// from json.encoder import JSONEncoder
|
596
|
-
////
|
597
|
-
//// [|/*src*/a = JSONEncoder()
|
598
|
-
//// b = loads("")|]
|
599
|
-
|
600
|
-
// @filename: test2.py
|
601
|
-
//// [|/*dest*/{|"r":"from json import loads!n!from json.encoder import JSONEncoder!n!!n!!n!"|}|]
|
602
|
-
////
|
603
|
-
`;
|
604
|
-
testImportMove(code);
|
605
|
-
});
|
606
|
-
test('move multiple from import statements with alias', () => {
|
607
|
-
const code = `
|
608
|
-
// @filename: test1.py
|
609
|
-
//// from json import loads as j
|
610
|
-
//// from json.encoder import JSONEncoder as j2
|
611
|
-
////
|
612
|
-
//// [|/*src*/a = j2()
|
613
|
-
//// b = j("")|]
|
614
|
-
|
615
|
-
// @filename: test2.py
|
616
|
-
//// [|/*dest*/{|"r":"from json import loads as j!n!from json.encoder import JSONEncoder as j2!n!!n!!n!"|}|]
|
617
|
-
////
|
618
|
-
`;
|
619
|
-
testImportMove(code);
|
620
|
-
});
|
621
|
-
test('move multiple from import statements - nested', () => {
|
622
|
-
const code = `
|
623
|
-
// @filename: test1.py
|
624
|
-
//// def foo():
|
625
|
-
//// from json import loads
|
626
|
-
//// from json.encoder import JSONEncoder
|
627
|
-
////
|
628
|
-
//// [|/*src*/a = JSONEncoder()
|
629
|
-
//// b = loads("")|]
|
630
|
-
|
631
|
-
// @filename: test2.py
|
632
|
-
//// [|/*dest*/{|"r":"from json import loads!n!from json.encoder import JSONEncoder!n!!n!!n!"|}|]
|
633
|
-
////
|
634
|
-
`;
|
635
|
-
testImportMove(code);
|
636
|
-
});
|
637
|
-
test('move multiple from import statements - part of nested body', () => {
|
638
|
-
const code = `
|
639
|
-
// @filename: test1.py
|
640
|
-
//// def foo():
|
641
|
-
//// from json import loads
|
642
|
-
//// from json.encoder import JSONEncoder
|
643
|
-
////
|
644
|
-
//// [|/*src*/a = JSONEncoder()|]
|
645
|
-
//// b = loads("")
|
646
|
-
|
647
|
-
// @filename: test2.py
|
648
|
-
//// [|/*dest*/{|"r":"from json.encoder import JSONEncoder!n!!n!!n!"|}|]
|
649
|
-
////
|
650
|
-
`;
|
651
|
-
testImportMove(code);
|
652
|
-
});
|
653
|
-
test('move multiple from import statements - multi dotted name', () => {
|
654
|
-
const code = `
|
655
|
-
// @filename: nested/__init__.py
|
656
|
-
//// def foo(): pass
|
657
|
-
|
658
|
-
// @filename: nested/nested2/__init__.py
|
659
|
-
//// def foo2(): pass
|
660
|
-
|
661
|
-
// @filename: nested/nested2/module.py
|
662
|
-
//// def foo3(): pass
|
663
|
-
|
664
|
-
// @filename: test1.py
|
665
|
-
//// from nested import foo
|
666
|
-
//// from nested.nested2 import foo2
|
667
|
-
//// from nested.nested2.module import foo3
|
668
|
-
////
|
669
|
-
//// foo()
|
670
|
-
////
|
671
|
-
//// [|/*src*/foo2()
|
672
|
-
//// foo3()|]
|
673
|
-
|
674
|
-
// @filename: test2.py
|
675
|
-
//// [|/*dest*/{|"r":"from nested.nested2 import foo2!n!from nested.nested2.module import foo3!n!!n!!n!"|}|]
|
676
|
-
`;
|
677
|
-
testImportMove(code);
|
678
|
-
});
|
679
|
-
test('relative path from import', () => {
|
680
|
-
const code = `
|
681
|
-
// @filename: nested/__init__.py
|
682
|
-
//// def foo(): pass
|
683
|
-
|
684
|
-
// @filename: nested/nested2/__init__.py
|
685
|
-
//// def foo2(): pass
|
686
|
-
|
687
|
-
// @filename: nested/nested2/module.py
|
688
|
-
//// def foo3(): pass
|
689
|
-
|
690
|
-
// @filename: nested/nested2/test1.py
|
691
|
-
//// from ...nested import foo
|
692
|
-
//// from ..nested2 import foo2
|
693
|
-
//// from .module import foo3
|
694
|
-
//// [|/*src*/foo()
|
695
|
-
//// foo2()
|
696
|
-
//// foo3()|]
|
697
|
-
|
698
|
-
// @filename: test2.py
|
699
|
-
//// [|/*dest*/{|"r":"from nested import foo!n!from nested.nested2 import foo2!n!from nested.nested2.module import foo3!n!!n!!n!"|}|]
|
700
|
-
`;
|
701
|
-
testImportMove(code);
|
702
|
-
});
|
703
|
-
test('namespace package from import', () => {
|
704
|
-
const code = `
|
705
|
-
// @filename: nested/module.py
|
706
|
-
//// def foo(): pass
|
707
|
-
|
708
|
-
// @filename: test1.py
|
709
|
-
//// from nested.module import foo
|
710
|
-
////
|
711
|
-
//// [|/*src*/foo()|]
|
712
|
-
|
713
|
-
// @filename: test2.py
|
714
|
-
//// [|/*dest*/{|"r":"from nested.module import foo!n!!n!!n!"|}|]
|
715
|
-
`;
|
716
|
-
testImportMove(code);
|
717
|
-
});
|
718
|
-
test('namespace package with submodule from import', () => {
|
719
|
-
const code = `
|
720
|
-
// @filename: nested/module.py
|
721
|
-
//// def foo(): pass
|
722
|
-
|
723
|
-
// @filename: test1.py
|
724
|
-
//// from nested import module
|
725
|
-
////
|
726
|
-
//// [|/*src*/module.foo()|]
|
727
|
-
|
728
|
-
// @filename: test2.py
|
729
|
-
//// [|/*dest*/{|"r":"from nested import module!n!!n!!n!"|}|]
|
730
|
-
`;
|
731
|
-
testImportMove(code);
|
732
|
-
});
|
733
|
-
test('multi nested namespace package with submodule from import', () => {
|
734
|
-
const code = `
|
735
|
-
// @filename: nested/nested2/nested3/module.py
|
736
|
-
//// def foo(): pass
|
737
|
-
|
738
|
-
// @filename: test1.py
|
739
|
-
//// from nested.nested2.nested3 import module
|
740
|
-
////
|
741
|
-
//// [|/*src*/module.foo()|]
|
742
|
-
|
743
|
-
// @filename: test2.py
|
744
|
-
//// [|/*dest*/{|"r":"from nested.nested2.nested3 import module!n!!n!!n!"|}|]
|
745
|
-
`;
|
746
|
-
testImportMove(code);
|
747
|
-
});
|
748
|
-
test('multi nested namespace package with __init__ from import', () => {
|
749
|
-
const code = `
|
750
|
-
// @filename: nested/nested2/nested3/__init__.py
|
751
|
-
//// def foo(): pass
|
752
|
-
|
753
|
-
// @filename: test1.py
|
754
|
-
//// from nested.nested2.nested3 import foo
|
755
|
-
////
|
756
|
-
//// [|/*src*/foo()|]
|
757
|
-
|
758
|
-
// @filename: test2.py
|
759
|
-
//// [|/*dest*/{|"r":"from nested.nested2.nested3 import foo!n!!n!!n!"|}|]
|
760
|
-
`;
|
761
|
-
testImportMove(code);
|
762
|
-
});
|
763
|
-
test('namespace package with relative path to root - from import', () => {
|
764
|
-
const code = `
|
765
|
-
// @filename: module.py
|
766
|
-
//// def foo(): pass
|
767
|
-
|
768
|
-
// @filename: test1.py
|
769
|
-
//// from . import module
|
770
|
-
////
|
771
|
-
//// [|/*src*/module.foo()|]
|
772
|
-
|
773
|
-
// @filename: test2.py
|
774
|
-
//// [|/*dest*/{|"r":"from . import module!n!!n!!n!"|}|]
|
775
|
-
`;
|
776
|
-
testImportMove(code);
|
777
|
-
});
|
778
|
-
test('namespace package with relative path from import', () => {
|
779
|
-
const code = `
|
780
|
-
// @filename: nested/module.py
|
781
|
-
//// def foo(): pass
|
782
|
-
|
783
|
-
// @filename: test1.py
|
784
|
-
//// from .nested import module
|
785
|
-
////
|
786
|
-
//// [|/*src*/module.foo()|]
|
787
|
-
|
788
|
-
// @filename: test2.py
|
789
|
-
//// [|/*dest*/{|"r":"from nested import module!n!!n!!n!"|}|]
|
790
|
-
`;
|
791
|
-
testImportMove(code);
|
792
|
-
});
|
793
|
-
test('namespace package import', () => {
|
794
|
-
const code = `
|
795
|
-
// @filename: nested/module.py
|
796
|
-
//// def foo(): pass
|
797
|
-
|
798
|
-
// @filename: test1.py
|
799
|
-
//// import nested.module
|
800
|
-
////
|
801
|
-
//// [|/*src*/nested.module.foo()|]
|
802
|
-
|
803
|
-
// @filename: test2.py
|
804
|
-
//// [|/*dest*/{|"r":"import nested.module!n!!n!!n!"|}|]
|
805
|
-
`;
|
806
|
-
testImportMove(code);
|
807
|
-
});
|
808
|
-
test('__init__ at root', () => {
|
809
|
-
const code = `
|
810
|
-
// @filename: __init__.py
|
811
|
-
//// def foo(): pass
|
812
|
-
|
813
|
-
// @filename: test1.py
|
814
|
-
//// from . import foo
|
815
|
-
////
|
816
|
-
//// [|/*src*/foo()|]
|
817
|
-
|
818
|
-
// @filename: test2.py
|
819
|
-
//// [|/*dest*/{|"r":"from . import foo!n!!n!!n!"|}|]
|
820
|
-
`;
|
821
|
-
testImportMove(code);
|
822
|
-
});
|
823
|
-
test('__init__ at root to nested file', () => {
|
824
|
-
const code = `
|
825
|
-
// @filename: __init__.py
|
826
|
-
//// def foo(): pass
|
827
|
-
|
828
|
-
// @filename: test1.py
|
829
|
-
//// from . import foo
|
830
|
-
////
|
831
|
-
//// [|/*src*/foo()|]
|
832
|
-
|
833
|
-
// @filename: nested/test2.py
|
834
|
-
//// [|/*dest*/{|"r":"from .. import foo!n!!n!!n!"|}|]
|
835
|
-
`;
|
836
|
-
testImportMove(code);
|
837
|
-
});
|
838
|
-
test('move wild card imports', () => {
|
839
|
-
const code = `
|
840
|
-
// @filename: module.py
|
841
|
-
//// def foo(): pass
|
842
|
-
//// __all__ = [ 'foo' ]
|
843
|
-
|
844
|
-
// @filename: test1.py
|
845
|
-
//// from module import *
|
846
|
-
////
|
847
|
-
//// [|/*src*/foo()|]
|
848
|
-
|
849
|
-
// @filename: nested/test2.py
|
850
|
-
//// [|/*dest*/{|"r":"from module import foo!n!!n!!n!"|}|]
|
851
|
-
`;
|
852
|
-
testImportMove(code);
|
853
|
-
});
|
854
|
-
test('move wild card imports from __init__', () => {
|
855
|
-
const code = `
|
856
|
-
// @filename: nested/__init__.py
|
857
|
-
//// def foo(): pass
|
858
|
-
//// __all__ = [ 'foo' ]
|
859
|
-
|
860
|
-
// @filename: test1.py
|
861
|
-
//// from nested import *
|
862
|
-
////
|
863
|
-
//// [|/*src*/foo()|]
|
864
|
-
|
865
|
-
// @filename: nested/test2.py
|
866
|
-
//// [|/*dest*/{|"r":"from nested import foo!n!!n!!n!"|}|]
|
867
|
-
`;
|
868
|
-
testImportMove(code);
|
869
|
-
});
|
870
|
-
test('merge with existing import', () => {
|
871
|
-
const code = `
|
872
|
-
// @filename: test1.py
|
873
|
-
//// val1 = 1
|
874
|
-
//// val2 = 2
|
875
|
-
//// [|/*src*/a = val2|]
|
876
|
-
|
877
|
-
// @filename: test2.py
|
878
|
-
//// from test1 import val1[|/*dest*/{|"r":", val2"|}|]
|
879
|
-
`;
|
880
|
-
testImportMove(code);
|
881
|
-
});
|
882
|
-
test('merge multiple symbols with existing import', () => {
|
883
|
-
const code = `
|
884
|
-
// @filename: test1.py
|
885
|
-
//// val1 = 1
|
886
|
-
//// val2 = 2
|
887
|
-
//// val3 = 3
|
888
|
-
//// [|/*src*/a = val2
|
889
|
-
//// b = val3|]
|
890
|
-
|
891
|
-
// @filename: test2.py
|
892
|
-
//// from test1 import val1[|/*dest*/{|"r":", val2, val3"|}|]
|
893
|
-
`;
|
894
|
-
testImportMove(code);
|
895
|
-
});
|
896
|
-
test('move with existing import with wild card', () => {
|
897
|
-
const code = `
|
898
|
-
// @filename: test1.py
|
899
|
-
//// val1 = 1
|
900
|
-
//// val2 = 2
|
901
|
-
//// [|/*src*/a = val2|]
|
902
|
-
|
903
|
-
// @filename: test2.py
|
904
|
-
//// from test1 import *[|/*dest*/{|"r":"!n!from test1 import val2"|}|]
|
905
|
-
`;
|
906
|
-
testImportMove(code);
|
907
|
-
});
|
908
|
-
test('merge multiple symbols with multiple existing import and wildcard', () => {
|
909
|
-
const code = `
|
910
|
-
// @filename: test1.py
|
911
|
-
//// val1 = 1
|
912
|
-
//// val2 = 2
|
913
|
-
//// val3 = 3
|
914
|
-
//// [|/*src*/a = val2
|
915
|
-
//// b = val3|]
|
916
|
-
|
917
|
-
// @filename: test2.py
|
918
|
-
//// from test1 import *
|
919
|
-
//// from test1 import val1[|/*dest*/{|"r":", val2, val3"|}|]
|
920
|
-
`;
|
921
|
-
testImportMove(code);
|
922
|
-
});
|
923
|
-
test('merge multiple symbols with multiple existing import', () => {
|
924
|
-
const code = `
|
925
|
-
// @filename: test1.py
|
926
|
-
//// val1 = 1
|
927
|
-
//// val2 = 2
|
928
|
-
//// val3 = 3
|
929
|
-
//// [|/*src*/a = val2
|
930
|
-
//// b = val3|]
|
931
|
-
|
932
|
-
// @filename: test2.py
|
933
|
-
//// from test1 import val1[|{|"r":", val3"|}|]
|
934
|
-
//// from test1 import val2[|/*dest*/|]
|
935
|
-
`;
|
936
|
-
testImportMove(code);
|
937
|
-
});
|
938
|
-
test('merge multiple symbols with multiple existing import with alias', () => {
|
939
|
-
const code = `
|
940
|
-
// @filename: test1.py
|
941
|
-
//// val1 = 1
|
942
|
-
//// val2 = 2
|
943
|
-
//// val3 = 3
|
944
|
-
//// [|/*src*/a = val2
|
945
|
-
//// b = val3|]
|
946
|
-
|
947
|
-
// @filename: test2.py
|
948
|
-
//// from test1 import val1[|{|"r":", val2, val3"|}|]
|
949
|
-
//// from test1 import val2 as v[|/*dest*/|]
|
950
|
-
`;
|
951
|
-
testImportMove(code);
|
952
|
-
});
|
953
|
-
test('skip with existing import statement', () => {
|
954
|
-
const code = `
|
955
|
-
// @filename: module.py
|
956
|
-
//// val1 = 1
|
957
|
-
//// val2 = 3
|
958
|
-
|
959
|
-
// @filename: test1.py
|
960
|
-
//// import module
|
961
|
-
////
|
962
|
-
//// [|/*src*/a = module.val1|]
|
963
|
-
|
964
|
-
// @filename: test2.py
|
965
|
-
//// import module
|
966
|
-
//// module.val2[|/*dest*/|]
|
967
|
-
`;
|
968
|
-
testImportMove(code);
|
969
|
-
});
|
970
|
-
test('skip with existing import statement with alias', () => {
|
971
|
-
const code = `
|
972
|
-
// @filename: module.py
|
973
|
-
//// val1 = 1
|
974
|
-
//// val2 = 3
|
975
|
-
|
976
|
-
// @filename: test1.py
|
977
|
-
//// import module as m
|
978
|
-
////
|
979
|
-
//// [|/*src*/a = m.val1|]
|
980
|
-
|
981
|
-
// @filename: test2.py
|
982
|
-
//// import module as m
|
983
|
-
//// m.val2[|/*dest*/|]
|
984
|
-
`;
|
985
|
-
testImportMove(code);
|
986
|
-
});
|
987
|
-
test('merge with existing import statement with alias', () => {
|
988
|
-
const code = `
|
989
|
-
// @filename: module.py
|
990
|
-
//// val1 = 1
|
991
|
-
//// val2 = 3
|
992
|
-
|
993
|
-
// @filename: test1.py
|
994
|
-
//// import module
|
995
|
-
////
|
996
|
-
//// [|/*src*/a = module.val1|]
|
997
|
-
|
998
|
-
// @filename: test2.py
|
999
|
-
//// import module as m[|{|"r":"!n!import module"|}|]
|
1000
|
-
//// m.val2[|/*dest*/|]
|
1001
|
-
`;
|
1002
|
-
testImportMove(code);
|
1003
|
-
});
|
1004
|
-
test('merge with existing import statement with alias 2', () => {
|
1005
|
-
const code = `
|
1006
|
-
// @filename: module.py
|
1007
|
-
//// val1 = 1
|
1008
|
-
//// val2 = 3
|
1009
|
-
|
1010
|
-
// @filename: test1.py
|
1011
|
-
//// import module as m
|
1012
|
-
////
|
1013
|
-
//// [|/*src*/a = m.val1|]
|
1014
|
-
|
1015
|
-
// @filename: test2.py
|
1016
|
-
//// import module[|{|"r":"!n!import module as m"|}|]
|
1017
|
-
//// module.val2[|/*dest*/|]
|
1018
|
-
`;
|
1019
|
-
testImportMove(code);
|
1020
|
-
});
|
1021
|
-
test('mixed with submodule and import - duplicated import', () => {
|
1022
|
-
const code = `
|
1023
|
-
// @filename: module.py
|
1024
|
-
//// val1 = 1
|
1025
|
-
//// val2 = 3
|
1026
|
-
|
1027
|
-
// @filename: test1.py
|
1028
|
-
//// import module
|
1029
|
-
////
|
1030
|
-
//// [|/*src*/a = module.val1|]
|
1031
|
-
|
1032
|
-
// @filename: test2.py
|
1033
|
-
//// [|{|"r":"import module!n!"|}|]from . import module
|
1034
|
-
//// module.val2[|/*dest*/|]
|
1035
|
-
`;
|
1036
|
-
testImportMove(code);
|
1037
|
-
});
|
1038
|
-
test('mixed with submodule and import - duplicated import 2', () => {
|
1039
|
-
const code = `
|
1040
|
-
// @filename: module.py
|
1041
|
-
//// val1 = 1
|
1042
|
-
//// val2 = 3
|
1043
|
-
|
1044
|
-
// @filename: test1.py
|
1045
|
-
//// from . import module
|
1046
|
-
////
|
1047
|
-
//// [|/*src*/a = module.val1|]
|
1048
|
-
|
1049
|
-
// @filename: test2.py
|
1050
|
-
//// [|{|"r":"from . import module!n!"|}|]import module
|
1051
|
-
//// module.val2[|/*dest*/|]
|
1052
|
-
`;
|
1053
|
-
testImportMove(code);
|
1054
|
-
});
|
1055
|
-
test('multiple mixed import statements', () => {
|
1056
|
-
const code = `
|
1057
|
-
// @filename: test1.py
|
1058
|
-
//// import typing
|
1059
|
-
//// from os import path
|
1060
|
-
//// import json.encoder as j
|
1061
|
-
//// import json.decoder
|
1062
|
-
////
|
1063
|
-
//// [|/*src*/def foo(p1: str, p2: typing.Any, p3: typing.Union[int, str]):
|
1064
|
-
//// b = path.join(p1)
|
1065
|
-
//// e = j.JSONEncoder(skipkeys=True)
|
1066
|
-
//// d = json.decoder.JSONDecoder()|]
|
1067
|
-
// @filename: test2.py
|
1068
|
-
//// [|{|"r":"import json.decoder!n!import json.encoder as j!n!"|}|]import os[|{|"r":"!n!from os import path"|}|]
|
1069
|
-
//// import sys
|
1070
|
-
//// import typing
|
1071
|
-
//// from json import decoder[|/*dest*/|]
|
1072
|
-
`;
|
1073
|
-
testImportMove(code);
|
1074
|
-
});
|
1075
|
-
test('multiple mixed import statements with merge', () => {
|
1076
|
-
const code = `
|
1077
|
-
// @filename: test1.py
|
1078
|
-
//// import typing
|
1079
|
-
//// from os import path
|
1080
|
-
//// from json import encoder as j
|
1081
|
-
//// from json import decoder
|
1082
|
-
////
|
1083
|
-
//// [|/*src*/def foo(p1: str, p2: typing.Any, p3: typing.Union[int, str]):
|
1084
|
-
//// b = path.join(p1)
|
1085
|
-
//// e = j.JSONEncoder(skipkeys=True)
|
1086
|
-
//// d = decoder.JSONDecoder()|]
|
1087
|
-
// @filename: test2.py
|
1088
|
-
//// import sys
|
1089
|
-
//// import typing
|
1090
|
-
//// from os import abort[|{|"r":", path"|}|]
|
1091
|
-
//// from json import decoder[|{|"r":", encoder as j"|}|][|/*dest*/|]
|
1092
|
-
`;
|
1093
|
-
testImportMove(code);
|
1094
|
-
});
|
1095
|
-
test('move into the same file import statement', () => {
|
1096
|
-
const code = `
|
1097
|
-
// @filename: test1.py
|
1098
|
-
//// import test2
|
1099
|
-
////
|
1100
|
-
//// [|/*src*/test2.foo()|]
|
1101
|
-
|
1102
|
-
// @filename: test2.py
|
1103
|
-
//// [|{|"r":"import test2!n!!n!!n!"|}|]def foo(): pass
|
1104
|
-
//// [|/*dest*/|]
|
1105
|
-
`;
|
1106
|
-
testImportMove(code);
|
1107
|
-
});
|
1108
|
-
test('move into the same file from import statement', () => {
|
1109
|
-
const code = `
|
1110
|
-
// @filename: test1.py
|
1111
|
-
//// from test2 import foo
|
1112
|
-
////
|
1113
|
-
//// [|/*src*/foo()|]
|
1114
|
-
|
1115
|
-
// @filename: test2.py
|
1116
|
-
//// def foo(): pass
|
1117
|
-
//// [|/*dest*/|]
|
1118
|
-
`;
|
1119
|
-
testImportMove(code);
|
1120
|
-
});
|
1121
|
-
test('move into the same file from import statement with alias', () => {
|
1122
|
-
const code = `
|
1123
|
-
// @filename: test1.py
|
1124
|
-
//// from test2 import foo as f
|
1125
|
-
////
|
1126
|
-
//// [|/*src*/f()|]
|
1127
|
-
|
1128
|
-
// @filename: test2.py
|
1129
|
-
//// [|{|"r":"from test2 import foo as f!n!!n!!n!"|}|]def foo(): pass
|
1130
|
-
//// [|/*dest*/|]
|
1131
|
-
`;
|
1132
|
-
testImportMove(code);
|
1133
|
-
});
|
1134
|
-
test('move into the same file from import statement for __init__', () => {
|
1135
|
-
const code = `
|
1136
|
-
// @filename: test1.py
|
1137
|
-
//// from nested import foo
|
1138
|
-
////
|
1139
|
-
//// [|/*src*/foo()|]
|
1140
|
-
|
1141
|
-
// @filename: nested/__init__.py
|
1142
|
-
//// def foo(): pass
|
1143
|
-
//// [|/*dest*/|]
|
1144
|
-
`;
|
1145
|
-
testImportMove(code);
|
1146
|
-
});
|
1147
|
-
test('move into the same file from import statement for __init__ with alias', () => {
|
1148
|
-
const code = `
|
1149
|
-
// @filename: test1.py
|
1150
|
-
//// from nested import foo as f
|
1151
|
-
////
|
1152
|
-
//// [|/*src*/f()|]
|
1153
|
-
|
1154
|
-
// @filename: nested/__init__.py
|
1155
|
-
//// [|{|"r":"from nested import foo as f!n!!n!!n!"|}|]def foo(): pass
|
1156
|
-
//// [|/*dest*/|]
|
1157
|
-
`;
|
1158
|
-
testImportMove(code);
|
1159
|
-
});
|
1160
|
-
test('move into the same file from import statement for submodule', () => {
|
1161
|
-
const code = `
|
1162
|
-
// @filename: test1.py
|
1163
|
-
//// from nested import module
|
1164
|
-
////
|
1165
|
-
//// [|/*src*/module.foo()|]
|
1166
|
-
|
1167
|
-
// @filename: nested/__init__.py
|
1168
|
-
//// [|{|"r":"from nested import module!n!!n!!n!"|}|][|/*dest*/|]
|
1169
|
-
|
1170
|
-
// @filename: nested/module.py
|
1171
|
-
//// def foo(): pass
|
1172
|
-
`;
|
1173
|
-
testImportMove(code);
|
1174
|
-
});
|
1175
|
-
test('use relative import format', () => {
|
1176
|
-
const code = `
|
1177
|
-
// @filename: test1.py
|
1178
|
-
//// from nested import module
|
1179
|
-
////
|
1180
|
-
//// [|/*src*/module.foo()|]
|
1181
|
-
|
1182
|
-
// @filename: nested/__init__.py
|
1183
|
-
//// [|{|"r":"from . import module!n!!n!!n!"|}|][|/*dest*/|]
|
1184
|
-
|
1185
|
-
// @filename: nested/module.py
|
1186
|
-
//// def foo(): pass
|
1187
|
-
`;
|
1188
|
-
testImportMove(code, "relative" /* Relative */);
|
1189
|
-
});
|
1190
|
-
test('use relative import format - textEditTracker', () => {
|
1191
|
-
const code = `
|
1192
|
-
// @filename: test1.py
|
1193
|
-
//// from nested import module
|
1194
|
-
////
|
1195
|
-
//// [|/*src*/module.foo()|]
|
1196
|
-
|
1197
|
-
// @filename: nested/__init__.py
|
1198
|
-
//// [|{|"r":"from . import module!n!!n!!n!"|}|][|/*dest*/|]
|
1199
|
-
|
1200
|
-
// @filename: nested/module.py
|
1201
|
-
//// def foo(): pass
|
1202
|
-
`;
|
1203
|
-
testImportMoveWithTracker(code, "relative" /* Relative */);
|
1204
|
-
});
|
1205
|
-
test('dont include token not contained in the span', () => {
|
1206
|
-
const code = `
|
1207
|
-
// @filename: test1.py
|
1208
|
-
//// import random
|
1209
|
-
////
|
1210
|
-
//// [|/*src*/answer_word = random.choice(["a","b","c","d"])
|
1211
|
-
//// |]guess_word = "c"
|
1212
|
-
|
1213
|
-
// @filename: nested/__init__.py
|
1214
|
-
//// [|{|"r":"import random!n!!n!!n!"|}|][|/*dest*/|]
|
1215
|
-
`;
|
1216
|
-
testImportMove(code, "absolute" /* Absolute */);
|
1217
|
-
});
|
1218
|
-
test('multiple ranges', () => {
|
1219
|
-
const code = `
|
1220
|
-
// @filename: test1.py
|
1221
|
-
//// class A:
|
1222
|
-
//// pass
|
1223
|
-
////
|
1224
|
-
//// class B:
|
1225
|
-
//// pass
|
1226
|
-
////
|
1227
|
-
//// class N:
|
1228
|
-
//// pass
|
1229
|
-
////
|
1230
|
-
//// a = [|/*src*/A()|]
|
1231
|
-
//// n = N()
|
1232
|
-
//// b = [|B()|]
|
1233
|
-
|
1234
|
-
// @filename: nested/__init__.py
|
1235
|
-
//// [|{|"r":"from test1 import A, B!n!!n!!n!"|}|][|/*dest*/|]
|
1236
|
-
`;
|
1237
|
-
testImportMove(code, "absolute" /* Absolute */);
|
1238
|
-
});
|
1239
|
-
test('adding decl manually', () => {
|
1240
|
-
var _a;
|
1241
|
-
const code = `
|
1242
|
-
// @filename: test1.py
|
1243
|
-
//// class A:
|
1244
|
-
//// pass
|
1245
|
-
////
|
1246
|
-
//// a = [|/*src*/A|]()
|
1247
|
-
|
1248
|
-
// @filename: test2.py
|
1249
|
-
//// [|{|"r":"from test1 import A!n!!n!!n!"|}|][|/*dest*/|]
|
1250
|
-
`;
|
1251
|
-
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
1252
|
-
const src = state.getMarkerByName('src');
|
1253
|
-
const dest = state.getMarkerByName('dest');
|
1254
|
-
const parseResults = state.workspace.service.test_program.getBoundSourceFile(src.fileName).getParseResults();
|
1255
|
-
const node = (0, parseTreeUtils_1.findNodeByOffset)(parseResults.parseTree, src.position);
|
1256
|
-
const decl = (_a = state.workspace.service.test_program.evaluator) === null || _a === void 0 ? void 0 : _a.getDeclarationsForNameNode(node)[0];
|
1257
|
-
const importAdder = new importAdder_1.ImportAdder(state.configOptions, state.importResolver, state.program.evaluator);
|
1258
|
-
const importData = { containsUnreferenceableSymbols: false, declarations: new Map() };
|
1259
|
-
importAdder.addDeclaration(decl, node, importData);
|
1260
|
-
const edits = importAdder.applyImports(importData, dest.fileName, state.program.getBoundSourceFile(dest.fileName).getParseResults(), dest.position, "absolute" /* Absolute */, vscode_languageserver_1.CancellationToken.None);
|
1261
|
-
verifyEdits(edits, state);
|
1262
|
-
});
|
1263
|
-
test('adding import info manually', () => {
|
1264
|
-
const code = `
|
1265
|
-
// @filename: test1.py
|
1266
|
-
//// class [|/*src*/A|]:
|
1267
|
-
//// pass
|
1268
|
-
|
1269
|
-
// @filename: test2.py
|
1270
|
-
//// [|{|"r":"from test1 import A!n!!n!!n!"|}|][|/*dest*/|]
|
1271
|
-
`;
|
1272
|
-
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
1273
|
-
const src = state.getMarkerByName('src');
|
1274
|
-
const dest = state.getMarkerByName('dest');
|
1275
|
-
const importAdder = new importAdder_1.ImportAdder(state.configOptions, state.importResolver, state.program.evaluator);
|
1276
|
-
const importData = { containsUnreferenceableSymbols: false, declarations: new Map() };
|
1277
|
-
importAdder.addImportInfo({ filePath: src.fileName, nameInfo: { name: 'A' } }, importData);
|
1278
|
-
const edits = importAdder.applyImports(importData, dest.fileName, state.program.getBoundSourceFile(dest.fileName).getParseResults(), dest.position, "absolute" /* Absolute */, vscode_languageserver_1.CancellationToken.None);
|
1279
|
-
verifyEdits(edits, state);
|
1280
|
-
});
|
1281
|
-
function testImportMoveWithTracker(code, importFormat = "absolute" /* Absolute */) {
|
1282
|
-
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
1283
|
-
const src = state.getRangeByMarkerName('src');
|
1284
|
-
const dest = state.getMarkerByName('dest');
|
1285
|
-
const importMover = new importAdder_1.ImportAdder(state.configOptions, state.importResolver, state.program.evaluator);
|
1286
|
-
const importData = importMover.collectImportsForSymbolsUsed(state.program.getBoundSourceFile(src.fileName).getParseResults(), textRange_1.TextRange.fromBounds(src.pos, src.end), vscode_languageserver_1.CancellationToken.None);
|
1287
|
-
const tracker = new textEditTracker_1.TextEditTracker();
|
1288
|
-
importMover.applyImportsTo(importData, state.program.getBoundSourceFile(dest.fileName).getParseResults(), importFormat, tracker, vscode_languageserver_1.CancellationToken.None);
|
1289
|
-
verifyEdits(tracker.getEdits(vscode_languageserver_1.CancellationToken.None), state);
|
1290
|
-
}
|
1291
|
-
function testImportMove(code, importFormat = "absolute" /* Absolute */) {
|
1292
|
-
const state = (0, testState_1.parseAndGetTestState)(code).state;
|
1293
|
-
const src = state.getRangeByMarkerName('src');
|
1294
|
-
const dest = state.getMarkerByName('dest');
|
1295
|
-
const ranges = state
|
1296
|
-
.getRanges()
|
1297
|
-
.filter((r) => r.fileName === src.fileName)
|
1298
|
-
.map((r) => textRange_1.TextRange.fromBounds(r.pos, r.end));
|
1299
|
-
const importMover = new importAdder_1.ImportAdder(state.configOptions, state.importResolver, state.program.evaluator);
|
1300
|
-
const importData = importMover.collectImportsForSymbolsUsed(state.program.getBoundSourceFile(src.fileName).getParseResults(), ranges.length === 1 ? ranges[0] : ranges, vscode_languageserver_1.CancellationToken.None);
|
1301
|
-
const edits = importMover.applyImports(importData, dest.fileName, state.program.getBoundSourceFile(dest.fileName).getParseResults(), dest.position, importFormat, vscode_languageserver_1.CancellationToken.None);
|
1302
|
-
verifyEdits(edits, state);
|
1303
|
-
}
|
1304
|
-
function verifyEdits(edits, state) {
|
1305
|
-
(0, assert_1.default)(edits);
|
1306
|
-
const filePath = state.getMarkerByName('dest').fileName;
|
1307
|
-
const ranges = state.getRanges().filter((r) => { var _a; return !!((_a = r.marker) === null || _a === void 0 ? void 0 : _a.data); });
|
1308
|
-
assert_1.default.strictEqual(edits.length, ranges.length, `${edits.map((e) => (0, testStateUtils_1.convertFileEditActionToString)({ filePath, ...e })).join('|')} vs ${ranges
|
1309
|
-
.map((r) => (0, testStateUtils_1.convertRangeToFileEditAction)(state, r))
|
1310
|
-
.map((e) => (0, testStateUtils_1.convertFileEditActionToString)(e))
|
1311
|
-
.join('|')}`);
|
1312
|
-
for (const edit of edits) {
|
1313
|
-
(0, assert_1.default)(ranges.some((r) => {
|
1314
|
-
const data = r.marker.data;
|
1315
|
-
const expectedText = data.r;
|
1316
|
-
const expectedRange = state.convertPositionRange(r);
|
1317
|
-
return ((0, textRange_1.rangesAreEqual)(expectedRange, edit.range) &&
|
1318
|
-
expectedText.replace(/!n!/g, '\n') === edit.replacementText);
|
1319
|
-
}), `can't find ${(0, testStateUtils_1.convertFileEditActionToString)({ filePath, ...edit })} in ${ranges
|
1320
|
-
.map((r) => (0, testStateUtils_1.convertRangeToFileEditAction)(state, r))
|
1321
|
-
.map((e) => (0, testStateUtils_1.convertFileEditActionToString)(e))
|
1322
|
-
.join('|')}`);
|
1323
|
-
}
|
1324
|
-
}
|
1325
|
-
//# sourceMappingURL=importAdder.test.js.map
|