public void WhenTwoArguments_ExpectReplacementFileAndSourceFile() { IUtilities util = Substitute.For<IUtilities>(); util.ExpandFileNameWildCards("*.txt").Returns(new List<string>{"file1.txt", "file2.txt"}); ParseCommandLine commandLine = new ParseCommandLine() {utilities = util}; commandLine.Init(new string[] { "a", "*.txt" }); Assert.AreEqual(new List<string>{"file1.txt","file2.txt"}, commandLine.InputSourceList); }
public void WhenOnlyReplacementFileArgument_ExpectStdinAsInputSource() { string[] args = new String[] { "hi~bye" }; ParseCommandLine cmd = new ParseCommandLine(); cmd.Init(args); Assert.AreEqual("hi~bye", cmd.ReplacementFileName); Assert.AreEqual(1, cmd.InputSourceList.Count); Assert.AreEqual(cmd.STDIN, cmd.InputSourceList[0]); }
public void WhenNoArguments_ExpectNoArguments() { string[] args = new String[] { "" }; ParseCommandLine cmd = new ParseCommandLine(); cmd.Init(args); Assert.AreEqual("", cmd.ReplacementFileName); Assert.AreEqual(1, cmd.InputSourceList.Count); // empty string Assert.AreEqual(cmd.STDIN, cmd.InputSourceList[0]); }
public void WhenThreeArguments_ExpectReplacementFileAndSourceFiles(string token, string repfile, string expected) { IUtilities util = Substitute.For<IUtilities>(); util.ExpandFileNameWildCards("file.txt").Returns(new List<string> { "file.txt" }); ParseCommandLine commandLine = new ParseCommandLine() {utilities = util}; commandLine.Init(new String[] { token, repfile }); Assert.AreEqual(expected, commandLine.ReplacementFileName); Assert.AreEqual(1, commandLine.InputSourceList.Count); }
static void Main(string[] args) { ParseCommandLine commandLine = new ParseCommandLine(); commandLine.Init(args); if (commandLine.InputSourceList.Count == 0) Usage("No input sources given/recognized."); ParseCommandFile commands = new ParseCommandFile(commandLine.ReplacementFileName); IFileAction engine = (new FileActionFactory()).GetFileAction(commands.kgrepMode); engine.ApplyCommandsToInputFileList(commands, commandLine.InputSourceList); }
public void WhenFullCycleReplace_ExpectChanges() { IUtilities util = Substitute.For<IUtilities>(); util.ExpandFileNameWildCards("abc").Returns(new List<string> { "abc" }); string[] args = new String[] { "a~c", "abc" }; ParseCommandLine cmd = new ParseCommandLine() {utilities = util}; cmd.Init(args); ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() }; ParseCommandFile commands = new ParseCommandFile(cmd.ReplacementFileName); string results = engine.ApplyCommandsToInputFileList(commands, cmd.InputSourceList); Assert.AreEqual("cbc\n", results); }