Skip to content

Commit 6de89cc

Browse files
committed
Fix selection tests
1 parent 9568c8a commit 6de89cc

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

UnitTestPSReadLine/KillYankTest.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ public void TestSelectBackwardChar()
363363

364364
Test("echo", Keys(
365365
"eczz", _.ShiftLeftArrow,
366-
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ecz", Inverted, "z", Inverted)),
366+
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ecz", Selected("z"))),
367367
_.ShiftLeftArrow,
368-
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ec", Inverted, "zz", Inverted)),
368+
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "ec", Selected("zz"))),
369369
_.Delete, "ho"));
370370
}
371371

@@ -376,9 +376,9 @@ public void TestSelectForwardChar()
376376

377377
Test("echo", Keys(
378378
"zzho", _.Home, _.ShiftRightArrow,
379-
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Inverted, "z", Inverted, "zho")),
379+
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Selected("z"), "zho")),
380380
_.ShiftRightArrow,
381-
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Inverted, "zz", Inverted, "ho")),
381+
CheckThat(() => AssertScreenIs(1, TokenClassification.Command, Selected("zz"), "ho")),
382382
"ec"));
383383
}
384384

@@ -392,7 +392,7 @@ public void TestSelectBackwardWord()
392392
CheckThat(() => AssertScreenIs(1,
393393
TokenClassification.Command, "echo",
394394
TokenClassification.None, " ",
395-
Inverted, "foo ", Inverted, "bar")),
395+
Selected("foo "), "bar")),
396396
_.Delete));
397397
}
398398

@@ -404,8 +404,8 @@ public void TestSelectNextWord()
404404
Test("echo bar", Keys(
405405
"foo echo bar", _.Home, _.CtrlShiftRightArrow,
406406
CheckThat(() => AssertScreenIs(1,
407-
TokenClassification.Command, Inverted, "foo",
408-
TokenClassification.None, Inverted, " ", Inverted,
407+
TokenClassification.Command, Selected("foo"),
408+
TokenClassification.None, Selected(" "),
409409
TokenClassification.None, "echo bar")),
410410
_.Delete));
411411
}
@@ -418,7 +418,7 @@ public void TestSelectForwardWord()
418418
Test(" echo bar", Keys(
419419
"foo echo bar", _.Home, _.AltShiftF,
420420
CheckThat(() => AssertScreenIs(1,
421-
TokenClassification.Command, Inverted, "foo", Inverted,
421+
TokenClassification.Command, Selected("foo"),
422422
TokenClassification.None, " echo bar")),
423423
_.Delete));
424424
}
@@ -431,7 +431,7 @@ public void TestSelectShellForwardWord()
431431
Test(" echo bar", Keys(
432432
"a\\b\\c echo bar", _.Home, _.CtrlZ,
433433
CheckThat(() => AssertScreenIs(1,
434-
TokenClassification.Command, Inverted, "a\\b\\c", Inverted,
434+
TokenClassification.Command, Selected("a\\b\\c"),
435435
TokenClassification.None, " echo bar")),
436436
_.Delete));
437437
}
@@ -444,8 +444,7 @@ public void TestSelectShellNextWord()
444444
Test("echo bar", Keys(
445445
"a\\b\\c echo bar", _.Home, _.CtrlZ,
446446
CheckThat(() => AssertScreenIs(1,
447-
TokenClassification.Command, Inverted, "a\\b\\c",
448-
TokenClassification.None, Inverted, " ",
447+
TokenClassification.Command, Selected("a\\b\\c "),
449448
TokenClassification.None, "echo bar")),
450449
_.Delete));
451450
}
@@ -460,7 +459,7 @@ public void TestSelectShellBackwardWord()
460459
CheckThat(() => AssertScreenIs(1,
461460
TokenClassification.Command, "echo",
462461
TokenClassification.None, " bar ",
463-
TokenClassification.String, Inverted, "'a b c'")),
462+
TokenClassification.String, Selected("'a b c'"))),
464463
_.Delete));
465464
}
466465

@@ -472,8 +471,7 @@ public void TestSelectBackwardsLine()
472471
Test("", Keys(
473472
"echo foo", _.ShiftHome,
474473
CheckThat(() => AssertScreenIs(1,
475-
TokenClassification.Command, Inverted, "echo",
476-
TokenClassification.None, Inverted, " foo")),
474+
TokenClassification.Command, Selected("echo foo"))),
477475
_.Backspace));
478476
}
479477

@@ -485,8 +483,7 @@ public void TestSelectLine()
485483
Test("", Keys(
486484
"echo foo", _.Home, _.ShiftEnd,
487485
CheckThat(() => AssertScreenIs(1,
488-
TokenClassification.Command, Inverted, "echo",
489-
TokenClassification.None, Inverted, " foo")),
486+
TokenClassification.Command, Selected("echo foo"))),
490487
_.Delete));
491488
}
492489

@@ -498,16 +495,14 @@ public void TestSelectAll()
498495
Test("", Keys(
499496
"echo foo", _.CtrlA,
500497
CheckThat(() => AssertScreenIs(1,
501-
TokenClassification.Command, Inverted, "echo",
502-
TokenClassification.None, Inverted, " foo")),
498+
TokenClassification.Command, Selected("echo foo"))),
503499
_.Delete
504500
));
505501

506502
Test("", Keys(
507503
"echo foo", _.CtrlLeftArrow, _.CtrlA,
508504
CheckThat(() => AssertScreenIs(1,
509-
TokenClassification.Command, Inverted, "echo",
510-
TokenClassification.None, Inverted, " foo")),
505+
TokenClassification.Command, Selected("echo foo"))),
511506
CheckThat(() => AssertCursorLeftIs(8)),
512507
_.Delete
513508
));

UnitTestPSReadLine/UnitTestReadLine.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ private static void ToggleNegative(TestConsole c, bool b)
326326
c.Negative = b;
327327
}
328328
private static readonly Dictionary<string, Action<TestConsole>> EscapeSequenceActions = new Dictionary<string, Action<TestConsole>> {
329+
{"\x1b[30;47m", c => {
330+
c.ForegroundColor = ConsoleColor.Black;
331+
c.BackgroundColor = ConsoleColor.Gray; } },
329332
{"\x1b[7m", c => ToggleNegative(c, true) },
330333
{"\x1b[27m", c => ToggleNegative(c, false) },
331334
{"\x1b[40m", c => c.BackgroundColor = ConsoleColor.Black},
@@ -577,8 +580,8 @@ private static void ExecuteOnSTAThread(Action action)
577580
private class NextLineToken { }
578581
static readonly NextLineToken NextLine = new NextLineToken();
579582

580-
private class InvertedToken { }
581-
static readonly InvertedToken Inverted = new InvertedToken();
583+
private class SelectionToken { public string _text; }
584+
private static SelectionToken Selected(string s) { return new SelectionToken {_text = s}; }
582585

583586
private CHAR_INFO[] CreateCharInfoBuffer(int lines, params object[] items)
584587
{
@@ -594,10 +597,9 @@ private CHAR_INFO[] CreateCharInfoBuffer(int lines, params object[] items)
594597
result.Add(new CHAR_INFO((char)item, fg, bg));
595598
continue;
596599
}
597-
if (item is InvertedToken)
600+
if (item is SelectionToken st)
598601
{
599-
fg = (ConsoleColor)((int)fg ^ 7);
600-
bg = (ConsoleColor)((int)bg ^ 7);
602+
result.AddRange(st._text.Select(c => new CHAR_INFO(c, ConsoleColor.Black, ConsoleColor.Gray)));
601603
continue;
602604
}
603605
if (item is NextLineToken)

0 commit comments

Comments
 (0)