2016-06-14 00:51:40 +03:00
|
|
|
import * as assert from 'assert';
|
2016-09-13 05:55:29 +03:00
|
|
|
import * as vscode from 'vscode';
|
2017-12-11 16:05:43 +03:00
|
|
|
|
|
|
|
import { getAndUpdateModeHandler } from '../extension';
|
2017-12-12 14:07:31 +03:00
|
|
|
import { Globals } from '../src/globals';
|
2019-11-29 22:35:30 +03:00
|
|
|
import { Mode } from '../src/mode/mode';
|
2016-06-14 00:51:40 +03:00
|
|
|
import { ModeHandler } from '../src/mode/modeHandler';
|
|
|
|
import { TextEditor } from '../src/textEditor';
|
2020-07-06 05:00:46 +03:00
|
|
|
import { assertEqualLines, reloadConfiguration } from './testUtils';
|
2019-08-26 08:05:55 +03:00
|
|
|
import { globalState } from '../src/state/globalState';
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
import { IKeyRemapping } from '../src/configuration/iconfiguration';
|
|
|
|
import * as os from 'os';
|
|
|
|
import { VimrcImpl } from '../src/configuration/vimrc';
|
|
|
|
import { vimrcKeyRemappingBuilder } from '../src/configuration/vimrcKeyRemappingBuilder';
|
2020-07-06 05:00:46 +03:00
|
|
|
import { IConfiguration } from '../src/configuration/iconfiguration';
|
2020-11-14 05:48:12 +03:00
|
|
|
import { Position } from 'vscode';
|
2016-06-14 00:51:40 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
function getNiceStack(stack: string | undefined): string {
|
|
|
|
return stack ? stack.split('\n').splice(2, 1).join('\n') : 'no stack available :(';
|
|
|
|
}
|
2017-12-25 01:37:43 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
function newTestGeneric<T extends ITestObject | ITestWithRemapsObject>(
|
|
|
|
testObj: T,
|
|
|
|
testFunc: Mocha.TestFunction | Mocha.ExclusiveTestFunction | Mocha.PendingTestFunction,
|
|
|
|
innerTest: (modeHandler: ModeHandler, testObj: T) => Promise<void>
|
|
|
|
): void {
|
|
|
|
const stack = new Error().stack;
|
|
|
|
const niceStack = getNiceStack(stack);
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
testFunc(testObj.title, async () => {
|
|
|
|
const prevConfig = { ...Globals.mockConfiguration };
|
|
|
|
try {
|
|
|
|
if (testObj.config) {
|
|
|
|
for (const key in testObj.config) {
|
|
|
|
if (testObj.config.hasOwnProperty(key)) {
|
|
|
|
const value = testObj.config[key];
|
|
|
|
Globals.mockConfiguration[key] = value;
|
2020-07-06 05:00:46 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-16 21:37:55 +03:00
|
|
|
await reloadConfiguration();
|
2020-07-06 05:00:46 +03:00
|
|
|
}
|
2020-11-16 22:55:44 +03:00
|
|
|
const mh = (await getAndUpdateModeHandler())!;
|
2020-11-16 21:37:55 +03:00
|
|
|
await innerTest(mh, testObj);
|
|
|
|
} catch (reason) {
|
|
|
|
reason.stack = niceStack;
|
|
|
|
throw reason;
|
|
|
|
} finally {
|
|
|
|
if (testObj.config) {
|
|
|
|
Globals.mockConfiguration = prevConfig;
|
|
|
|
await reloadConfiguration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
export const newTest = (testObj: ITestObject) => newTestGeneric(testObj, test, testIt);
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
export const newTestOnly = (testObj: ITestObject) => {
|
|
|
|
console.warn('!!! Running single test !!!');
|
|
|
|
return newTestGeneric(testObj, test.only, testIt);
|
|
|
|
};
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
export const newTestSkip = (testObj: ITestObject) => newTestGeneric(testObj, test.skip, testIt);
|
2019-10-04 07:38:28 +03:00
|
|
|
|
2020-11-16 21:37:55 +03:00
|
|
|
export const newTestWithRemaps = (testObj: ITestWithRemapsObject) =>
|
|
|
|
newTestGeneric(testObj, test, testItWithRemaps);
|
|
|
|
export const newTestWithRemapsOnly = (testObj: ITestWithRemapsObject) => {
|
|
|
|
console.warn('!!! Running single test !!!');
|
|
|
|
return newTestGeneric(testObj, test.only, testItWithRemaps);
|
|
|
|
};
|
|
|
|
export const newTestWithRemapsSkip = (testObj: ITestWithRemapsObject) =>
|
|
|
|
newTestGeneric(testObj, test.skip, testItWithRemaps);
|
2016-06-14 00:51:40 +03:00
|
|
|
|
2016-06-18 11:11:27 +03:00
|
|
|
interface ITestObject {
|
2016-07-16 20:02:31 +03:00
|
|
|
title: string;
|
2020-07-06 05:00:46 +03:00
|
|
|
config?: Partial<IConfiguration>;
|
2016-07-16 20:02:31 +03:00
|
|
|
start: string[];
|
|
|
|
keysPressed: string;
|
|
|
|
end: string[];
|
2019-11-29 22:35:30 +03:00
|
|
|
endMode?: Mode;
|
2018-09-02 21:28:21 +03:00
|
|
|
jumps?: string[];
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
type Step = {
|
|
|
|
title?: string;
|
|
|
|
keysPressed: string;
|
|
|
|
stepResult: {
|
|
|
|
end: string[];
|
|
|
|
endAfterTimeout?: string[];
|
|
|
|
endMode?: Mode;
|
|
|
|
endModeAfterTimeout?: Mode;
|
|
|
|
jumps?: string[];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
interface ITestWithRemapsObject {
|
|
|
|
title: string;
|
|
|
|
config?: Partial<IConfiguration>;
|
|
|
|
start: string[];
|
|
|
|
remaps?:
|
|
|
|
| {
|
|
|
|
normalModeKeyBindings?: IKeyRemapping[];
|
|
|
|
normalModeKeyBindingsNonRecursive?: IKeyRemapping[];
|
|
|
|
insertModeKeyBindings?: IKeyRemapping[];
|
|
|
|
insertModeKeyBindingsNonRecursive?: IKeyRemapping[];
|
|
|
|
visualModeKeyBindings?: IKeyRemapping[];
|
|
|
|
visualModeKeyBindingsNonRecursive?: IKeyRemapping[];
|
|
|
|
operatorPendingModeKeyBindings?: IKeyRemapping[];
|
|
|
|
operatorPendingModeKeyBindingsNonRecursive?: IKeyRemapping[];
|
|
|
|
}
|
|
|
|
| string[];
|
|
|
|
steps: Step[];
|
|
|
|
}
|
|
|
|
|
2016-06-14 00:51:40 +03:00
|
|
|
class TestObjectHelper {
|
2016-09-13 05:55:29 +03:00
|
|
|
/**
|
|
|
|
* Position that the test says that the cursor starts at.
|
|
|
|
*/
|
2016-07-16 20:02:31 +03:00
|
|
|
startPosition = new Position(0, 0);
|
2016-09-13 05:55:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Position that the test says that the cursor ends at.
|
|
|
|
*/
|
2016-07-16 20:02:31 +03:00
|
|
|
endPosition = new Position(0, 0);
|
|
|
|
|
|
|
|
private _isValid = false;
|
|
|
|
private _testObject: ITestObject;
|
|
|
|
|
|
|
|
constructor(_testObject: ITestObject) {
|
|
|
|
this._testObject = _testObject;
|
|
|
|
|
|
|
|
this._parse(_testObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get isValid(): boolean {
|
|
|
|
return this._isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setStartCursorPosition(lines: string[]): boolean {
|
2019-10-21 06:25:01 +03:00
|
|
|
const result = this._getCursorPosition(lines);
|
2016-07-16 20:02:31 +03:00
|
|
|
this.startPosition = result.position;
|
|
|
|
return result.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setEndCursorPosition(lines: string[]): boolean {
|
2019-10-21 06:25:01 +03:00
|
|
|
const result = this._getCursorPosition(lines);
|
2016-07-16 20:02:31 +03:00
|
|
|
this.endPosition = result.position;
|
|
|
|
return result.success;
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
private _getCursorPosition(lines: string[]): { success: boolean; position: Position } {
|
2019-10-21 06:25:01 +03:00
|
|
|
const ret = { success: false, position: new Position(0, 0) };
|
2016-07-16 20:02:31 +03:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2019-10-21 06:25:01 +03:00
|
|
|
const columnIdx = lines[i].indexOf('|');
|
2016-07-16 20:02:31 +03:00
|
|
|
if (columnIdx >= 0) {
|
2019-12-30 21:19:55 +03:00
|
|
|
ret.position = new Position(i, columnIdx);
|
2016-07-16 20:02:31 +03:00
|
|
|
ret.success = true;
|
|
|
|
}
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2016-06-18 11:11:27 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
private _parse(t: ITestObject): void {
|
2020-07-06 05:00:46 +03:00
|
|
|
this._isValid = this._setStartCursorPosition(t.start) && this._setEndCursorPosition(t.end);
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public asVimInputText(): string[] {
|
2019-10-21 06:25:01 +03:00
|
|
|
const ret = 'i' + this._testObject.start.join('\n').replace('|', '');
|
2016-07-16 20:02:31 +03:00
|
|
|
return ret.split('');
|
|
|
|
}
|
|
|
|
|
|
|
|
public asVimOutputText(): string[] {
|
2019-10-21 06:25:01 +03:00
|
|
|
const ret = this._testObject.end.slice(0);
|
2016-07-16 20:02:31 +03:00
|
|
|
ret[this.endPosition.line] = ret[this.endPosition.line].replace('|', '');
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a sequence of Vim movement characters 'hjkl' as a string array
|
|
|
|
* which will move the cursor to the start position given in the test.
|
|
|
|
*/
|
|
|
|
public getKeyPressesToMoveToStartPosition(): string[] {
|
|
|
|
let ret = '';
|
2019-10-21 06:25:01 +03:00
|
|
|
const linesToMove = this.startPosition.line;
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2019-10-21 06:25:01 +03:00
|
|
|
const cursorPosAfterEsc =
|
2016-07-16 20:02:31 +03:00
|
|
|
this._testObject.start[this._testObject.start.length - 1].replace('|', '').length - 1;
|
2019-10-21 06:25:01 +03:00
|
|
|
const numCharsInCursorStartLine =
|
2016-07-16 20:02:31 +03:00
|
|
|
this._testObject.start[this.startPosition.line].replace('|', '').length - 1;
|
2019-10-21 06:25:01 +03:00
|
|
|
const charactersToMove = this.startPosition.character;
|
2016-07-16 20:02:31 +03:00
|
|
|
|
|
|
|
if (linesToMove > 0) {
|
|
|
|
ret += Array(linesToMove + 1).join('j');
|
|
|
|
} else if (linesToMove < 0) {
|
|
|
|
ret += Array(Math.abs(linesToMove) + 1).join('k');
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
if (charactersToMove > 0) {
|
|
|
|
ret += Array(charactersToMove + 1).join('l');
|
|
|
|
} else if (charactersToMove < 0) {
|
|
|
|
ret += Array(Math.abs(charactersToMove) + 1).join('h');
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
return ret.split('');
|
|
|
|
}
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
class TestWithRemapsObjectHelper {
|
|
|
|
/**
|
|
|
|
* Position that the test says that the cursor starts at.
|
|
|
|
*/
|
|
|
|
currentStepStartPosition = new Position(0, 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Position that the test says that the cursor ends at.
|
|
|
|
*/
|
|
|
|
currentStepEndPosition = new Position(0, 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Position that the test says that the cursor ends at after timeout finishes.
|
|
|
|
*/
|
|
|
|
currentStepEndAfterTimeoutPosition: Position | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current step index
|
|
|
|
*/
|
|
|
|
currentStep = 0;
|
|
|
|
|
|
|
|
private _isValid = false;
|
|
|
|
private _testObject: ITestWithRemapsObject;
|
|
|
|
|
|
|
|
constructor(_testObject: ITestWithRemapsObject) {
|
|
|
|
this._testObject = _testObject;
|
|
|
|
|
|
|
|
this.parseStep(_testObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get isValid(): boolean {
|
|
|
|
return this._isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setStartCursorPosition(lines: string[]): boolean {
|
|
|
|
const result = this._getCursorPosition(lines);
|
|
|
|
this.currentStepStartPosition = result.position;
|
|
|
|
return result.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setEndCursorPosition(lines: string[]): boolean {
|
|
|
|
const result = this._getCursorPosition(lines);
|
|
|
|
this.currentStepEndPosition = result.position;
|
|
|
|
return result.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setEndAfterTimeoutCursorPosition(lines: string[] | undefined): boolean {
|
|
|
|
if (!lines) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const result = this._getCursorPosition(lines);
|
|
|
|
this.currentStepEndAfterTimeoutPosition = result.position;
|
|
|
|
return result.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _getCursorPosition(lines: string[]): { success: boolean; position: Position } {
|
|
|
|
const ret = { success: false, position: new Position(0, 0) };
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
const columnIdx = lines[i].indexOf('|');
|
|
|
|
if (columnIdx >= 0) {
|
|
|
|
ret.position = new Position(i, columnIdx);
|
|
|
|
ret.success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public parseStep(t: ITestWithRemapsObject): void {
|
|
|
|
this._isValid = true;
|
|
|
|
const stepIdx = this.currentStep;
|
|
|
|
if (stepIdx === 0) {
|
|
|
|
if (!this._setStartCursorPosition(t.start)) {
|
|
|
|
this._isValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const lastStepEnd =
|
|
|
|
t.steps[stepIdx - 1].stepResult.endAfterTimeout ?? t.steps[stepIdx - 1].stepResult.end;
|
|
|
|
if (!this._setStartCursorPosition(lastStepEnd)) {
|
|
|
|
this._isValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!this._setEndCursorPosition(t.steps[stepIdx].stepResult.end)) {
|
|
|
|
this._isValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this._setEndAfterTimeoutCursorPosition(t.steps[stepIdx].stepResult.endAfterTimeout)) {
|
|
|
|
this._isValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public asVimInputText(): string[] {
|
|
|
|
const ret = 'i' + this._testObject.start.join('\n').replace('|', '');
|
|
|
|
return ret.split('');
|
|
|
|
}
|
|
|
|
|
|
|
|
public asVimOutputText(afterTimeout: boolean = false): string[] {
|
|
|
|
const step = this._testObject.steps[this.currentStep];
|
|
|
|
const ret = afterTimeout
|
|
|
|
? step.stepResult.endAfterTimeout!.slice(0)
|
|
|
|
: step.stepResult.end.slice(0);
|
|
|
|
const cursorLine = afterTimeout
|
|
|
|
? this.currentStepEndAfterTimeoutPosition!.line
|
|
|
|
: this.currentStepEndPosition.line;
|
|
|
|
ret[cursorLine] = ret[cursorLine].replace('|', '');
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a sequence of Vim movement characters 'hjkl' as a string array
|
|
|
|
* which will move the cursor to the start position given in the test.
|
|
|
|
*/
|
|
|
|
public getKeyPressesToMoveToStartPosition(): string[] {
|
|
|
|
let ret = '';
|
|
|
|
const linesToMove = this.currentStepStartPosition.line;
|
|
|
|
|
|
|
|
const cursorPosAfterEsc =
|
|
|
|
this._testObject.start[this._testObject.start.length - 1].replace('|', '').length - 1;
|
|
|
|
const numCharsInCursorStartLine =
|
|
|
|
this._testObject.start[this.currentStepStartPosition.line].replace('|', '').length - 1;
|
|
|
|
const charactersToMove = this.currentStepStartPosition.character;
|
|
|
|
|
|
|
|
if (linesToMove > 0) {
|
|
|
|
ret += Array(linesToMove + 1).join('j');
|
|
|
|
} else if (linesToMove < 0) {
|
|
|
|
ret += Array(Math.abs(linesToMove) + 1).join('k');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charactersToMove > 0) {
|
|
|
|
ret += Array(charactersToMove + 1).join('l');
|
|
|
|
} else if (charactersToMove < 0) {
|
|
|
|
ret += Array(Math.abs(charactersToMove) + 1).join('h');
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret.split('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-18 21:59:22 +03:00
|
|
|
/**
|
2016-09-01 07:09:50 +03:00
|
|
|
* Tokenize a string like "abc<Esc>d<C-c>" into ["a", "b", "c", "<Esc>", "d", "<C-c>"]
|
2016-06-18 21:59:22 +03:00
|
|
|
*/
|
|
|
|
function tokenizeKeySequence(sequence: string): string[] {
|
2016-07-16 20:02:31 +03:00
|
|
|
let isBracketedKey = false;
|
2017-06-28 03:02:35 +03:00
|
|
|
let key = '';
|
2019-10-21 06:25:01 +03:00
|
|
|
const result: string[] = [];
|
2016-06-18 21:59:22 +03:00
|
|
|
|
2018-01-19 12:56:31 +03:00
|
|
|
// no close bracket, probably trying to do a left shift, take literal
|
|
|
|
// char sequence
|
|
|
|
function rawTokenize(characters: string): void {
|
|
|
|
for (const char of characters) {
|
|
|
|
result.push(char);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
for (const char of sequence) {
|
|
|
|
key += char;
|
2016-06-18 21:59:22 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
if (char === '<') {
|
2018-01-19 12:56:31 +03:00
|
|
|
if (isBracketedKey) {
|
|
|
|
rawTokenize(key.slice(0, key.length - 1));
|
|
|
|
key = '<';
|
|
|
|
} else {
|
|
|
|
isBracketedKey = true;
|
|
|
|
}
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
2016-06-18 21:59:22 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
if (char === '>') {
|
|
|
|
isBracketedKey = false;
|
|
|
|
}
|
2016-06-18 21:59:22 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
if (isBracketedKey) {
|
|
|
|
continue;
|
2016-06-18 21:59:22 +03:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
result.push(key);
|
2017-06-28 03:02:35 +03:00
|
|
|
key = '';
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
|
|
|
|
2018-01-19 12:56:31 +03:00
|
|
|
if (isBracketedKey) {
|
|
|
|
rawTokenize(key);
|
|
|
|
}
|
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
return result;
|
2016-06-18 21:59:22 +03:00
|
|
|
}
|
|
|
|
|
2016-06-18 11:11:27 +03:00
|
|
|
async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise<void> {
|
2018-09-06 05:15:04 +03:00
|
|
|
modeHandler.vimState.editor = vscode.window.activeTextEditor!;
|
2017-03-03 10:49:54 +03:00
|
|
|
|
2019-10-21 06:25:01 +03:00
|
|
|
const helper = new TestObjectHelper(testObj);
|
2019-08-26 08:05:55 +03:00
|
|
|
const jumpTracker = globalState.jumpTracker;
|
2016-06-14 00:51:40 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// Don't try this at home, kids.
|
|
|
|
(modeHandler as any).vimState.cursorPosition = new Position(0, 0);
|
2016-06-29 05:19:12 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
await modeHandler.handleKeyEvent('<Esc>');
|
2016-06-18 12:16:43 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// Insert all the text as a single action.
|
2020-03-26 20:02:33 +03:00
|
|
|
await modeHandler.vimState.editor.edit((builder) => {
|
2018-09-06 05:15:04 +03:00
|
|
|
builder.insert(new Position(0, 0), testObj.start.join('\n').replace('|', ''));
|
|
|
|
});
|
2016-06-18 11:11:27 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g']);
|
2016-09-13 05:55:29 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// Since we bypassed VSCodeVim to add text,
|
|
|
|
// we need to tell the history tracker that we added it.
|
|
|
|
modeHandler.vimState.historyTracker.addChange();
|
|
|
|
modeHandler.vimState.historyTracker.finishCurrentStep();
|
2016-09-15 23:42:00 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// move cursor to start position using 'hjkl'
|
|
|
|
await modeHandler.handleMultipleKeyEvents(helper.getKeyPressesToMoveToStartPosition());
|
2016-06-14 00:51:40 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
Globals.mockModeHandler = modeHandler;
|
2016-10-10 06:41:28 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
let keysPressed = testObj.keysPressed;
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
keysPressed = keysPressed.replace(/\\n/g, '\\r\\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
jumpTracker.clearJumps();
|
|
|
|
|
2019-12-23 05:53:35 +03:00
|
|
|
// Assumes key presses are single characters for now
|
2018-09-06 05:15:04 +03:00
|
|
|
await modeHandler.handleMultipleKeyEvents(tokenizeKeySequence(keysPressed));
|
|
|
|
|
|
|
|
// Check valid test object input
|
|
|
|
assert(helper.isValid, "Missing '|' in test object.");
|
|
|
|
|
2019-12-23 05:53:35 +03:00
|
|
|
// Check given end output is correct
|
2018-09-06 05:15:04 +03:00
|
|
|
const lines = helper.asVimOutputText();
|
|
|
|
assertEqualLines(lines);
|
2019-12-23 05:53:35 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// Check final cursor position
|
2020-05-17 05:05:28 +03:00
|
|
|
const actualPosition = TextEditor.getSelection().start;
|
2019-10-21 06:25:01 +03:00
|
|
|
const expectedPosition = helper.endPosition;
|
2020-05-17 05:05:28 +03:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
{ line: actualPosition.line, character: actualPosition.character },
|
|
|
|
{ line: expectedPosition.line, character: expectedPosition.character },
|
|
|
|
'Cursor position is wrong.'
|
2018-09-06 05:15:04 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// endMode: check end mode is correct if given
|
2019-12-27 00:32:22 +03:00
|
|
|
if (testObj.endMode !== undefined) {
|
2019-11-29 22:35:30 +03:00
|
|
|
const actualMode = Mode[modeHandler.currentMode].toUpperCase();
|
|
|
|
const expectedMode = Mode[testObj.endMode].toUpperCase();
|
2019-10-21 07:29:23 +03:00
|
|
|
assert.strictEqual(actualMode, expectedMode, "Didn't enter correct mode.");
|
2018-09-06 05:15:04 +03:00
|
|
|
}
|
2018-09-02 21:28:21 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
// jumps: check jumps are correct if given
|
2019-12-27 00:32:22 +03:00
|
|
|
if (testObj.jumps !== undefined) {
|
2018-09-06 05:15:04 +03:00
|
|
|
assert.deepEqual(
|
2020-03-26 20:02:33 +03:00
|
|
|
jumpTracker.jumps.map((j) => lines[j.position.line] || '<MISSING>'),
|
|
|
|
testObj.jumps.map((t) => t.replace('|', '')),
|
2018-09-06 05:15:04 +03:00
|
|
|
'Incorrect jumps found'
|
2018-09-02 21:28:21 +03:00
|
|
|
);
|
2018-02-20 08:50:16 +03:00
|
|
|
|
2019-12-27 00:32:22 +03:00
|
|
|
const stripBar = (text: string | undefined) => (text ? text.replace('|', '') : text);
|
2018-09-06 05:15:04 +03:00
|
|
|
const actualJumpPosition =
|
|
|
|
(jumpTracker.currentJump && lines[jumpTracker.currentJump.position.line]) || '<FRONT>';
|
2020-03-26 20:02:33 +03:00
|
|
|
const expectedJumpPosition = stripBar(testObj.jumps.find((t) => t.includes('|'))) || '<FRONT>';
|
2018-09-02 21:28:21 +03:00
|
|
|
|
2018-09-06 05:15:04 +03:00
|
|
|
assert.deepEqual(
|
|
|
|
actualJumpPosition.toString(),
|
|
|
|
expectedJumpPosition.toString(),
|
|
|
|
'Incorrect jump position found'
|
|
|
|
);
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
2016-06-14 00:51:40 +03:00
|
|
|
}
|
|
|
|
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
async function testItWithRemaps(
|
|
|
|
modeHandler: ModeHandler,
|
|
|
|
testObj: ITestWithRemapsObject
|
|
|
|
): Promise<void> {
|
|
|
|
modeHandler.vimState.editor = vscode.window.activeTextEditor!;
|
|
|
|
|
|
|
|
const helper = new TestWithRemapsObjectHelper(testObj);
|
|
|
|
const jumpTracker = globalState.jumpTracker;
|
|
|
|
|
|
|
|
// Don't try this at home, kids.
|
|
|
|
(modeHandler as any).vimState.cursorPosition = new Position(0, 0);
|
|
|
|
|
|
|
|
await modeHandler.handleKeyEvent('<Esc>');
|
|
|
|
|
|
|
|
// Insert all the text as a single action.
|
|
|
|
await modeHandler.vimState.editor.edit((builder) => {
|
|
|
|
builder.insert(new Position(0, 0), testObj.start.join('\n').replace('|', ''));
|
|
|
|
});
|
|
|
|
|
|
|
|
await modeHandler.handleMultipleKeyEvents(['<Esc>', 'g', 'g']);
|
|
|
|
|
|
|
|
// Since we bypassed VSCodeVim to add text,
|
|
|
|
// we need to tell the history tracker that we added it.
|
|
|
|
modeHandler.vimState.historyTracker.addChange();
|
|
|
|
modeHandler.vimState.historyTracker.finishCurrentStep();
|
|
|
|
|
|
|
|
// move cursor to start position using 'hjkl'
|
|
|
|
await modeHandler.handleMultipleKeyEvents(helper.getKeyPressesToMoveToStartPosition());
|
|
|
|
|
|
|
|
// Check valid test object input
|
|
|
|
assert(helper.isValid, "Missing '|' in test object.");
|
|
|
|
|
|
|
|
Globals.mockModeHandler = modeHandler;
|
|
|
|
|
|
|
|
// Change remappings
|
|
|
|
if (testObj.remaps) {
|
|
|
|
if (!(testObj.remaps instanceof Array)) {
|
|
|
|
Globals.mockConfiguration.normalModeKeyBindings = testObj.remaps?.normalModeKeyBindings ?? [];
|
|
|
|
Globals.mockConfiguration.normalModeKeyBindingsNonRecursive =
|
|
|
|
testObj.remaps?.normalModeKeyBindingsNonRecursive ?? [];
|
|
|
|
Globals.mockConfiguration.insertModeKeyBindings = testObj.remaps?.insertModeKeyBindings ?? [];
|
|
|
|
Globals.mockConfiguration.insertModeKeyBindingsNonRecursive =
|
|
|
|
testObj.remaps?.insertModeKeyBindingsNonRecursive ?? [];
|
|
|
|
Globals.mockConfiguration.visualModeKeyBindings = testObj.remaps?.visualModeKeyBindings ?? [];
|
|
|
|
Globals.mockConfiguration.visualModeKeyBindingsNonRecursive =
|
|
|
|
testObj.remaps?.visualModeKeyBindingsNonRecursive ?? [];
|
|
|
|
Globals.mockConfiguration.operatorPendingModeKeyBindings =
|
|
|
|
testObj.remaps?.operatorPendingModeKeyBindings ?? [];
|
|
|
|
Globals.mockConfiguration.operatorPendingModeKeyBindingsNonRecursive =
|
|
|
|
testObj.remaps?.operatorPendingModeKeyBindingsNonRecursive ?? [];
|
|
|
|
} else {
|
|
|
|
await parseVimRCMappings(testObj.remaps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeout = Globals.mockConfiguration.timeout;
|
|
|
|
const timeoutOffset = timeout / 2;
|
|
|
|
// Globals.mockConfiguration.timeout = timeout;
|
|
|
|
|
|
|
|
await reloadConfiguration();
|
|
|
|
|
|
|
|
for (const { step, index } of testObj.steps.map((value, i) => ({ step: value, index: i }))) {
|
|
|
|
let keysPressed = step.keysPressed;
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
keysPressed = keysPressed.replace(/\\n/g, '\\r\\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse current step
|
|
|
|
helper.currentStep = index;
|
|
|
|
helper.parseStep(testObj);
|
|
|
|
|
|
|
|
const stepTitleOrIndex = step.title ? `nr. ${index} - "${step.title}"` : index;
|
|
|
|
|
|
|
|
// Check valid step object input
|
|
|
|
assert(helper.isValid, `Step ${stepTitleOrIndex} Missing '|' in test object.`);
|
|
|
|
|
|
|
|
jumpTracker.clearJumps();
|
|
|
|
|
|
|
|
// Checks if this step should wait for timeout or not
|
2020-11-20 21:41:47 +03:00
|
|
|
const waitsForTimeout = step.stepResult.endAfterTimeout !== undefined;
|
|
|
|
|
|
|
|
type ResultType = {
|
|
|
|
lines: string;
|
|
|
|
position: vscode.Position;
|
|
|
|
endMode: Mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
const p1 = () => {
|
|
|
|
return new Promise<ResultType>((p1Resolve, p1Reject) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
// Get lines, position and mode after half timeout finishes
|
|
|
|
p1Resolve({
|
|
|
|
lines: TextEditor.getText(),
|
|
|
|
position: TextEditor.getSelection().start,
|
|
|
|
endMode: modeHandler.currentMode,
|
|
|
|
});
|
|
|
|
}, timeoutOffset);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const p2 = () => {
|
2020-11-20 21:53:31 +03:00
|
|
|
return new Promise<ResultType | undefined>((p2Resolve, p2Reject) => {
|
2020-11-20 21:41:47 +03:00
|
|
|
if (waitsForTimeout) {
|
|
|
|
setTimeout(async () => {
|
|
|
|
if (modeHandler.vimState.isCurrentlyPerformingRemapping) {
|
|
|
|
// Performing a remapping, which means it started at the right time but it has not
|
|
|
|
// finished yet (maybe the remapping has a lot of keys to handle) so we wait for the
|
|
|
|
// remapping to finish
|
|
|
|
const wait = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
|
|
|
while (modeHandler.vimState.isCurrentlyPerformingRemapping) {
|
|
|
|
// Wait a little bit longer here because the currently performing remap might have
|
|
|
|
// some remaining keys to handle after it finishes performing the remap and there
|
|
|
|
// might even be there some keys still to be sent that might create another remap.
|
|
|
|
// Example: if you have and ambiguous remap like 'ab -> abcd' and 'abc -> abcdef'
|
|
|
|
// and an insert remap like 'jj -> <Esc>' and you press 'abjj' the first 'j' breaks
|
|
|
|
// the ambiguity and makes the remap start performing, but when the remap finishes
|
|
|
|
// performing there is still the 'jj' to be handled and remapped.
|
|
|
|
await wait(10);
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 21:41:47 +03:00
|
|
|
// Get lines, position and mode after timeout + offset finishes
|
|
|
|
p2Resolve({
|
|
|
|
lines: TextEditor.getText(),
|
|
|
|
position: TextEditor.getSelection().start,
|
|
|
|
endMode: modeHandler.currentMode,
|
|
|
|
});
|
|
|
|
}, timeout + timeoutOffset);
|
|
|
|
} else {
|
2020-11-20 21:53:31 +03:00
|
|
|
p2Resolve(undefined);
|
2020-11-20 21:41:47 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Assumes key presses are single characters for now
|
|
|
|
await modeHandler.handleMultipleKeyEvents(tokenizeKeySequence(keysPressed));
|
|
|
|
|
|
|
|
// Only start the end check promises after the keys were handled to make sure they don't
|
|
|
|
// finish before all the keys are pressed. The keys handler above will resolve when the
|
|
|
|
// keys are handled even if it buffered some keys to wait for a timeout.
|
|
|
|
const [result1, result2] = await Promise.all([p1(), p2()]);
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
|
|
|
|
// Lines after keys pressed but before any timeout
|
|
|
|
|
|
|
|
// Check given end output is correct
|
|
|
|
const endLines = helper.asVimOutputText(false);
|
|
|
|
assert.strictEqual(
|
2020-11-20 21:41:47 +03:00
|
|
|
result1.lines,
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
endLines.join(os.EOL),
|
|
|
|
`Document content does not match on step ${stepTitleOrIndex}.`
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check end cursor position
|
2020-11-20 21:41:47 +03:00
|
|
|
const actualEndPosition = result1.position;
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
const expectedEndPosition = helper.currentStepEndPosition;
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
{ line: actualEndPosition.line, character: actualEndPosition.character },
|
|
|
|
{ line: expectedEndPosition.line, character: expectedEndPosition.character },
|
|
|
|
`Cursor position is wrong on step ${stepTitleOrIndex}.`
|
|
|
|
);
|
|
|
|
|
|
|
|
// endMode: check end mode is correct if given
|
|
|
|
const expectedEndMode = step.stepResult.endMode;
|
|
|
|
if (expectedEndMode !== undefined) {
|
2020-11-20 21:41:47 +03:00
|
|
|
const actualMode = Mode[result1.endMode].toUpperCase();
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
const expectedMode = Mode[expectedEndMode].toUpperCase();
|
|
|
|
assert.strictEqual(
|
|
|
|
actualMode,
|
|
|
|
expectedMode,
|
|
|
|
`Didn't enter correct mode on step ${stepTitleOrIndex}.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-20 21:53:31 +03:00
|
|
|
if (result2) {
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
// After the timeout finishes (plus an offset to be sure it finished)
|
2020-11-20 21:41:47 +03:00
|
|
|
assert.notStrictEqual(result2, undefined);
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
|
|
|
|
// Check given endAfterTimeout output is correct
|
|
|
|
const endAfterTimeoutLines = helper.asVimOutputText(true);
|
|
|
|
assert.strictEqual(
|
2020-11-20 21:41:47 +03:00
|
|
|
result2.lines,
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
endAfterTimeoutLines.join(os.EOL),
|
|
|
|
`Document content does not match on step ${stepTitleOrIndex} after timeout.`
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check endAfterTimeout cursor position
|
2020-11-20 21:41:47 +03:00
|
|
|
const actualEndAfterTimeoutPosition = result2.position;
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
const expectedEndAfterTimeoutPosition = helper.currentStepEndAfterTimeoutPosition!;
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
{
|
|
|
|
line: actualEndAfterTimeoutPosition.line,
|
|
|
|
character: actualEndAfterTimeoutPosition.character,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
line: expectedEndAfterTimeoutPosition.line,
|
|
|
|
character: expectedEndAfterTimeoutPosition.character,
|
|
|
|
},
|
|
|
|
`Cursor position is wrong on step ${stepTitleOrIndex} after Timeout.`
|
|
|
|
);
|
|
|
|
|
|
|
|
// endMode: check end mode is correct if given
|
|
|
|
const expectedEndAfterTimeoutMode = step.stepResult.endModeAfterTimeout;
|
|
|
|
if (expectedEndAfterTimeoutMode !== undefined) {
|
2020-11-20 21:41:47 +03:00
|
|
|
const actualMode = Mode[result2.endMode].toUpperCase();
|
Overhaul remapping logic (#4735)
This is a pretty massive change; see pull request #4735 for full details
Most notably:
- Support for operator-pending mode, including remaps and a half-cursor decoration
- Correct handling of ambiguous remaps with timeout
- Correct handling of recursive special case when the RHS starts with the LHS
- Correct handling of multi-key remaps in insert mode
- Failed movements that occur partway through a remap stop & discard the rest of the remap
- Implement `unmap` and `mapclear` in .vimrc
Refs #463, refs #4908
Fixes #1261, fixes #1398, fixes #1579, fixes #1821, fixes #1835
Fixes #1870, fixes #1883, fixes #2041, fixes #2234, fixes #2466
Fixes #2897, fixes #2955, fixes #2975, fixes #3082, fixes #3086
Fixes #3171, fixes #3373, fixes #3413, fixes #3742, fixes #3768
Fixes #3988, fixes #4057, fixes #4118, fixes #4236, fixes #4353
Fixes #4464, fixes #4530, fixes #4532, fixes #4563, fixes #4674
Fixes #4756, fixes #4883, fixes #4928, fixes #4991, fixes #5016
Fixes #5057, fixes #5067, fixes #5084, fixes #5125
2020-08-16 21:22:51 +03:00
|
|
|
const expectedMode = Mode[expectedEndAfterTimeoutMode].toUpperCase();
|
|
|
|
assert.strictEqual(
|
|
|
|
actualMode,
|
|
|
|
expectedMode,
|
|
|
|
`Didn't enter correct mode on step ${stepTitleOrIndex} after Timeout.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// jumps: check jumps are correct if given
|
|
|
|
if (step.stepResult.jumps !== undefined) {
|
|
|
|
assert.deepEqual(
|
|
|
|
jumpTracker.jumps.map((j) => endLines[j.position.line] || '<MISSING>'),
|
|
|
|
step.stepResult.jumps.map((t) => t.replace('|', '')),
|
|
|
|
'Incorrect jumps found'
|
|
|
|
);
|
|
|
|
|
|
|
|
const stripBar = (text: string | undefined) => (text ? text.replace('|', '') : text);
|
|
|
|
const actualJumpPosition =
|
|
|
|
(jumpTracker.currentJump && endLines[jumpTracker.currentJump.position.line]) || '<FRONT>';
|
|
|
|
const expectedJumpPosition =
|
|
|
|
stripBar(step.stepResult.jumps.find((t) => t.includes('|'))) || '<FRONT>';
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
actualJumpPosition.toString(),
|
|
|
|
expectedJumpPosition.toString(),
|
|
|
|
`Incorrect jump position found on step ${stepTitleOrIndex}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function parseVimRCMappings(lines: string[]): Promise<void> {
|
|
|
|
const config = Globals.mockConfiguration;
|
|
|
|
|
|
|
|
// Remove all the old remappings from the .vimrc file
|
|
|
|
VimrcImpl.removeAllRemapsFromConfig(config);
|
|
|
|
|
|
|
|
// Add the new remappings
|
|
|
|
for (const line of lines) {
|
|
|
|
const remap = await vimrcKeyRemappingBuilder.build(line);
|
|
|
|
if (remap) {
|
|
|
|
VimrcImpl.addRemapToConfig(config, remap);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const unremap = await vimrcKeyRemappingBuilder.buildUnmapping(line);
|
|
|
|
if (unremap) {
|
|
|
|
VimrcImpl.removeRemapFromConfig(config, unremap);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const clearRemap = await vimrcKeyRemappingBuilder.buildClearMapping(line);
|
|
|
|
if (clearRemap) {
|
|
|
|
VimrcImpl.clearRemapsFromConfig(config, clearRemap);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
export { ITestObject, testIt };
|