Vim/test/plugins/imswitcher.test.ts

69 lines
2.5 KiB
TypeScript

import * as assert from 'assert';
import { Configuration } from '../testConfiguration';
import { setupWorkspace, cleanUpWorkspace } from '../testUtils';
import { InputMethodSwitcher } from '../../src/actions/plugins/imswitcher';
import { Mode } from '../../src/mode/mode';
suite('Input method plugin', () => {
let savedCmd = '';
function fakeExecuteChinese(cmd: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
if (cmd === 'im-select') {
resolve('chinese');
} else {
savedCmd = cmd;
resolve('');
}
});
}
function fakeExecuteDefault(cmd: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
if (cmd === 'im-select') {
resolve('default');
} else {
savedCmd = cmd;
resolve('');
}
});
}
setup(async () => {
const configuration = new Configuration();
configuration.autoSwitchInputMethod.enable = true;
configuration.autoSwitchInputMethod.defaultIM = 'default';
configuration.autoSwitchInputMethod.obtainIMCmd = 'im-select';
configuration.autoSwitchInputMethod.switchIMCmd = 'im-select {im}';
await setupWorkspace(configuration);
});
teardown(cleanUpWorkspace);
test('use default im in insert mode', async () => {
savedCmd = '';
const inputMethodSwitcher = new InputMethodSwitcher(fakeExecuteDefault);
await inputMethodSwitcher.switchInputMethod(Mode.Normal, Mode.Insert);
assert.strictEqual('', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Insert, Mode.Normal);
assert.strictEqual('', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Normal, Mode.Insert);
assert.strictEqual('', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Insert, Mode.Normal);
assert.strictEqual('', savedCmd);
});
test('use other im in insert mode', async () => {
savedCmd = '';
const inputMethodSwitcher = new InputMethodSwitcher(fakeExecuteChinese);
await inputMethodSwitcher.switchInputMethod(Mode.Normal, Mode.Insert);
assert.strictEqual('', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Insert, Mode.Normal);
assert.strictEqual('im-select default', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Normal, Mode.Insert);
assert.strictEqual('im-select chinese', savedCmd);
await inputMethodSwitcher.switchInputMethod(Mode.Insert, Mode.Normal);
assert.strictEqual('im-select default', savedCmd);
});
});