-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayback_nested.test.js
138 lines (119 loc) · 5.97 KB
/
playback_nested.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
const assert = require('assert');
const vscode = require('vscode');
const util = require('../../src/util.js');
const { TestUtil } = require('./test_util.js');
const { CommandsToTest } = require('./commands_to_test.js');
const { keyboardMacro, awaitController } = require('../../src/extension.js');
describe('Recording and Playback with Nested Playback', () => {
let textEditor;
const Cmd = CommandsToTest;
const Type = text => ({ command: '$type', args: { text } });
const Move = delta => ({ command: '$moveCursor', args: { characterDelta: delta } });
const setSelections = async function(array) {
await awaitController.waitFor('selection', 1).catch(() => {});
const newSelections = TestUtil.arrayToSelections(array);
if (!util.isEqualSelections(textEditor.selections, newSelections)) {
const timeout = 1000;
textEditor.selections = newSelections;
await awaitController.waitFor('selection', timeout).catch(
() => { console.log('Warning: timeout in setSelections!'); }
);
}
};
const getSelections = function() {
return TestUtil.selectionsToArray(textEditor.selections);
};
before(async () => {
vscode.window.showInformationMessage('Started test for Recording and Playback with Nested Playback.');
textEditor = await TestUtil.setupTextEditor({ content: '' });
});
describe('playback during recording', () => {
beforeEach(async () => {
await TestUtil.resetDocument(textEditor, (
'zero\n' +
'one\n' +
'two\n' +
'three\n' +
'four\n' +
'five\n'
));
});
it('should record whole sequence', async () => {
const sequence = [ Cmd.CursorEnd, Cmd.DeleteLeft, Cmd.CursorRight ];
await setSelections([[0, 0]]);
keyboardMacro.startRecording();
await keyboardMacro.playback({ sequence });
keyboardMacro.finishRecording();
assert.strictEqual(textEditor.document.lineAt(0).text, 'zer');
assert.deepStrictEqual(getSelections(), [[1, 0]]);
assert.deepStrictEqual(keyboardMacro.getCurrentSequence(), sequence);
await keyboardMacro.playback();
assert.strictEqual(textEditor.document.lineAt(1).text, 'on');
assert.deepStrictEqual(getSelections(), [[2, 0]]);
});
it('should record whole sequence when it called within wrap', async () => {
const sequence = [ Cmd.CursorEnd, Cmd.DeleteLeft, Cmd.CursorRight ];
await setSelections([[0, 0]]);
keyboardMacro.startRecording();
await keyboardMacro.wrapSync({
command: 'kb-macro.playback',
args: { sequence }
});
keyboardMacro.finishRecording();
assert.strictEqual(textEditor.document.lineAt(0).text, 'zer');
assert.deepStrictEqual(getSelections(), [[1, 0]]);
assert.deepStrictEqual(keyboardMacro.getCurrentSequence(), sequence);
await keyboardMacro.playback();
assert.strictEqual(textEditor.document.lineAt(1).text, 'on');
assert.deepStrictEqual(getSelections(), [[2, 0]]);
});
it('should record whole sequence with repeat', async () => {
const sequence = [ Cmd.CursorEnd, Cmd.DeleteLeft, Cmd.CursorRight ];
const repeat = 3;
await setSelections([[0, 0]]);
keyboardMacro.startRecording();
await keyboardMacro.playback({ sequence, repeat });
keyboardMacro.finishRecording();
assert.strictEqual(textEditor.document.lineAt(0).text, 'zer');
assert.strictEqual(textEditor.document.lineAt(1).text, 'on');
assert.strictEqual(textEditor.document.lineAt(2).text, 'tw');
assert.deepStrictEqual(getSelections(), [[3, 0]]);
assert.deepStrictEqual(
keyboardMacro.getCurrentSequence(),
[].concat(sequence).concat(sequence).concat(sequence)
);
await keyboardMacro.playback();
assert.strictEqual(textEditor.document.lineAt(3).text, 'thre');
assert.strictEqual(textEditor.document.lineAt(4).text, 'fou');
assert.strictEqual(textEditor.document.lineAt(5).text, 'fiv');
assert.deepStrictEqual(getSelections(), [[6, 0]]);
});
it('should record sequence with $type command', async () => {
const sequence = [ Cmd.CursorEnd, Type('!!'), Cmd.CursorRight ];
await setSelections([[0, 0]]);
keyboardMacro.startRecording();
await keyboardMacro.playback({ sequence });
keyboardMacro.finishRecording();
assert.strictEqual(textEditor.document.lineAt(0).text, 'zero!!');
assert.deepStrictEqual(getSelections(), [[1, 0]]);
assert.deepStrictEqual(keyboardMacro.getCurrentSequence(), sequence);
await keyboardMacro.playback();
assert.strictEqual(textEditor.document.lineAt(1).text, 'one!!');
assert.deepStrictEqual(getSelections(), [[2, 0]]);
});
it('should record sequence with $moveCursor command', async () => {
const sequence = [ Cmd.CursorEnd, Type('()'), Move(-1), Type('!!'), Cmd.CursorEnd, Cmd.CursorRight ];
await setSelections([[0, 0]]);
keyboardMacro.startRecording();
await keyboardMacro.playback({ sequence });
keyboardMacro.finishRecording();
assert.strictEqual(textEditor.document.lineAt(0).text, 'zero(!!)');
assert.deepStrictEqual(getSelections(), [[1, 0]]);
assert.deepStrictEqual(keyboardMacro.getCurrentSequence(), sequence);
await keyboardMacro.playback();
assert.strictEqual(textEditor.document.lineAt(1).text, 'one(!!)');
assert.deepStrictEqual(getSelections(), [[2, 0]]);
});
});
});