static void Main(string[] args) { // ReadMe if (args.Length == 0) { string ReadMe = Properties.Resources.ReadMe; Console.WriteLine(ReadMe + Environment.NewLine); } do { string Command = args.Length == 0 ? Console.ReadLine() : string.Join(" ", args); if (Command.Length > 0) { try { GrepResultCollection grepResultCollection = new GrepResultCollection(); grepResultCollection.ItemsAdded += OnResultsAdded; GrepEngine.RunCommand(Command, grepResultCollection); } catch (Exception ex) { Console.WriteLine(ex.Message + Environment.NewLine); } } }while (args.Length == 0); }
public void Replace_FlagFirst_FlagShort_DoubleQuotes() { try { CreateTestFiles(); string SearchTerm = "quick brown fox"; string ReplaceText = "slow green turtle"; string Command = $"{_FlagDescriptorShort} \"{ReplaceText}\" -d '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); // Assert there are no files returned in the grep collection whose text doesn't match the expected text Assert.IsFalse(GrepResultCollection.Where(result => File.ReadAllText(result.SourceFile) != _TestFileExpectedResultText).Any()); } catch { throw; } finally { DeleteTestFiles(); } }
public void FileNamesOnly_FlagFirst_FlagLong_MultiResult() { string SearchTerm = "FileNamesOnly"; string Command = $"{_FlagDescriptorLong} -d '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 4); }
public void ChainCommands_Two() { string SearchTerm = "fox jumps over"; string Command = $"-d '{TestDataDirectory}' -k ChainCommands | -r -i {SearchTerm} | -k Two"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void Recursive_FlagFirst_FlagShort() { string SearchTerm = "quick brown fox"; string Command = $"{_FlagDescriptorShort} -d '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 2); }
public void IgnoreCase_FlagMiddle_FlagLong() { string SearchTerm = "quick brown fox"; string Command = $"-d '{TestDataDirectory}' {_FlagDescriptorLong} {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 2); }
public void Directory_FlagFirst_FlagLong_DoubleQuotes() { string SearchTerm = "fox"; string Command = $"{_FlagDescriptorLong} \"{TestDataDirectory}\" {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 2); }
public void Directory_FlagMiddle_FlagShort_SingleQuotes() { string SearchTerm = "fox"; string Command = $"-i {_FlagDescriptorShort} '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 2); }
public void FileNamesOnly_FlagLast_FlagShort_SingleResult() { string SearchTerm = "One"; string Command = $"{SearchTerm} {_FlagDescriptorShort} -d '{TestDataDirectory}'"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 1); }
public void FileTypeInclusion_FlagMiddle_FlagShort_SingleType() { string SearchTerm = "quick brown fox"; string FlagParameter = ".html"; string Command = $"-d '{TestDataDirectory}' {_FlagDescriptorShort} {FlagParameter} {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void FileTypeInclusion_FlagLast_FlagLong_MultiType_CommaDelimited() { string SearchTerm = "quick brown fox"; string FlagParameter = ".txt,.wg"; string Command = $"-d '{TestDataDirectory}' {SearchTerm} {_FlagDescriptorLong} {FlagParameter}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 2); }
public void FileTypeInclusion_FlagFirst_FlagShort_MultiType_SemiColonDelimited() { string SearchTerm = "quick brown fox"; string FlagParameter = ".cpp;.txt"; string Command = $"{_FlagDescriptorShort} {FlagParameter} -d '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 2); }
public void FileTypeInclusion_FlagFirst_FlagLong_SingleType() { string SearchTerm = "quick brown fox"; string FlagParameter = ".txt"; string Command = $"{_FlagDescriptorLong} {FlagParameter} -d '{TestDataDirectory}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void FileTypeExclusion_FileTypeNotExists() { string SearchTerm = "quick brown fox"; string FlagParameter = ".tig"; string Command = $"-d '{TestDataDirectory}' {SearchTerm} {_FlagDescriptorLong} {FlagParameter}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 7); }
public void FileTypeExclusion_FlagMiddle_FlagLong_MultiType_SemiColonDelimited() { string SearchTerm = "quick brown fox"; string FlagParameter = ".php;.wg"; string Command = $"-d '{TestDataDirectory}' {_FlagDescriptorLong} {FlagParameter} {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 4); }
public void Write_FlagMiddle_FlagLong() { File.WriteAllText(_TestFilePath, "Delete flag test"); string SearchTerm = "Delete flag test"; string Command = $"-f '{_TestFilePath}' {_FlagDescriptorLong} {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsFalse(File.Exists(_TestFilePath)); }
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_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 RegularExpressions_Characters_AnyCharacter() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"power, which eventually. of co.rse, h..did"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
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_CharacterClasses_Characters_Negative() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"so powerful[^\d]*wise"; 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_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 IgnoreCase_FlagFirst_FlagLong_MultiResult() { string TestFilePath = Path.Combine(TestDataDirectory, "IgnoreCase.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "lazy"; string Command = $"{_FlagDescriptorLong} -f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 3); }
public void RegularExpressions_Characters_NonDigit() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsOne.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"Palpat\Dne 2005"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void RegularExpressions_LookArounds_NegativeLookBehind_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.Any()); }
public void IgnoreCase_FlagLast_FlagShort_SingleResult() { string TestFilePath = Path.Combine(TestDataDirectory, "IgnoreCase.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "fox"; string Command = $"-f '{TestFilePath}' {SearchTerm} {_FlagDescriptorShort}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 1); }
public void RegularExpressions_LookArounds_PositiveLookBehind_AfterMatch() { string TestFilePath = Path.Combine(TestDataDirectory, "RegularExpressionsTwo.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = @"\d{3}(?<=USD\d{3})"; string Command = $"-f '{TestFilePath}' {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count == 1); }
public void TargetFile_FlagFirst_FlagLong_DoubleQuotes() { string TestFilePath = Path.Combine(TestDataDirectory, "TargetFile.txt"); Assert.IsTrue(File.Exists(TestFilePath)); string SearchTerm = "fox"; string Command = $"{_FlagDescriptorLong} \"{TestFilePath}\" {SearchTerm}"; var GrepResultCollection = new GrepResultCollection(); GrepEngine.RunCommand(Command, GrepResultCollection); Assert.IsTrue(GrepResultCollection.Count(x => x.MatchedString.EqualsIgnoreCase(SearchTerm)) == 1); }
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); }