Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Feb 2, 2025
1 parent ec4a048 commit f2fbb9f
Showing 1 changed file with 67 additions and 62 deletions.
129 changes: 67 additions & 62 deletions src/test/terminals/codeExecution/smartSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
import { ICodeExecutionHelper } from '../../../client/terminals/types';
import { Commands, EXTENSION_ROOT_DIR } from '../../../client/common/constants';
import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info';
import { PYTHON_PATH } from '../../common';
import { PYTHON_PATH, getPythonSemVer } from '../../common';
import { Architecture } from '../../../client/common/utils/platform';
import { ProcessService } from '../../../client/common/process/proc';
import { l10n } from '../../mocks/vsc';
Expand Down Expand Up @@ -168,67 +168,72 @@ suite('REPL - Smart Send', async () => {
commandManager.verifyAll();
});

test('Smart send should perform smart selection and move cursor', async () => {
configurationService
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
.returns({
REPL: {
REPLSmartSend: true,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);

const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
const firstIndexPosition = new Position(0, 0);
const selection = TypeMoq.Mock.ofType<Selection>();
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');

selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
selection.setup((s) => s.active).returns(() => firstIndexPosition);
selection.setup((s) => s.isEmpty).returns(() => true);
activeEditor.setup((e) => e.selection).returns(() => selection.object);

documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
const actualProcessService = new ProcessService();

const { execObservable } = actualProcessService;

processService
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));

const actualSmartOutput = await codeExecutionHelper.normalizeLines(
'my_dict = {',
ReplType.terminal,
wholeFileContent,
);

// my_dict = { <----- smart shift+enter here
// "key1": "value1",
// "key2": "value2"
// } <---- cursor should be here afterwards, hence offset 3
commandManager
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
.callback((_, arg2) => {
assert.deepEqual(arg2, {
to: 'down',
by: 'line',
value: 3,
});
return Promise.resolve();
})
.verifiable(TypeMoq.Times.once());

commandManager
.setup((c) => c.executeCommand('cursorEnd'))
.returns(() => Promise.resolve())
.verifiable(TypeMoq.Times.once());

const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
commandManager.verifyAll();
});
const pythonVersion = await getPythonSemVer();
console.log('Just printed pythoNVersion: \n');
console.log(pythonVersion);
if (pythonVersion && pythonVersion.minor < 13) {
test('Smart send should perform smart selection and move cursor', async () => {
configurationService
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
.returns({
REPL: {
REPLSmartSend: true,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);

const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
const firstIndexPosition = new Position(0, 0);
const selection = TypeMoq.Mock.ofType<Selection>();
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');

selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
selection.setup((s) => s.active).returns(() => firstIndexPosition);
selection.setup((s) => s.isEmpty).returns(() => true);
activeEditor.setup((e) => e.selection).returns(() => selection.object);

documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
const actualProcessService = new ProcessService();

const { execObservable } = actualProcessService;

processService
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));

const actualSmartOutput = await codeExecutionHelper.normalizeLines(
'my_dict = {',
ReplType.terminal,
wholeFileContent,
);

// my_dict = { <----- smart shift+enter here
// "key1": "value1",
// "key2": "value2"
// } <---- cursor should be here afterwards, hence offset 3
commandManager
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
.callback((_, arg2) => {
assert.deepEqual(arg2, {
to: 'down',
by: 'line',
value: 3,
});
return Promise.resolve();
})
.verifiable(TypeMoq.Times.once());

commandManager
.setup((c) => c.executeCommand('cursorEnd'))
.returns(() => Promise.resolve())
.verifiable(TypeMoq.Times.once());

const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
commandManager.verifyAll();
});
}

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

0 comments on commit f2fbb9f

Please sign in to comment.