Skip to content

Commit

Permalink
fix: add configuration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Jan 30, 2019
1 parent 04de9ea commit f5855ba
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/configuration/remapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class Remapper implements IRemapper {
const userDefinedRemappings = configuration[this._configKey] as Map<string, IKeyRemapping>;

this._logger.debug(
`find matching remap. keys=${keys}. mode=${ModeName[vimState.currentMode]}. keybindings=${
this._configKey
}.`
`trying to find matching remap. keys=${keys}. mode=${
ModeName[vimState.currentMode]
}. keybindings=${this._configKey}.`
);
let remapping: IKeyRemapping | undefined = Remapper.findMatchingRemap(
userDefinedRemappings,
Expand Down Expand Up @@ -113,7 +113,7 @@ export class Remapper implements IRemapper {
}

// Check to see if a remapping could potentially be applied when more keys are received
for (let remap of Object.keys(userDefinedRemappings)) {
for (let remap of userDefinedRemappings.keys()) {
if (keys.join('') === remap.slice(0, keys.length)) {
this._isPotentialRemap = true;
break;
Expand Down
7 changes: 3 additions & 4 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,19 @@ export class ModeHandler implements vscode.Disposable {
}

private async handleKeyEventHelper(key: string, vimState: VimState): Promise<VimState> {
// Just nope right out of here.
if (vscode.window.activeTextEditor !== this.vimState.editor) {
this._logger.warn('Current window is not active');
return this.vimState;
}

// Catch any text change not triggered by us (example: tab completion).
vimState.historyTracker.addChange(this.vimState.cursorPositionJustBeforeAnythingHappened);

let recordedState = vimState.recordedState;
vimState.keyHistory.push(key);

let recordedState = vimState.recordedState;
recordedState.actionKeys.push(key);

vimState.keyHistory.push(key);

let result = Actions.getRelevantAction(recordedState.actionKeys, vimState);
switch (result) {
case KeypressState.NoPossibleMatch:
Expand Down
4 changes: 2 additions & 2 deletions test/cmd_line/substitute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ suite('Basic substitute', () => {
});

suite('Effects of substituteGlobalFlag=true', () => {
setup(() => {
setup(async () => {
Globals.mockConfiguration.substituteGlobalFlag = true;
reloadConfiguration();
await reloadConfiguration();
});

test('Replace all matches in the line', async () => {
Expand Down
44 changes: 37 additions & 7 deletions test/configuration/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as assert from 'assert';

import * as srcConfiguration from '../../src/configuration/configuration';
import * as testConfiguration from '../testConfiguration';
import { cleanUpWorkspace, setupWorkspace } from './../testUtils';
Expand All @@ -20,6 +19,23 @@ suite('Configuration', () => {
after: ['v'],
},
];
(configuration.visualModeKeyBindingsNonRecursive = [
// duplicate keybindings
{
before: ['c', 'o', 'p', 'y'],
after: ['c', 'o', 'p', 'y'],
},
{
before: ['c', 'o', 'p', 'y'],
after: ['c', 'o', 'p', 'y'],
},
]),
(configuration.insertModeKeyBindingsNonRecursive = [
{
// missing after and command
before: ['a'],
},
]);
configuration.whichwrap = 'h,l';

setup(async () => {
Expand All @@ -30,19 +46,24 @@ suite('Configuration', () => {

test('remappings are normalized', async () => {
const normalizedKeybinds = srcConfiguration.configuration.normalModeKeyBindingsNonRecursive;
const normalizedKeybindsMap =
srcConfiguration.configuration.normalModeKeyBindingsNonRecursiveMap;
const testingKeybinds = configuration.normalModeKeyBindingsNonRecursive;

assert.equal(normalizedKeybinds.length, testingKeybinds.length);
assert.equal(normalizedKeybinds.length, normalizedKeybindsMap.size);
assert.deepEqual(normalizedKeybinds[0].before, [' ', 'o']);
assert.deepEqual(normalizedKeybinds[0].after, ['o', '<Esc>', 'k']);
});

newTest({
title: 'Can handle long key chords',
start: ['|'],
keysPressed: ' fes',
end: ['|'],
endMode: ModeName.Visual,
test('remappings are de-duped', async () => {
const keybindings = srcConfiguration.configuration.visualModeKeyBindingsNonRecursiveMap;
assert.equal(keybindings.size, 1);
});

test('invalid remappings are ignored', async () => {
const keybindings = srcConfiguration.configuration.insertModeKeyBindingsNonRecursiveMap;
assert.equal(keybindings.size, 0);
});

test('whichwrap is parsed into wrapKeys', async () => {
Expand All @@ -54,4 +75,13 @@ suite('Configuration', () => {
assert.equal(wrapKeys[h], true);
assert.equal(wrapKeys[j], undefined);
});

newTest({
title: 'Can handle long key chords',
start: ['|'],
// <leader>fes
keysPressed: ' fes',
end: ['|'],
endMode: ModeName.Visual,
});
});
4 changes: 2 additions & 2 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ suite('Mode Visual', () => {
});

suite('visualstar', () => {
setup(() => {
setup(async () => {
Globals.mockConfiguration.visualstar = true;
reloadConfiguration();
await reloadConfiguration();
});

newTest({
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/sneak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ suite('sneak plugin', () => {
setup(async () => {
await setupWorkspace();
Globals.mockConfiguration.sneak = true;
reloadConfiguration();
await reloadConfiguration();
});

teardown(cleanUpWorkspace);
Expand Down
6 changes: 3 additions & 3 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function setupWorkspace(
await vscode.window.showTextDocument(doc);

Globals.mockConfiguration = config;
reloadConfiguration();
await reloadConfiguration();

let activeTextEditor = vscode.window.activeTextEditor;
assert.ok(activeTextEditor);
Expand Down Expand Up @@ -134,8 +134,8 @@ export async function cleanUpWorkspace(): Promise<any> {
});
}

export function reloadConfiguration() {
require('../src/configuration/configuration').configuration.load();
export async function reloadConfiguration() {
await require('../src/configuration/configuration').configuration.load();
}

/**
Expand Down

0 comments on commit f5855ba

Please sign in to comment.