Skip to content

Commit f1e8d44

Browse files
committed
why no async
1 parent 33ec0ab commit f1e8d44

File tree

2 files changed

+62
-65
lines changed

2 files changed

+62
-65
lines changed

src/test/terminals/codeExecution/helper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { ReplType } from '../../../client/repl/types';
3838

3939
const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'python_files', 'terminalExec');
4040

41-
suite('Terminal - Code Execution Helper', () => {
41+
suite('Terminal - Code Execution Helper', async () => {
4242
let activeResourceService: TypeMoq.IMock<IActiveResourceService>;
4343
let documentManager: TypeMoq.IMock<IDocumentManager>;
4444
let applicationShell: TypeMoq.IMock<IApplicationShell>;

src/test/terminals/codeExecution/smartSend.test.ts

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -168,70 +168,67 @@ suite('REPL - Smart Send', async () => {
168168
commandManager.verifyAll();
169169
});
170170

171-
const pythonVersion = await getPythonSemVer();
172-
if (pythonVersion && pythonVersion.minor < 13) {
173-
test('Smart send should perform smart selection and move cursor', async () => {
174-
configurationService
175-
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
176-
.returns({
177-
REPL: {
178-
REPLSmartSend: true,
179-
},
180-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
181-
} as any);
182-
183-
const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
184-
const firstIndexPosition = new Position(0, 0);
185-
const selection = TypeMoq.Mock.ofType<Selection>();
186-
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');
187-
188-
selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
189-
selection.setup((s) => s.active).returns(() => firstIndexPosition);
190-
selection.setup((s) => s.isEmpty).returns(() => true);
191-
activeEditor.setup((e) => e.selection).returns(() => selection.object);
192-
193-
documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
194-
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
195-
const actualProcessService = new ProcessService();
196-
197-
const { execObservable } = actualProcessService;
198-
199-
processService
200-
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
201-
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));
202-
203-
const actualSmartOutput = await codeExecutionHelper.normalizeLines(
204-
'my_dict = {',
205-
ReplType.terminal,
206-
wholeFileContent,
207-
);
208-
209-
// my_dict = { <----- smart shift+enter here
210-
// "key1": "value1",
211-
// "key2": "value2"
212-
// } <---- cursor should be here afterwards, hence offset 3
213-
commandManager
214-
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
215-
.callback((_, arg2) => {
216-
assert.deepEqual(arg2, {
217-
to: 'down',
218-
by: 'line',
219-
value: 3,
220-
});
221-
return Promise.resolve();
222-
})
223-
.verifiable(TypeMoq.Times.once());
224-
225-
commandManager
226-
.setup((c) => c.executeCommand('cursorEnd'))
227-
.returns(() => Promise.resolve())
228-
.verifiable(TypeMoq.Times.once());
229-
230-
const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
231-
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
232-
commandManager.verifyAll();
233-
});
234-
}
171+
test('Smart send should perform smart selection and move cursor', async () => {
172+
configurationService
173+
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
174+
.returns({
175+
REPL: {
176+
REPLSmartSend: true,
177+
},
178+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
179+
} as any);
180+
181+
const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
182+
const firstIndexPosition = new Position(0, 0);
183+
const selection = TypeMoq.Mock.ofType<Selection>();
184+
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');
185+
186+
selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
187+
selection.setup((s) => s.active).returns(() => firstIndexPosition);
188+
selection.setup((s) => s.isEmpty).returns(() => true);
189+
activeEditor.setup((e) => e.selection).returns(() => selection.object);
190+
191+
documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
192+
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
193+
const actualProcessService = new ProcessService();
194+
195+
const { execObservable } = actualProcessService;
196+
197+
processService
198+
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
199+
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));
200+
201+
const actualSmartOutput = await codeExecutionHelper.normalizeLines(
202+
'my_dict = {',
203+
ReplType.terminal,
204+
wholeFileContent,
205+
);
206+
207+
// my_dict = { <----- smart shift+enter here
208+
// "key1": "value1",
209+
// "key2": "value2"
210+
// } <---- cursor should be here afterwards, hence offset 3
211+
commandManager
212+
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
213+
.callback((_, arg2) => {
214+
assert.deepEqual(arg2, {
215+
to: 'down',
216+
by: 'line',
217+
value: 3,
218+
});
219+
return Promise.resolve();
220+
})
221+
.verifiable(TypeMoq.Times.once());
222+
223+
commandManager
224+
.setup((c) => c.executeCommand('cursorEnd'))
225+
.returns(() => Promise.resolve())
226+
.verifiable(TypeMoq.Times.once());
227+
228+
const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
229+
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
230+
commandManager.verifyAll();
231+
});
235232

236233
// Do not perform smart selection when there is explicit selection
237234
test('Smart send should not perform smart selection when there is explicit selection', async () => {

0 commit comments

Comments
 (0)