{{ message }}
Repository navigation
Expand file tree
/
Copy pathKillYankTest.cs
More file actions
511 lines (420 loc) · 16.4 KB
/
Copy pathKillYankTest.cs
File metadata and controls
511 lines (420 loc) · 16.4 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.PowerShell;
using Xunit;
namespace Test
{
public partial class ReadLine
{
[SkippableFact]
public void KillWord()
{
TestSetup(KeyMode.Emacs);
Test("echo defabc", Keys(
_.Alt_d, // Test on empty input
"echo abc def",
Enumerable.Repeat(_.LeftArrow, 7),
_.Alt_d, // Kill 'abc'
_.End, _.Ctrl_y)); // Yank 'abc' at end of line
}
[SkippableFact]
public void BackwardKillWord()
{
TestSetup(KeyMode.Emacs);
Test("echo defabc ", Keys(
_.Alt_Backspace, // Test on empty line
"echo abc def",
Enumerable.Repeat(_.LeftArrow, 3),
_.Alt_Backspace, // Kill 'abc '
_.End, _.Ctrl_y)); // Yank 'abc ' at the end
}
[SkippableFact]
public void UnixWordRubout()
{
TestSetup(KeyMode.Emacs);
Test("echo abc ", Keys("echo abc a\\b\\c", _.Ctrl_w));
}
[SkippableFact]
public void KillRegion()
{
Skip.IfNot(KeyboardHasCtrlAt);
TestSetup(KeyMode.Emacs, new KeyHandler("Ctrl+z", PSConsoleReadLine.KillRegion));
Test("echo foobar", Keys("bar", _.Ctrl_At, "echo foo", _.Ctrl_z, _.Home, _.Ctrl_y));
}
[SkippableFact]
public void YankPop()
{
TestSetup(KeyMode.Emacs);
var killedText = new List<string>();
Test("z", Keys(_.Ctrl_y, _.Alt_y, _.z));
// Fill the kill ring plus some extra.
for (int i = 0; i < PSConsoleReadLineOptions.DefaultMaximumKillRingCount + 2; i++)
{
var c = (char)('a' + i);
killedText.Add(c + "zz");
Test("", Keys(c, "zz", _.Ctrl_u));
}
int killRingIndex = killedText.Count - 1;
Test(killedText[killRingIndex], Keys(_.Ctrl_y));
Test(killedText[killRingIndex] + killedText[killRingIndex],
Keys(_.Ctrl_y, _.Ctrl_y));
killRingIndex -= 1;
Test(killedText[killRingIndex], Keys(_.Ctrl_y, _.Alt_y));
// Test wrap around. We need 1 yank and n-1 yankpop to wrap around once, plus enter.
Test(killedText[killRingIndex],
Keys(_.Ctrl_y, Enumerable.Repeat(_.Alt_y, PSConsoleReadLineOptions.DefaultMaximumKillRingCount)));
// Make sure an empty kill doesn't end up in the kill ring
Test("a", Keys("a", _.Ctrl_u, _.Ctrl_u, "b", _.Ctrl_u, _.Ctrl_y, _.Alt_y));
// Make sure an empty kill doesn't end up in the kill ring after movement commands
Test("abc def", Keys(
"abc def",
_.Ctrl_w, // remove 'def'
_.Ctrl_a, _.Ctrl_u, // empty kill at beginning of line
_.Ctrl_e, // back to end of line
"ghi",
_.Ctrl_w, // remove 'ghi'
_.Ctrl_y, // yank 'ghi'
_.Alt_y)); // replace busy with previous text in kill ring
}
[SkippableFact]
public void KillLine()
{
TestSetup(KeyMode.Emacs);
// Kill whole line
Test("", Keys("dir", _.Ctrl_a, _.Ctrl_k));
Test("dir", Keys(_.Ctrl_y));
// Kill partial line
Test("dir ", Keys("dir foo", _.Alt_b, _.Ctrl_k));
Test("foo", Keys(_.Ctrl_y));
}
[SkippableFact]
public void BackwardKillLine()
{
TestSetup(KeyMode.Emacs);
// Kill whole line
// Check killed text by yanking
Test("ls", Keys("dir", _.Ctrl_u, "ls"));
Test("dir", Keys(_.Ctrl_y));
// Kill whole line with second key binding
Test("def", Keys("abc", _.Ctrl_x, _.Backspace, "def"));
Test("abc", Keys(_.Ctrl_y));
// Kill partial line
Test("foo", Keys("dir foo", _.Alt_b, _.Ctrl_u));
Test("dir ", Keys(_.Ctrl_y));
}
[SkippableFact]
public void KillAppend()
{
TestSetup(KeyMode.Emacs);
Test(" abcdir", Keys(
" abcdir", _.LeftArrow, _.LeftArrow, _.LeftArrow,
_.Ctrl_k, // Kill 'dir'
_.Ctrl_u, // Kill append ' abc'
_.Ctrl_y)); // Yank ' abcdir'
// Test empty kill doesn't affect kill append
Test("ab", Keys("ab", _.LeftArrow, _.Ctrl_k, _.Ctrl_k, _.Ctrl_u, _.Ctrl_y));
// test empty kill then good kill
Test("abc", Keys(
"abc",
_.Ctrl_k,
_.Ctrl_u,
_.Ctrl_y));
// test undo/redo history after empty kill
Test("abc def ghi", Keys(
"abc def ghi",
_.Ctrl_w, // remove ghi
_.Ctrl_k, // empty kill
_.Ctrl_w, // remove def
_.Ctrl_Underbar, // bring back def
_.Ctrl_Underbar)); // bring back ghi
// startup edge condition
TestSetup(KeyMode.Emacs);
Test("abc", Keys(
"abc",
_.Ctrl_k,
_.Ctrl_u,
_.Ctrl_y));
}
[SkippableFact]
public void ShellKillWord()
{
TestSetup(KeyMode.Emacs,
new KeyHandler("Alt+d", PSConsoleReadLine.ShellKillWord));
Test("echo defabc", Keys(
_.Alt_d, // Test on empty input
"echo abc def",
Enumerable.Repeat(_.LeftArrow, 7),
_.Alt_d, // Kill 'abc'
_.End, _.Ctrl_y)); // Yank 'abc' at end of line
Test("echo foo", Keys("'a b c'echo foo", _.Home, _.Alt_d));
}
[SkippableFact]
public void ShellBackwardKillWord()
{
TestSetup(KeyMode.Emacs,
new KeyHandler("Alt+Backspace", PSConsoleReadLine.ShellBackwardKillWord));
Test("echo defabc ", Keys(
_.Alt_Backspace, // Test on empty line
"echo abc def",
Enumerable.Repeat(_.LeftArrow, 3),
_.Alt_Backspace, // Kill 'abc '
_.End, _.Ctrl_y)); // Yank 'abc ' at the end
Test("echo foo ", Keys("echo foo 'a b c'", _.Alt_Backspace));
}
[SkippableFact]
public void ExchangePointAndMark()
{
Skip.IfNot(KeyboardHasCtrlAt);
TestSetup(KeyMode.Emacs,
new KeyHandler("Ctrl+z", PSConsoleReadLine.ExchangePointAndMark));
var exchangePointAndMark = _.Ctrl_z;
var setMark = _.Ctrl_At;
Test("abcde", Keys(
"abcde",
exchangePointAndMark,
CheckThat(() => AssertCursorLeftIs(0)),
_.RightArrow,
setMark,
_.RightArrow,
_.RightArrow,
CheckThat(() => AssertCursorLeftIs(3)),
exchangePointAndMark,
CheckThat(() => AssertCursorLeftIs(1))
));
Test("abc", Keys(
"abc",
exchangePointAndMark,
CheckThat(() => AssertCursorLeftIs(0))
));
}
[SkippableFact]
public void YankLastNth()
{
TestSetup(KeyMode.Emacs);
SetHistory();
TestMustDing("", Keys(_.Ctrl_Alt_y));
SetHistory("echo a b c");
TestMustDing("", Keys(_.Alt_9, _.Ctrl_Alt_y));
SetHistory("echo a b c");
TestMustDing("", Keys(_.Alt_Minus, _.Alt_9, _.Ctrl_Alt_y));
// Test no argument, gets the first argument (not the command).
SetHistory("echo aa bb");
Test("aa", Keys(_.Ctrl_Alt_y));
// Test various arguments:
// * 0 - is the command
// * 2 - the second argument
// * -1 - the last argument
// * -2 - the second to last argument
SetHistory("echo aa bb cc 'zz zz $(1 2 3)'");
Test("echo bb 'zz zz $(1 2 3)' cc", Keys(
_.Alt_0, _.Ctrl_Alt_y, ' ',
_.Alt_2, _.Ctrl_Alt_y, ' ',
_.Alt_Minus, _.Escape, _.Ctrl_y, ' ',
_.Alt_Minus, _.Alt_2, _.Ctrl_Alt_y));
}
[SkippableFact]
public void YankLastArg()
{
TestSetup(KeyMode.Emacs);
SetHistory();
TestMustDing("", Keys(_.Alt_Period));
SetHistory("echo def");
Test("def", Keys(_.Alt_Period));
SetHistory("echo abc", "echo def");
Test("abc", Keys(_.Alt_Period, _.Alt_Period));
SetHistory("echo aa bb cc 'zz zz $(1 2 3)'");
Test("echo bb 'zz zz $(1 2 3)' cc", Keys(
_.Alt_0, _.Alt_Period, ' ',
_.Alt_2, _.Alt_Period, ' ',
_.Alt_Minus, _.Alt_Period, ' ',
_.Alt_Minus, _.Alt_2, _.Alt_Period));
SetHistory("echo a", "echo b");
TestMustDing("a", Keys(
_.Alt_Period, _.Alt_Period, _.Alt_Period));
SetHistory("echo a", "echo b");
TestMustDing("b", Keys(
_.Alt_Period, _.Alt_Period, _.Alt_Minus, _.Alt_Period, _.Alt_Period));
// Somewhat silly test to make sure invalid args are handled reasonably.
TestSetup(KeyMode.Emacs, new[] {new KeyHandler("Ctrl+z", (key,arg) => PSConsoleReadLine.YankLastArg(null, "zz"))});
SetHistory("echo a", "echo a");
TestMustDing("", Keys(_.Ctrl_z));
TestMustDing("a", Keys(_.Alt_Period, _.Ctrl_z));
}
[SkippableFact]
public void Paste()
{
TestSetup(KeyMode.Cmd);
SetClipboardText("pastetest1");
Test("pastetest1", Keys(_.Ctrl_v));
SetClipboardText("pastetest2");
Test("echo pastetest2", Keys(
"echo foobar", _.Ctrl_Shift_LeftArrow, _.Ctrl_v));
}
[SkippableFact]
public void Cut()
{
TestSetup(KeyMode.Cmd);
SetClipboardText("");
Test("", Keys(
"cuttest1", _.Ctrl_Shift_LeftArrow, _.Ctrl_x));
AssertClipboardTextIs("cuttest1");
}
[SkippableFact]
public void Copy()
{
TestSetup(KeyMode.Cmd);
SetClipboardText("");
Test("copytest1", Keys(
"copytest1", _.Ctrl_C));
AssertClipboardTextIs("copytest1");
SetClipboardText("");
Test("echo copytest2", Keys(
"echo copytest2", _.Ctrl_Shift_LeftArrow, _.Ctrl_C));
AssertClipboardTextIs("copytest2");
}
[SkippableFact]
public void CopyOrCancelLine()
{
TestSetup(KeyMode.Cmd);
SetClipboardText("");
Test("echo copytest2", Keys(
"echo copytest2", _.Ctrl_Shift_LeftArrow, _.Ctrl_c));
AssertClipboardTextIs("copytest2");
Test("", Keys("oops", _.Ctrl_c,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, "oops",
Tuple.Create(ConsoleColor.Red, _console.BackgroundColor), "^C")),
InputAcceptedNow));
}
[SkippableFact]
public void SelectBackwardChar()
{
TestSetup(KeyMode.Cmd);
Test("echo", Keys(
"eczz", _.Shift_LeftArrow,
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ecz", Selected("z"))),
_.Shift_LeftArrow,
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ec", Selected("zz"))),
_.Delete, "ho"));
}
[SkippableFact]
public void SelectForwardChar()
{
TestSetup(KeyMode.Cmd);
Test("echo", Keys(
"zzho", _.Home, _.Shift_RightArrow,
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Selected("z"), "zho")),
_.Shift_RightArrow,
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Selected("zz"), "ho")),
"ec"));
}
[SkippableFact]
public void SelectBackwardWord()
{
TestSetup(KeyMode.Cmd);
Test("echo bar", Keys(
"echo foo bar", _.Ctrl_LeftArrow, _.Ctrl_Shift_LeftArrow,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, "echo",
TokenClassification.None, " ",
Selected("foo "), "bar")),
_.Delete));
}
[SkippableFact]
public void SelectNextWord()
{
TestSetup(KeyMode.Cmd);
Test("echo bar", Keys(
"foo echo bar", _.Home, _.Ctrl_Shift_RightArrow,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("foo"),
TokenClassification.None, Selected(" "),
TokenClassification.None, "echo bar")),
_.Delete));
}
[SkippableFact]
public void SelectForwardWord()
{
TestSetup(KeyMode.Emacs);
Test(" echo bar", Keys(
"foo echo bar", _.Home, _.Alt_F,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("foo"),
TokenClassification.None, " echo bar")),
_.Delete));
}
[SkippableFact]
public void SelectShellForwardWord()
{
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+z", PSConsoleReadLine.SelectShellForwardWord));
Test(" echo bar", Keys(
"a\\b\\c echo bar", _.Home, _.Ctrl_z,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("a\\b\\c"),
TokenClassification.None, " echo bar")),
_.Delete));
}
[SkippableFact]
public void SelectShellNextWord()
{
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+z", PSConsoleReadLine.SelectShellNextWord));
Test("echo bar", Keys(
"a\\b\\c echo bar", _.Home, _.Ctrl_z,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("a\\b\\c "),
TokenClassification.None, "echo bar")),
_.Delete));
}
[SkippableFact]
public void SelectShellBackwardWord()
{
TestSetup(KeyMode.Cmd, new KeyHandler("Ctrl+z", PSConsoleReadLine.SelectShellBackwardWord));
Test("echo bar ", Keys(
"echo bar 'a b c'", _.Ctrl_z,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, "echo",
TokenClassification.None, " bar ",
TokenClassification.String, Selected("'a b c'"))),
_.Delete));
}
[SkippableFact]
public void SelectBackwardsLine()
{
TestSetup(KeyMode.Emacs);
Test("", Keys(
"echo foo", _.Shift_Home,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("echo foo"))),
_.Backspace));
}
[SkippableFact]
public void SelectLine()
{
TestSetup(KeyMode.Cmd);
Test("", Keys(
"echo foo", _.Home, _.Shift_End,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("echo foo"))),
_.Delete));
}
[SkippableFact]
public void SelectAll()
{
TestSetup(KeyMode.Cmd);
Test("", Keys(
"echo foo", _.Ctrl_a,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("echo foo"))),
_.Delete
));
Test("", Keys(
"echo foo", _.Ctrl_LeftArrow, _.Ctrl_a,
CheckThat(() => AssertScreenIs(1,
TokenClassification.Command, Selected("echo foo"))),
CheckThat(() => AssertCursorLeftIs(8)),
_.Delete
));
}
}
}
You can’t perform that action at this time.
