tracks/csharp/exercises/grep/GrepTest.cs in trackler-2.2.1.151 vs tracks/csharp/exercises/grep/GrepTest.cs in trackler-2.2.1.152
- old
+ new
@@ -1,361 +1,392 @@
-using System;
-using System.IO;
+// This file was auto-generated based on version 1.1.0 of the canonical data.
+
using Xunit;
+using System;
+using System.IO;
public class GrepTest : IDisposable
{
- private const string IliadFileName = "iliad.txt";
- private const string IliadContents =
- @"Achilles sing, O Goddess! Peleus' son;
-His wrath pernicious, who ten thousand woes
-Caused to Achaia's host, sent many a soul
-Illustrious into Ades premature,
-And Heroes gave (so stood the will of Jove)
-To dogs and to all ravening fowls a prey,
-When fierce dispute had separated once
-The noble Chief Achilles from the son
-Of Atreus, Agamemnon, King of men.
-";
-
- private const string MidsummerNightFileName = "midsummer-night.txt";
- private const string MidsummerNightContents =
- @"I do entreat your grace to pardon me.
-I know not by what power I am made bold,
-Nor how it may concern my modesty,
-In such a presence here to plead my thoughts;
-But I beseech your grace that I may know
-The worst that may befall me in this case,
-If I refuse to wed Demetrius.
-";
-
- private const string ParadiseLostFileName = "paradise-lost.txt";
- private const string ParadiseLostContents =
- @"Of Mans First Disobedience, and the Fruit
-Of that Forbidden Tree, whose mortal tast
-Brought Death into the World, and all our woe,
-With loss of Eden, till one greater Man
-Restore us, and regain the blissful Seat,
-Sing Heav'nly Muse, that on the secret top
-Of Oreb, or of Sinai, didst inspire
-That Shepherd, who first taught the chosen Seed
-";
-
- public GrepTest()
- {
- Directory.SetCurrentDirectory(Path.GetTempPath());
- File.WriteAllText(IliadFileName, IliadContents);
- File.WriteAllText(MidsummerNightFileName, MidsummerNightContents);
- File.WriteAllText(ParadiseLostFileName, ParadiseLostContents);
- }
-
- public void Dispose()
- {
- Directory.SetCurrentDirectory(Path.GetTempPath());
- File.Delete(IliadFileName);
- File.Delete(MidsummerNightFileName);
- File.Delete(ParadiseLostFileName);
- }
-
[Fact]
public void One_file_one_match_no_flags()
{
- const string pattern = "Agamemnon";
- const string flags = "";
- var files = new[] { IliadFileName };
-
- const string expected =
+ var pattern = "Agamemnon";
+ var flags = "";
+ var files = new[]
+ {
+ "iliad.txt"
+ };
+ var expected =
"Of Atreus, Agamemnon, King of men.\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_one_match_print_line_numbers_flag()
{
- const string pattern = "Forbidden";
- const string flags = "-n";
- var files = new[] { ParadiseLostFileName };
-
- const string expected =
+ var pattern = "Forbidden";
+ var flags = "-n";
+ var files = new[]
+ {
+ "paradise-lost.txt"
+ };
+ var expected =
"2:Of that Forbidden Tree, whose mortal tast\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_one_match_case_insensitive_flag()
{
- const string pattern = "Forbidden";
- const string flags = "-i";
- var files = new[] { ParadiseLostFileName };
-
- const string expected =
+ var pattern = "FORBIDDEN";
+ var flags = "-i";
+ var files = new[]
+ {
+ "paradise-lost.txt"
+ };
+ var expected =
"Of that Forbidden Tree, whose mortal tast\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_one_match_print_file_names_flag()
{
- const string pattern = "Forbidden";
- const string flags = "-l";
- var files = new[] { ParadiseLostFileName };
-
- var expected =
- $"{ParadiseLostFileName}\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "Forbidden";
+ var flags = "-l";
+ var files = new[]
+ {
+ "paradise-lost.txt"
+ };
+ var expected =
+ "paradise-lost.txt\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_one_match_match_entire_lines_flag()
{
- const string pattern = "With loss of Eden, till one greater Man";
- const string flags = "-x";
- var files = new[] { ParadiseLostFileName };
-
- const string expected =
+ var pattern = "With loss of Eden, till one greater Man";
+ var flags = "-x";
+ var files = new[]
+ {
+ "paradise-lost.txt"
+ };
+ var expected =
"With loss of Eden, till one greater Man\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_one_match_multiple_flags()
{
- const string pattern = "OF ATREUS, Agamemnon, KIng of MEN.";
- var files = new[] { IliadFileName };
- const string flags = "-n -i -x";
- const string expected =
+ var pattern = "OF ATREUS, Agamemnon, KIng of MEN.";
+ var flags = "-n -i -x";
+ var files = new[]
+ {
+ "iliad.txt"
+ };
+ var expected =
"9:Of Atreus, Agamemnon, King of men.\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_no_flags()
{
- const string pattern = "may";
- const string flags = "";
- var files = new[] { MidsummerNightFileName };
-
- const string expected =
+ var pattern = "may";
+ var flags = "";
+ var files = new[]
+ {
+ "midsummer-night.txt"
+ };
+ var expected =
"Nor how it may concern my modesty,\n" +
"But I beseech your grace that I may know\n" +
"The worst that may befall me in this case,\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_print_line_numbers_flag()
{
- const string pattern = "may";
- const string flags = "-n";
- var files = new[] { MidsummerNightFileName };
-
- const string expected =
+ var pattern = "may";
+ var flags = "-n";
+ var files = new[]
+ {
+ "midsummer-night.txt"
+ };
+ var expected =
"3:Nor how it may concern my modesty,\n" +
"5:But I beseech your grace that I may know\n" +
"6:The worst that may befall me in this case,\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_match_entire_lines_flag()
{
- const string pattern = "may";
- const string flags = "-x";
- var files = new[] { MidsummerNightFileName };
-
- const string expected = "";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "may";
+ var flags = "-x";
+ var files = new[]
+ {
+ "midsummer-night.txt"
+ };
+ var expected = "";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_case_insensitive_flag()
{
- const string pattern = "ACHILLES";
- const string flags = "-i";
- var files = new[] { IliadFileName };
-
- const string expected =
+ var pattern = "ACHILLES";
+ var flags = "-i";
+ var files = new[]
+ {
+ "iliad.txt"
+ };
+ var expected =
"Achilles sing, O Goddess! Peleus' son;\n" +
"The noble Chief Achilles from the son\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void One_file_several_matches_inverted_flag()
{
- const string pattern = "Of";
- const string flags = "-v";
- var files = new[] { ParadiseLostFileName };
-
- const string expected =
+ var pattern = "Of";
+ var flags = "-v";
+ var files = new[]
+ {
+ "paradise-lost.txt"
+ };
+ var expected =
"Brought Death into the World, and all our woe,\n" +
"With loss of Eden, till one greater Man\n" +
"Restore us, and regain the blissful Seat,\n" +
"Sing Heav'nly Muse, that on the secret top\n" +
"That Shepherd, who first taught the chosen Seed\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
- [Theory(Skip = "Remove to run test")]
- [InlineData("")]
- [InlineData("-n")]
- [InlineData("-l")]
- [InlineData("-x")]
- [InlineData("-i")]
- [InlineData("-n -l -x -i")]
- public void One_file_no_matches_various_flags(string flags)
+ [Fact(Skip = "Remove to run test")]
+ public void One_file_no_matches_various_flags()
{
- const string pattern = "Gandalf";
- var files = new[] { IliadFileName };
- const string expected = "";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "Gandalf";
+ var flags = "-n -l -x -i";
+ var files = new[]
+ {
+ "iliad.txt"
+ };
+ var expected = "";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_one_match_no_flags()
{
- const string pattern = "Agamemnon";
- const string flags = "";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{IliadFileName}:Of Atreus, Agamemnon, King of men.\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "Agamemnon";
+ var flags = "";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "iliad.txt:Of Atreus, Agamemnon, King of men.\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_no_flags()
{
- const string pattern = "may";
- const string flags = "";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{MidsummerNightFileName}:Nor how it may concern my modesty,\n" +
- $"{MidsummerNightFileName}:But I beseech your grace that I may know\n" +
- $"{MidsummerNightFileName}:The worst that may befall me in this case,\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "may";
+ var flags = "";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "midsummer-night.txt:Nor how it may concern my modesty,\n" +
+ "midsummer-night.txt:But I beseech your grace that I may know\n" +
+ "midsummer-night.txt:The worst that may befall me in this case,\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_print_line_numbers_flag()
{
- const string pattern = "that";
- const string flags = "-n";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{MidsummerNightFileName}:5:But I beseech your grace that I may know\n" +
- $"{MidsummerNightFileName}:6:The worst that may befall me in this case,\n" +
- $"{ParadiseLostFileName}:2:Of that Forbidden Tree, whose mortal tast\n" +
- $"{ParadiseLostFileName}:6:Sing Heav'nly Muse, that on the secret top\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "that";
+ var flags = "-n";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "midsummer-night.txt:5:But I beseech your grace that I may know\n" +
+ "midsummer-night.txt:6:The worst that may befall me in this case,\n" +
+ "paradise-lost.txt:2:Of that Forbidden Tree, whose mortal tast\n" +
+ "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
- public void Multiple_files_several_matches_print_file_names_flag()
+ public void Multiple_files_one_match_print_file_names_flag()
{
- const string pattern = "who";
- const string flags = "-l";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{IliadFileName}\n" +
- $"{ParadiseLostFileName}\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "who";
+ var flags = "-l";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "iliad.txt\n" +
+ "paradise-lost.txt\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_case_insensitive_flag()
{
- const string pattern = "TO";
- const string flags = "-i";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{IliadFileName}:Caused to Achaia's host, sent many a soul\n" +
- $"{IliadFileName}:Illustrious into Ades premature,\n" +
- $"{IliadFileName}:And Heroes gave (so stood the will of Jove)\n" +
- $"{IliadFileName}:To dogs and to all ravening fowls a prey,\n" +
- $"{MidsummerNightFileName}:I do entreat your grace to pardon me.\n" +
- $"{MidsummerNightFileName}:In such a presence here to plead my thoughts;\n" +
- $"{MidsummerNightFileName}:If I refuse to wed Demetrius.\n" +
- $"{ParadiseLostFileName}:Brought Death into the World, and all our woe,\n" +
- $"{ParadiseLostFileName}:Restore us, and regain the blissful Seat,\n" +
- $"{ParadiseLostFileName}:Sing Heav'nly Muse, that on the secret top\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "TO";
+ var flags = "-i";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "iliad.txt:Caused to Achaia's host, sent many a soul\n" +
+ "iliad.txt:Illustrious into Ades premature,\n" +
+ "iliad.txt:And Heroes gave (so stood the will of Jove)\n" +
+ "iliad.txt:To dogs and to all ravening fowls a prey,\n" +
+ "midsummer-night.txt:I do entreat your grace to pardon me.\n" +
+ "midsummer-night.txt:In such a presence here to plead my thoughts;\n" +
+ "midsummer-night.txt:If I refuse to wed Demetrius.\n" +
+ "paradise-lost.txt:Brought Death into the World, and all our woe,\n" +
+ "paradise-lost.txt:Restore us, and regain the blissful Seat,\n" +
+ "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_several_matches_inverted_flag()
{
- const string pattern = "a";
- const string flags = "-v";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{IliadFileName}:Achilles sing, O Goddess! Peleus' son;\n" +
- $"{IliadFileName}:The noble Chief Achilles from the son\n" +
- $"{MidsummerNightFileName}:If I refuse to wed Demetrius.\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "a";
+ var flags = "-v";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "iliad.txt:Achilles sing, O Goddess! Peleus' son;\n" +
+ "iliad.txt:The noble Chief Achilles from the son\n" +
+ "midsummer-night.txt:If I refuse to wed Demetrius.\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_one_match_match_entire_lines_flag()
{
- const string pattern = "But I beseech your grace that I may know";
- const string flags = "-x";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
-
- var expected =
- $"{MidsummerNightFileName}:But I beseech your grace that I may know\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "But I beseech your grace that I may know";
+ var flags = "-x";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "midsummer-night.txt:But I beseech your grace that I may know\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
[Fact(Skip = "Remove to run test")]
public void Multiple_files_one_match_multiple_flags()
{
- const string pattern = "WITH LOSS OF EDEN, TILL ONE GREATER MAN";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
- const string flags = "-n -i -x";
- var expected =
- $"{ParadiseLostFileName}:4:With loss of Eden, till one greater Man\n";
-
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ var pattern = "WITH LOSS OF EDEN, TILL ONE GREATER MAN";
+ var flags = "-n -i -x";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected =
+ "paradise-lost.txt:4:With loss of Eden, till one greater Man\n";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
}
- [Theory(Skip = "Remove to run test")]
- [InlineData("")]
- [InlineData("-n")]
- [InlineData("-l")]
- [InlineData("-x")]
- [InlineData("-i")]
- [InlineData("-n -l -x -i")]
- public void Multiple_files_no_matches_various_flags(string flags)
+ [Fact(Skip = "Remove to run test")]
+ public void Multiple_files_no_matches_various_flags()
{
- const string pattern = "Frodo";
- var files = new[] { IliadFileName, MidsummerNightFileName, ParadiseLostFileName };
+ var pattern = "Frodo";
+ var flags = "-n -l -x -i";
+ var files = new[]
+ {
+ "iliad.txt",
+ "midsummer-night.txt",
+ "paradise-lost.txt"
+ };
+ var expected = "";
+ Assert.Equal(expected, Grep.Match(pattern, flags, files));
+ }
- const string expected = "";
+ private const string IliadFileName = "iliad.txt";
+ private const string IliadContents =
+ "Achilles sing, O Goddess! Peleus' son;\n" +
+ "His wrath pernicious, who ten thousand woes\n" +
+ "Caused to Achaia's host, sent many a soul\n" +
+ "Illustrious into Ades premature,\n" +
+ "And Heroes gave (so stood the will of Jove)\n" +
+ "To dogs and to all ravening fowls a prey,\n" +
+ "When fierce dispute had separated once\n" +
+ "The noble Chief Achilles from the son\n" +
+ "Of Atreus, Agamemnon, King of men.\n";
- Assert.Equal(expected, Grep.Find(pattern, flags, files));
+ private const string MidsummerNightFileName = "midsummer-night.txt";
+ private const string MidsummerNightContents =
+ "I do entreat your grace to pardon me.\n" +
+ "I know not by what power I am made bold,\n" +
+ "Nor how it may concern my modesty,\n" +
+ "In such a presence here to plead my thoughts;\n" +
+ "But I beseech your grace that I may know\n" +
+ "The worst that may befall me in this case,\n" +
+ "If I refuse to wed Demetrius.\n";
+
+ private const string ParadiseLostFileName = "paradise-lost.txt";
+ private const string ParadiseLostContents =
+ "Of Mans First Disobedience, and the Fruit\n" +
+ "Of that Forbidden Tree, whose mortal tast\n" +
+ "Brought Death into the World, and all our woe,\n" +
+ "With loss of Eden, till one greater Man\n" +
+ "Restore us, and regain the blissful Seat,\n" +
+ "Sing Heav'nly Muse, that on the secret top\n" +
+ "Of Oreb, or of Sinai, didst inspire\n" +
+ "That Shepherd, who first taught the chosen Seed\n";
+
+ public GrepTest()
+ {
+ Directory.SetCurrentDirectory(Path.GetTempPath());
+ File.WriteAllText(IliadFileName, IliadContents);
+ File.WriteAllText(MidsummerNightFileName, MidsummerNightContents);
+ File.WriteAllText(ParadiseLostFileName, ParadiseLostContents);
+ }
+
+ public void Dispose()
+ {
+ Directory.SetCurrentDirectory(Path.GetTempPath());
+ File.Delete(IliadFileName);
+ File.Delete(MidsummerNightFileName);
+ File.Delete(ParadiseLostFileName);
}
}
\ No newline at end of file