public void RegularExpressions_Characters_SpaceCharacter() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"not\sa\sstory\sthe\sJedi\swould\stell\syou"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_LookArounds_PositiveLookBehind_BeforeMatch() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsTwo.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"(?<=USD)\d{3}"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_LookArounds_NegativeLookAhead_AfterMatch() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsTwo.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"\d+(?!\d| dollars)"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Any()); }
public void RegularExpressions_Logic_BackReferenceByName() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"I thought not(?<Cap>\.).*\k<Cap>"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_Boundaries_Word_Negative() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"power\B"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 2); }
public void RegularExpressions_Quantifiers_ZeroOrMore() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"He became so powerful\.\.\.[Z]* the only thing"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_Logic_OR() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"I(t's| thought) not"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 2); }
public void RegularExpressions_Characters_Digit() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"\d\d\d\d"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_Characters_NewLine() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"story the Jedi would tell you\.[\r\n\s]*It's a Sith"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void IgnoreBreaks_FlagMiddle_FlagShort() { string TestFilePath = Path.Combine(TestDataDirectory, "IgnoreBreaks.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "quick.*brown"; string Command = $"-f '{TestFilePath}' {_FlagDescriptorShort} {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void IgnoreBreaks_StartOfLineToEndOfLine_NoFlag() { string TestFilePath = Path.Combine(TestDataDirectory, "IgnoreBreaks.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "^a.*$"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 3); }
public void IgnoreBreaks_FlagFirst_FlagLong_SpaceReplace() { string TestFilePath = Path.Combine(TestDataDirectory, "IgnoreBreaks.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "quick brown"; string Command = $"{_FlagDescriptorLong} -f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 1); }
public void Write_FlagMiddle_FlagShort() { string TestFilePath = Path.Combine(TestDataDirectory, "Write.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "quick brown"; string Command = $"-f '{TestFilePath}' {_FlagDescriptorShort} '{_testOutputFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(File.Exists(_testOutputFilePath)); Assert.IsTrue(FileHasData(_testOutputFilePath)); File.Delete(_testOutputFilePath); }
public void RegularExpressions_Quantifiers_OnceOrNone() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); // Postive test string SearchTerm = @"He became so power[f]?ul\.\.\. the only thing"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); // Negative test SearchTerm = @"He became so powerful[\.]? the only thing"; Command = $"-f '{TestFilePath}' {SearchTerm}"; GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 0); }
public void RegularExpressions_Quantifiers_OneOrMoreLazy() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); // 1 string SearchTerm = @"He became so powerful[\.]+? the only thing"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); // 2 SearchTerm = @"He became so powerful[\.]+?"; Command = $"-f '{TestFilePath}' {SearchTerm}"; GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString == @"He became so powerful.") == 1); }
public void RegularExpressions_CharacterClasses_CharacterRange() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); // 1 string SearchTerm = @"the only [a-z\s]* afraid"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); // 2 SearchTerm = @"so powerful[a-z\s]* he was afraid"; Command = $"-f '{TestFilePath}' {SearchTerm}"; GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 0); }