-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathMovementTest.cs
More file actions
339 lines (293 loc) · 17 KB
/
MovementTest.cs
File metadata and controls
339 lines (293 loc) · 17 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
using Microsoft.PowerShell;
using Xunit;
namespace Test
{
public partial class ReadLine
{
[SkippableFact]
public void EndOfLine()
{
TestSetup(KeyMode.Cmd);
Test("", Keys( _.End, CheckThat(() => AssertCursorLeftIs(0)) ));
Test(_emptyLine, Keys(
_emptyLine,
_.Home,
CheckThat(() => AssertCursorLeftIs(0)),
_.End,
CheckThat(() => AssertCursorLeftTopIs(0, 1))
));
var buffer = new string(' ', _console.BufferWidth + 5);
Test(buffer, Keys(
buffer,
_.Home,
CheckThat(() => AssertCursorLeftIs(0)),
_.End,
CheckThat(() => AssertCursorLeftTopIs(5, 1))
));
}
[SkippableFact]
public void MultilineCursorMovement_WithWrappedLines()
{
TestSetup(KeyMode.Cmd);
string line_0 = "4444";
string line_1 = "33";
string line_2 = "666666";
string line_3 = "777";
int wrappedLength_1 = 9;
int wrappedLength_2 = 2;
string wrappedLine_1 = new string('8', _console.BufferWidth - ContinuationPromptLength + wrappedLength_1); // Take 2 physical lines
string wrappedLine_2 = new string('6', _console.BufferWidth - ContinuationPromptLength + wrappedLength_2); // Take 2 physical lines
Test("", Keys(
"", _.Shift_Enter, // physical line 0
line_0, _.Shift_Enter, // physical line 1
line_1, _.Shift_Enter, // physical line 2
line_2, _.Shift_Enter, // physical line 3
wrappedLine_1, _.Shift_Enter, // physical line 4,5
wrappedLine_2, _.Shift_Enter, // physical line 6,7
line_3, // physical line 8
// Starting at the end of the last line.
// Verify that UpArrow goes to the end of the previous logical line.
CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
// Press Up/Down/Up
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_2, 7)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_2, 7)),
// Press Up/Down/Up
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_1, 5)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_2, 7)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_1, 5)),
// Press Up/Down/Up
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_2.Length, 3)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_1, 5)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_2.Length, 3)),
// Press Up/Up
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_1.Length, 2)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length, 1)),
// Move to left for 1 character, so the cursor now is not at the end of line.
// Verify that DownArrow/UpArrow goes to the previous logical line at the same column.
_.LeftArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 1)),
// Press Down all the way to the end
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_1.Length, 2)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 3)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 4)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 5)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 6)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_2, 7)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_3.Length, 8)),
// Press Up all the way to the physical line 1
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(wrappedLength_2, 7)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 6)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 5)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 4)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 3)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_1.Length, 2)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength + line_0.Length - 1, 1)),
// Clear the input, we were just testing movement
_.Escape
));
}
[SkippableFact]
public void MultilineCursorMovement()
{
TestSetup(KeyMode.Cmd);
Test("", Keys(
"4444", _.Shift_Enter,
"666666", _.Shift_Enter,
"88888888", _.Shift_Enter,
"666666", _.Shift_Enter,
"4444", _.Shift_Enter,
// Starting at the end of the next to last line (because it's not blank)
// Verify that Home first goes to the start of the line, then the start of the input.
_.LeftArrow,
_.Home, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 4)),
_.Home, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
// Now (because we're at the start), verify first End goes to end of the line
// and the second End goes to the end of the input.
_.End, CheckThat(() => AssertCursorLeftTopIs(4, 0)),
_.End, CheckThat(() => AssertCursorLeftTopIs(0 + ContinuationPromptLength, 5)),
_.Home, _.Home,
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 2)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 3)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 4)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 5)),
_.LeftArrow, _.Home,
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 3)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 2)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 0)), // was (4,0), but seems wrong
// Make sure that movement between lines stays at the end of a line if it starts
// at the end of a line
_.End, _.End,
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(4 + ContinuationPromptLength, 4)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 3)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(8 + ContinuationPromptLength, 2)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 1)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(4, 0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 1)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(8 + ContinuationPromptLength, 2)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 3)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(4 + ContinuationPromptLength, 4)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(0 + ContinuationPromptLength, 5)),
_.Escape,
_.Shift_Enter,
"88888888", _.Shift_Enter,
"55555", _.Shift_Enter,
"22", _.Shift_Enter,
"55555", _.Shift_Enter,
"88888888",
_.LeftArrow, _.LeftArrow,
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(5 + ContinuationPromptLength, 4)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(2 + ContinuationPromptLength, 3)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(5 + ContinuationPromptLength, 2)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 1)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
_.UpArrow, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 1)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(5 + ContinuationPromptLength, 2)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(2 + ContinuationPromptLength, 3)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(5 + ContinuationPromptLength, 4)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(6 + ContinuationPromptLength, 5)),
// Using the input previously entered, check for correct cursor movements when first line is blank
_.Home, _.Home, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(8 + ContinuationPromptLength, 1)),
_.Home, CheckThat(() => AssertCursorLeftTopIs(ContinuationPromptLength, 1)),
_.Home, CheckThat(() => AssertCursorLeftTopIs(0,0)),
// Clear the input, we were just testing movement
_.Escape
));
}
[SkippableFact]
public void CursorMovement()
{
TestSetup(KeyMode.Cmd);
Test("abcde", Keys(
// Left arrow at start of line.
_.LeftArrow, CheckThat(() => AssertCursorLeftIs(0)),
"ace",
_.LeftArrow, CheckThat(() => AssertCursorLeftIs(2)),
'd',
_.LeftArrow, CheckThat(() => AssertCursorLeftIs(2)),
_.LeftArrow, CheckThat(() => AssertCursorLeftIs(1)),
'b'
));
// Test with digit arguments
var input = "0123456789";
Test(input, Keys(
_.Alt_9, _.LeftArrow, CheckThat(() => AssertCursorLeftIs(0)),
_.Alt_9, _.RightArrow, CheckThat(() => AssertCursorLeftIs(0)),
input,
_.Alt_5, _.LeftArrow, CheckThat(() => AssertCursorLeftIs(5)),
_.Alt_Minus, _.Alt_2, _.LeftArrow, CheckThat(() => AssertCursorLeftIs(7)),
_.Alt_2, _.RightArrow, CheckThat(() => AssertCursorLeftIs(9)),
_.Alt_Minus, _.Alt_7, _.RightArrow, CheckThat(() => AssertCursorLeftIs(2))));
}
[SkippableFact]
public void GotoBrace()
{
Skip.IfNot(KeyboardHasCtrlRBracket);
TestSetup(KeyMode.Cmd);
// Test empty input
Test("", Keys(_.Ctrl_RBracket));
Test("(11)", Keys("(11)", _.LeftArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(0))));
Test("$a[11]", Keys("$a[11]", _.LeftArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(2))));
Test("{11}", Keys("{11}", _.LeftArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(0))));
Test("(11)", Keys("(11)", _.Home, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(3))));
Test("$a[11]", Keys("$a[11]", _.Home, _.RightArrow, _.RightArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(5))));
Test("{11}", Keys("{11}", _.Home, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(3))));
// Test multiples, make sure we go to the right one.
Test("((11))", Keys("((11))", _.LeftArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(0))));
Test("((11))", Keys("((11))", _.LeftArrow, _.LeftArrow, _.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(1))));
// Make sure we don't match inside a string
TestMustDing("", Keys(
"'()'", _.LeftArrow, _.LeftArrow,
_.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(2)),
_.Ctrl_c, InputAcceptedNow));
foreach (var c in new[] {'(', ')', '{', '}', '[', ']'})
{
TestMustDing("", Keys(
'a', c, _.LeftArrow,
_.Ctrl_RBracket, CheckThat(() => AssertCursorLeftIs(1)),
_.Ctrl_c, InputAcceptedNow));
}
}
[SkippableFact]
public void CharacterSearch()
{
TestSetup(KeyMode.Cmd);
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3", _.Home,
_.F3, '|', CheckThat(() => AssertCursorLeftIs(5)),
_.F3, '|', CheckThat(() => AssertCursorLeftIs(12))));
}
[SkippableFact]
public void CharacterSearchEmacs()
{
Skip.IfNot(KeyboardHasCtrlRBracket);
TestSetup(KeyMode.Emacs);
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3", _.Home,
_.Ctrl_RBracket, '|', CheckThat(() => AssertCursorLeftIs(5)),
_.Ctrl_RBracket, '|', CheckThat(() => AssertCursorLeftIs(12)),
_.End,
_.Alt_Minus, _.Alt_2, _.Ctrl_RBracket, '|', CheckThat(() => AssertCursorLeftIs(5)),
_.Home,
_.Alt_2, _.Ctrl_RBracket, '|', CheckThat(() => AssertCursorLeftIs(12))));
TestMustDing("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Ctrl_RBracket, 'z'));
}
[SkippableFact]
public void CharacterSearchApi()
{
int i = 0;
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+z",
(key, count) => PSConsoleReadLine.CharacterSearch(null, i++ == 0 ? (object)'|' : "|")));
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Home,
_.Ctrl_z, CheckThat(() => AssertCursorLeftIs(5)),
_.Ctrl_z, CheckThat(() => AssertCursorLeftIs(12))));
}
[SkippableFact]
public void CharacterSearchBackward()
{
TestSetup(KeyMode.Cmd);
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Shift_F3, '|', CheckThat(() => AssertCursorLeftIs(12)),
_.Shift_F3, '|', CheckThat(() => AssertCursorLeftIs(5))));
}
[SkippableFact]
public void CharacterSearchBackwardEmacs()
{
Skip.IfNot(KeyboardHasCtrlRBracket);
TestSetup(KeyMode.Emacs);
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Ctrl_Alt_RBracket, '|', CheckThat(() => AssertCursorLeftIs(12)),
_.Ctrl_Alt_RBracket, '|', CheckThat(() => AssertCursorLeftIs(5)),
_.Home,
_.Alt_Minus, _.Alt_2, _.Ctrl_Alt_RBracket, '|', CheckThat(() => AssertCursorLeftIs(12)),
_.End,
_.Alt_2, _.Ctrl_Alt_RBracket, '|', CheckThat(() => AssertCursorLeftIs(5))));
TestMustDing("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Ctrl_Alt_RBracket, 'z'));
}
[SkippableFact]
public void CharacterSearchBackwardApi()
{
int i = 0;
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+z",
(key, count) => PSConsoleReadLine.CharacterSearchBackward(null, i++ == 0 ? (object)'|' : "|")));
Test("cmd1 | cmd2 | cmd3", Keys(
"cmd1 | cmd2 | cmd3",
_.Ctrl_z, CheckThat(() => AssertCursorLeftIs(12)),
_.Ctrl_z, CheckThat(() => AssertCursorLeftIs(5))));
}
}
}