2022-10-30 20:33:11 +03:00
|
|
|
import { Mode } from '../src/mode/mode';
|
|
|
|
import { newTest, newTestWithRemaps } from './testSimplifier';
|
2017-12-11 16:05:43 +03:00
|
|
|
import { cleanUpWorkspace, setupWorkspace } from './testUtils';
|
2022-10-30 20:33:11 +03:00
|
|
|
import * as testConfiguration from './testConfiguration';
|
2016-10-13 01:35:26 +03:00
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
suite('Record and execute a macro', () => {
|
2016-10-14 01:37:14 +03:00
|
|
|
setup(async () => {
|
2022-10-30 20:33:11 +03:00
|
|
|
const configuration = new testConfiguration.Configuration();
|
|
|
|
|
|
|
|
// for testing with <leader>
|
|
|
|
configuration.camelCaseMotion.enable = true;
|
|
|
|
|
|
|
|
await setupWorkspace(configuration);
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
teardown(cleanUpWorkspace);
|
|
|
|
|
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can record and execute',
|
|
|
|
start: ['|foo = 1', "bar = 'a'", 'foobar = foo + bar'],
|
2016-10-14 01:37:14 +03:00
|
|
|
keysPressed: 'qaA;<Esc>Ivar <Esc>qj@a',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['var foo = 1;', "var| bar = 'a';", 'foobar = foo + bar'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can repeat last invoked macro',
|
|
|
|
start: ['|foo = 1', "bar = 'a'", 'foobar = foo + bar'],
|
2016-10-14 01:37:14 +03:00
|
|
|
keysPressed: 'qaA;<Esc>Ivar <Esc>qj@aj@@',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['var foo = 1;', "var bar = 'a';", 'var| foobar = foo + bar;'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can play back with count',
|
2016-10-14 01:37:14 +03:00
|
|
|
start: ['|"("+a+","+b+","+c+","+d+","+e+")"'],
|
|
|
|
keysPressed: 'f+s + <Esc>qq;.q8@q',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['"(" + a + "," + b + "," + c + "," + d + "," + e +| ")"'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
2016-10-14 02:16:13 +03:00
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can play back with count, abort when a motion fails',
|
2016-10-14 02:16:13 +03:00
|
|
|
start: ['|"("+a+","+b+","+c+","+d+","+e+")"'],
|
|
|
|
keysPressed: 'f+s + <Esc>qq;.q22@q',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['"(" + a + "," + b + "," + c + "," + d + "," + e +| ")"'],
|
2016-10-14 02:16:13 +03:00
|
|
|
});
|
|
|
|
|
2016-10-14 01:37:14 +03:00
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Repeat change on contiguous lines',
|
2016-10-14 01:37:14 +03:00
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: 'qa0f.r)w~jq3@a',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['1) One', '2) Two', '3) Three', '4) F|our'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
2021-07-22 21:07:21 +03:00
|
|
|
newTest({
|
|
|
|
title: 'Repeat insertion with arrow keys and <BS>',
|
|
|
|
start: ['o|ne two three', 'four five six'],
|
|
|
|
keysPressed: 'qk' + 'A' + ' tpyo' + '<left><BS><left>y' + '<Esc>' + 'q' + 'j0' + '@k',
|
|
|
|
end: ['one two three typo', 'four five six t|ypo'],
|
|
|
|
});
|
|
|
|
|
2016-10-14 01:37:14 +03:00
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Append command to a macro',
|
2016-10-14 01:37:14 +03:00
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: 'qa0f.r)qqAw~jq3@a',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['1) One', '2) Two', '3) Three', '4) F|our'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
|
|
|
|
2020-06-28 23:38:58 +03:00
|
|
|
newTest({
|
|
|
|
title: 'Append command to a not yet created register creates a new register',
|
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: 'qB0f.r)w~jq3@b',
|
|
|
|
end: ['1) One', '2) Two', '3) Three', '4) F|our'],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'Can handle calling an uppercase register',
|
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: 'qa0f.r)w~jq3@A',
|
|
|
|
end: ['1) One', '2) Two', '3) Three', '4) F|our'],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'Can handle calling a non existing macro',
|
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: '@x',
|
|
|
|
end: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'Can handle calling a non existing macro with uppercase letter',
|
|
|
|
start: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
keysPressed: '@Z',
|
|
|
|
end: ['1. |one', '2. two', '3. three', '4. four'],
|
|
|
|
});
|
|
|
|
|
2016-10-14 01:37:14 +03:00
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can record Ctrl Keys and repeat',
|
|
|
|
start: ['1|.'],
|
2016-10-14 01:37:14 +03:00
|
|
|
keysPressed: 'qayyp<C-a>q4@a',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['1.', '2.', '3.', '4.', '5.', '|6.'],
|
2016-10-14 01:37:14 +03:00
|
|
|
});
|
2017-04-29 07:29:33 +03:00
|
|
|
|
2017-04-29 07:32:29 +03:00
|
|
|
newTest({
|
2017-06-28 03:02:35 +03:00
|
|
|
title: 'Can execute macros with dot commands properly',
|
|
|
|
start: ['|test', 'test', 'test', 'test', 'test', 'test', 'test'],
|
2017-04-29 07:29:33 +03:00
|
|
|
keysPressed: 'qadd.q@a@a',
|
2017-06-28 03:02:35 +03:00
|
|
|
end: ['|test'],
|
2017-04-29 07:29:33 +03:00
|
|
|
});
|
2019-05-06 07:06:42 +03:00
|
|
|
|
2022-10-31 05:27:25 +03:00
|
|
|
suite('`:` (command) register used as macro', () => {
|
|
|
|
newTest({
|
|
|
|
title: 'Repeat :s',
|
|
|
|
start: ['|old', 'old', 'old'],
|
|
|
|
keysPressed: ':s/old/new\nj@:j@@',
|
|
|
|
end: ['new', 'new', '|new'],
|
|
|
|
});
|
2020-05-13 02:45:50 +03:00
|
|
|
|
2022-10-31 05:27:25 +03:00
|
|
|
newTest({
|
|
|
|
title: 'Repeat :d',
|
|
|
|
start: ['one', 't|wo', 'three', 'four', 'five'],
|
|
|
|
keysPressed: ':d/\n' + '@:' + '@@',
|
|
|
|
end: ['one', '|five'],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'Repeat :co',
|
|
|
|
start: ['|one', 'two'],
|
|
|
|
keysPressed: ':.co$\n' + '@:',
|
|
|
|
end: ['one', 'two', '|one', 'one'], // TODO: Cursor should be on line 3, not 4
|
|
|
|
});
|
2021-08-03 05:28:47 +03:00
|
|
|
});
|
|
|
|
|
2020-05-13 02:45:50 +03:00
|
|
|
newTest({
|
|
|
|
title: 'Can record and execute macro that handles multiple lines',
|
|
|
|
start: ['|Countdown:', '1', 'LAUNCH!!!'],
|
|
|
|
keysPressed: 'qajyyP<C-a>kq8@a',
|
|
|
|
end: ['C|ountdown:', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'LAUNCH!!!'],
|
|
|
|
});
|
2021-05-11 05:48:12 +03:00
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'Failed `n` stops macro from repeating',
|
|
|
|
config: { wrapscan: false },
|
|
|
|
start: ['|one two three', 'one two three', 'one two three'],
|
|
|
|
keysPressed: '/two\n0' + 'qq' + 'nea XXX<Esc>q' + '5@q',
|
|
|
|
end: ['one two XXX three', 'one two XXX three', 'one two XX|X three'],
|
|
|
|
});
|
2021-07-21 07:40:53 +03:00
|
|
|
|
2021-08-14 08:08:30 +03:00
|
|
|
newTest({
|
|
|
|
title: 'q[A-Z] (action) Can record and append to a macro',
|
|
|
|
start: ['|'],
|
|
|
|
keysPressed:
|
|
|
|
'qb' +
|
|
|
|
'i' +
|
|
|
|
'one two ' +
|
|
|
|
'<Esc>q' +
|
|
|
|
'o<Esc>@b' +
|
|
|
|
'o<Esc>' +
|
|
|
|
'qB' +
|
|
|
|
'i' +
|
|
|
|
'three four' +
|
|
|
|
'<Esc>q' +
|
|
|
|
'o<Esc>@b',
|
|
|
|
end: ['one two ', 'one two ', 'three four', 'one twothree fou|r '],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: 'q[A-Z] (action) Creates new register, accessible by [a-z]',
|
|
|
|
start: ['|'],
|
|
|
|
keysPressed: 'qB' + 'i' + 'one two' + '<Esc>q' + 'o<Esc>@b',
|
|
|
|
end: ['one two', 'one tw|o'],
|
|
|
|
});
|
|
|
|
|
2021-07-21 07:40:53 +03:00
|
|
|
newTest({
|
|
|
|
title: 'Invalid register throws E354',
|
|
|
|
start: ['one t|wo three'],
|
|
|
|
keysPressed: '@~',
|
|
|
|
end: ['one t|wo three'],
|
2021-07-21 21:21:54 +03:00
|
|
|
statusBar: "E354: Invalid register name: '~'",
|
2021-07-21 07:40:53 +03:00
|
|
|
});
|
2021-07-27 00:13:28 +03:00
|
|
|
|
2022-03-09 08:05:43 +03:00
|
|
|
for (const register of ['%', '#']) {
|
|
|
|
newTest({
|
|
|
|
title: `Filename register '${register}' throw E354`,
|
|
|
|
start: ['one t|wo three'],
|
|
|
|
keysPressed: `@${register}`,
|
|
|
|
end: ['one t|wo three'],
|
|
|
|
statusBar: `E354: Invalid register name: '${register}'`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-27 00:13:28 +03:00
|
|
|
newTest({
|
|
|
|
title: '`@@` before a macro has been run throws E748',
|
|
|
|
start: ['one t|wo three'],
|
|
|
|
keysPressed: '@@',
|
|
|
|
end: ['one t|wo three'],
|
|
|
|
statusBar: 'E748: No previously used register',
|
|
|
|
});
|
2022-10-30 20:33:11 +03:00
|
|
|
|
|
|
|
suite('Text copied into register can be run as a macro', () => {
|
|
|
|
const start = ['one', 'two', 'three'];
|
|
|
|
const register = 'x';
|
|
|
|
const testCases: Array<[string, string[]]> = [
|
|
|
|
['', ['|one', 'two', 'three']],
|
|
|
|
['j', ['one', '|two', 'three']],
|
|
|
|
['2j', ['one', 'two', '|three']],
|
|
|
|
|
|
|
|
['A' + ', uno<Esc>', ['one, un|o', 'two', 'three']],
|
|
|
|
|
|
|
|
['dd', ['|two', 'three']],
|
|
|
|
|
|
|
|
['yyp', ['one', '|one', 'two', 'three']],
|
|
|
|
|
|
|
|
['VGJ', ['one two| three']],
|
|
|
|
|
|
|
|
['gUU' + 'j.' + 'j.', ['ONE', 'TWO', '|THREE']],
|
|
|
|
|
|
|
|
[':2d\\n', ['one', '|three']],
|
|
|
|
|
|
|
|
['jjl~l~0' + '<leader>w' + '<leader>w', ['one', 'two', 'tHr|Ee']],
|
|
|
|
|
|
|
|
// TODO: control characters...
|
|
|
|
];
|
|
|
|
for (const [macro, end] of testCases) {
|
|
|
|
newTest({
|
|
|
|
title: `macro='${macro}'`,
|
|
|
|
start: [`|${macro}`, ...start],
|
|
|
|
keysPressed: `"${register}dd` + `@${register}`,
|
|
|
|
end,
|
|
|
|
endMode: Mode.Normal,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: `test @@ - 1`,
|
|
|
|
start: [`|j`, ...start],
|
|
|
|
keysPressed: `"${register}dd` + `@${register}` + `@@`,
|
|
|
|
end: ['one', 'two', '|three'],
|
|
|
|
endMode: Mode.Normal,
|
|
|
|
});
|
|
|
|
|
|
|
|
newTest({
|
|
|
|
title: `test @@ - 2`,
|
|
|
|
start: [`|dd`, ...start],
|
|
|
|
keysPressed: `"${register}dd` + `@${register}` + `@@`,
|
|
|
|
end: ['|three'],
|
|
|
|
endMode: Mode.Normal,
|
|
|
|
});
|
|
|
|
|
|
|
|
newTestWithRemaps({
|
|
|
|
title: 'test with remaps: simple',
|
|
|
|
start: [`|J`, ...start],
|
|
|
|
remaps: ['nmap J jj'],
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
// Step 0:
|
|
|
|
keysPressed: `"${register}dd` + `@${register}`,
|
|
|
|
stepResult: {
|
|
|
|
end: ['one', 'two', '|three'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTestWithRemaps({
|
|
|
|
title: 'test with remaps: repeat',
|
|
|
|
start: [`|Pm`, ...start],
|
|
|
|
remaps: ['nmap Pm Cabc<Esc>'],
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
// Step 0:
|
|
|
|
keysPressed: `"${register}dd` + `@${register}`,
|
|
|
|
stepResult: {
|
|
|
|
end: ['ab|c', 'two', 'three'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Step 1:
|
|
|
|
keysPressed: 'j0' + `@@`,
|
|
|
|
stepResult: {
|
|
|
|
end: ['abc', 'ab|c', 'three'],
|
|
|
|
},
|
2022-10-31 05:27:25 +03:00
|
|
|
},
|
2022-10-30 20:33:11 +03:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
newTestWithRemaps({
|
|
|
|
title: 'test with remaps: leader',
|
|
|
|
start: [`|<leader>J`, ...start],
|
|
|
|
remaps: ['nmap <leader>J jj'],
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
// Step 0:
|
|
|
|
keysPressed: `"${register}dd` + `@${register}`,
|
|
|
|
stepResult: {
|
|
|
|
end: ['one', 'two', '|three'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2017-06-28 03:02:35 +03:00
|
|
|
});
|