8000 Adding more tests from C# side for simple and allmatch · powercode/PowerShell@818249a · GitHub
[go: up one dir, main page]

Skip to content

Commit 818249a

Browse files
committed
Adding more tests from C# side for simple and allmatch
1 parent 564a642 commit 818249a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/xUnit/csharp/test_SelectString.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
using System.IO;
88
using System.IO.MemoryMappedFiles;
99
using System.Linq;
10+
using System.Management.Automation;
1011
using System.Net.Http;
1112
using System.Text;
1213
using System.Text.RegularExpressions;
1314
using System.Threading;
15+
using Microsoft.PowerShell.Commands;
1416
using Xunit;
1517

1618
namespace PSTests.Parallel;
@@ -158,4 +160,71 @@ most other parts of the world at no cost and with almost no restrictions
158160

159161
Assert.Equal(expectedRanges, actualRanges);
160162
}
163+
164+
[Fact]
165+
public void RunSelectStringOnWarAndPeace()
166+
{
167+
using var ps = PowerShell.Create();
168+
ps.AddScript("$PSStyle.OutputRendering = 'Ansi'");
169+
ps.AddStatement();
170+
ps.Commands.AddCommand("Select-String")
171+
.AddParameter(nameof(SelectStringCommand.LiteralPath), _filePath)
172+
.AddParameter(nameof(SelectStringCommand.Pattern), @"\b(Gutenberg|the)\b")
173+
.AddParameter(nameof(SelectStringCommand.AllMatches));
174+
ps.Commands.AddCommand("Out-String");
175+
var res = ps.Invoke<string>();
176+
var errors = ps.Streams.Error.ReadAll();
177+
Assert.Empty(errors);
178+
}
179+
180+
[Fact]
181+
public void ShouldOnlyReturnTheCaseSensitiveMatch()
182+
{
183+
using var ps = PowerShell.Create();
184+
ps.AddScript("$PSStyle.OutputRendering = 'Ansi'");
185+
ps.AddStatement();
186+
ps.Commands.AddCommand("Select-String")
187+
.AddParameter(nameof(SelectStringCommand.CaseSensitive))
188+
.AddParameter(nameof(SelectStringCommand.Pattern), @"hello");
189+
string[] input = ["hello", "Hello"];
190+
var res = ps.Invoke<MatchInfo>(input);
191+
var match = Assert.Single(res);
192+
Assert.Equal("hello", match.ToString());
193+
}
194+
195+
[Fact]
196+
public void AllMatch()
197+
{
198+
199+
using var ps = PowerShell.Create();
200+
ps.AddScript("$PSStyle.OutputRendering = 'Ansi'");
201+
ps.AddStatement();
202+
ps.Commands.AddCommand("Select-String")
203+
.AddParameter(nameof(SelectStringCommand.AllMatches))
204+
.AddParameter(nameof(SelectStringCommand.Pattern), @"l");
205+
ps.Commands.AddCommand("Out-String");
206+
string[] input = ["hello", "Hello", "goodbye"];
207+
var res = ps.Invoke<string>(input).First();
208+
var nl = Environment.NewLine;
209+
string expected = $"{nl}he\e[7ml\e[0m\e[7ml\e[0mo{nl}He\e[7ml\e[0m\e[7ml\e[0mo{nl}{nl}";
210+
Assert.Equal(expected, res);
211+
}
212+
213+
[Fact]
214+
public void SimpleMatch()
215+
{
216+
217+
using var ps = PowerShell.Create();
218+
ps.AddScript("$PSStyle.OutputRendering = 'Ansi'");
219+
ps.AddStatement();
220+
ps.Commands.AddCommand("Select-String")
221+
.AddParameter(nameof(SelectStringCommand.SimpleMatch))
222+
.AddParameter(nameof(SelectStringCommand.Pattern), @"l");
223+
ps.Commands.AddCommand("Out-String");
224+
string[] input = ["hello", "Hello", "goodbye"];
225+
var res = ps.Invoke<string>(input).First();
226+
var nl = Environment.NewLine;
227+
string expected = $"{nl}he\e[7ml\e[0mlo{nl}He\e[7ml\e[0mlo{nl}{nl}";
228+
Assert.Equal(expected, res);
229+
}
161230
}

0 commit comments

Comments
 (0)
0