|
1 | | -using Microsoft.PowerShell; |
| 1 | +using System; |
| 2 | +using Microsoft.PowerShell; |
2 | 3 | using Xunit; |
3 | 4 |
|
4 | 5 | namespace Test |
@@ -56,31 +57,114 @@ public void ViSearchHistory() |
56 | 57 |
|
57 | 58 | // Clear history in case the above added some history (but it shouldn't) |
58 | 59 | SetHistory(); |
59 | | - Test( " ", Keys( ' ', _.UpArrow, _.DownArrow ) ); |
60 | | - |
61 | | - SetHistory( "dosomething", "this way", "that way", "anyway", "no way", "yah way" ); |
| 60 | + Test(" ", Keys(' ', _.UpArrow, _.DownArrow)); |
62 | 61 |
|
63 | | - Test( "dosomething", Keys( |
64 | | - _.Escape, _.Slash, "some", _.Enter, CheckThat( () => AssertLineIs( "dosomething" ) ), |
65 | | - _.Question, "yah", _.Enter, CheckThat( () => AssertLineIs( "yah way" ) ), |
66 | | - _.Slash, "some", _.Enter, 'h' // need 'h' here to avoid bogus failure |
67 | | - ) ); |
| 62 | + var emphasisColors = Tuple.Create(PSConsoleReadLineOptions.DefaultEmphasisColor, _console.BackgroundColor); |
| 63 | + var statusColors = Tuple.Create(_console.ForegroundColor, _console.BackgroundColor); |
68 | 64 |
|
69 | 65 | SetHistory("dosomething", "this way", "that way", "anyway", "no way", "yah way"); |
70 | 66 |
|
71 | 67 | Test("dosomething", Keys( |
72 | | - _.Escape, _.Ctrl_r, "some", _.Enter, CheckThat(() => AssertLineIs("dosomething")), |
73 | | - _.Ctrl_s, "yah", _.Enter, CheckThat(() => AssertLineIs("yah way")), |
74 | | - _.Ctrl_r, "some", _.Enter, 'h' // need 'h' here to avoid bogus failure |
| 68 | + _.Escape, _.Slash, "some", _.Enter, CheckThat(() => AssertLineIs("dosomething")), |
| 69 | + _.Question, "yah", _.Enter, CheckThat(() => AssertLineIs("yah way")), |
| 70 | + _.Slash, "some", _.Enter, 'h' // need 'h' here to avoid bogus failure |
75 | 71 | )); |
76 | 72 |
|
77 | | - SetHistory("dosomething", "this way", "that way", "anyway", "no way", "yah way"); |
78 | | - |
79 | | - Test("dosomething", Keys( |
80 | | - _.Ctrl_r, "some", _.Enter, CheckThat(() => AssertLineIs("dosomething")), |
81 | | - _.Ctrl_s, "yah", _.Enter, CheckThat(() => AssertLineIs("yah way")), |
82 | | - _.Ctrl_r, "some", _.Enter, _.Escape // new esc here to avoid bogus failure |
83 | | - )); |
| 73 | + SetHistory("someway", "noway", "yahway"); |
| 74 | + |
| 75 | + Test("yahway", Keys( |
| 76 | + // Change to Command mode. |
| 77 | + _.Escape, |
| 78 | + _.Ctrl_r, "way", |
| 79 | + CheckThat(() => AssertScreenIs(2, |
| 80 | + TokenClassification.Command, "yah", |
| 81 | + emphasisColors, "way", |
| 82 | + NextLine, |
| 83 | + statusColors, "bck-i-search: way_")), |
| 84 | + _.Ctrl_r, |
| 85 | + CheckThat(() => AssertScreenIs(2, |
| 86 | + TokenClassification.Command, "no", |
| 87 | + emphasisColors, "way", |
| 88 | + NextLine, |
| 89 | + statusColors, "bck-i-search: way_")), |
| 90 | + _.Ctrl_r, |
| 91 | + CheckThat(() => AssertScreenIs(2, |
| 92 | + TokenClassification.Command, "some", |
| 93 | + emphasisColors, "way", |
| 94 | + NextLine, |
| 95 | + statusColors, "bck-i-search: way_")), |
| 96 | + _.Ctrl_s, |
| 97 | + CheckThat(() => AssertScreenIs(2, |
| 98 | + TokenClassification.Command, "no", |
| 99 | + emphasisColors, "way", |
| 100 | + NextLine, |
| 101 | + statusColors, "fwd-i-search: way_")), |
| 102 | + _.Ctrl_s, |
| 103 | + CheckThat(() => AssertScreenIs(2, |
| 104 | + TokenClassification.Command, "yah", |
| 105 | + emphasisColors, "way", |
| 106 | + NextLine, |
| 107 | + statusColors, "fwd-i-search: way_")), |
| 108 | + _.Ctrl_s, |
| 109 | + CheckThat(() => AssertScreenIs(2, |
| 110 | + TokenClassification.Command, "yahway", |
| 111 | + NextLine, |
| 112 | + statusColors, "failed-fwd-i-search: way_")), |
| 113 | + |
| 114 | + // Abort the history search. |
| 115 | + _.Ctrl_g, CheckThat(() => AssertLineIs(string.Empty)), |
| 116 | + // Search again and escape from the search. |
| 117 | + _.Ctrl_r, "yah", |
| 118 | + _.Escape, CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "yahway")), |
| 119 | + // We should not be able to edit the line, because we are in Command mode. |
| 120 | + "nnn")); |
| 121 | + |
| 122 | + SetHistory("someway", "noway", "yahway"); |
| 123 | + |
| 124 | + Test("nnnyahway", Keys( |
| 125 | + _.Ctrl_r, "way", |
| 126 | + CheckThat(() => AssertScreenIs(2, |
| 127 | + TokenClassification.Command, "yah", |
| 128 | + emphasisColors, "way", |
| 129 | + NextLine, |
| 130 | + statusColors, "bck-i-search: way_")), |
| 131 | + _.Ctrl_r, |
| 132 | + CheckThat(() => AssertScreenIs(2, |
| 133 | + TokenClassification.Command, "no", |
| 134 | + emphasisColors, "way", |
| 135 | + NextLine, |
| 136 | + statusColors, "bck-i-search: way_")), |
| 137 | + _.Ctrl_r, |
| 138 | + CheckThat(() => AssertScreenIs(2, |
| 139 | + TokenClassification.Command, "some", |
| 140 | + emphasisColors, "way", |
| 141 | + NextLine, |
| 142 | + statusColors, "bck-i-search: way_")), |
| 143 | + _.Ctrl_s, |
| 144 | + CheckThat(() => AssertScreenIs(2, |
| 145 | + TokenClassification.Command, "no", |
| 146 | + emphasisColors, "way", |
| 147 | + NextLine, |
| 148 | + statusColors, "fwd-i-search: way_")), |
| 149 | + _.Ctrl_s, |
| 150 | + CheckThat(() => AssertScreenIs(2, |
| 151 | + TokenClassification.Command, "yah", |
| 152 | + emphasisColors, "way", |
| 153 | + NextLine, |
| 154 | + statusColors, "fwd-i-search: way_")), |
| 155 | + _.Ctrl_s, |
| 156 | + CheckThat(() => AssertScreenIs(2, |
| 157 | + TokenClassification.Command, "yahway", |
| 158 | + NextLine, |
| 159 | + statusColors, "failed-fwd-i-search: way_")), |
| 160 | + |
| 161 | + // Abort the history search. |
| 162 | + _.Ctrl_g, CheckThat(() => AssertLineIs(string.Empty)), |
| 163 | + // Search again and escape from the search. |
| 164 | + _.Ctrl_r, "yah", |
| 165 | + _.Escape, CheckThat(() => AssertScreenIs(1, TokenClassification.Command, "yahway")), |
| 166 | + // We should be able to edit the line, because we are in Edit mode. |
| 167 | + "nnn")); |
84 | 168 | } |
85 | 169 |
|
86 | 170 | [SkippableFact] |
|
0 commit comments