Beispiel #1
0
 public void LimitMatchesToDefault()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("a~b;b~c;c~d;d~e");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "abcde" });
     Assert.AreEqual("eeeee\n", results);
 }
Beispiel #2
0
 public void WhenGlobPickupAtEndOfLine_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"{num=[0-9]+}{title};->${title}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "900  the end"});
     Assert.AreEqual("  the end\n", results);
 }
Beispiel #3
0
 public void WhenGlobPickupIsTooShort_ExpectNoValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"<{opentag}>;abc~${opentag}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "<>def", "abc here" });
     Assert.AreEqual("<>def\n here\n", results);
 }
Beispiel #4
0
 public void TemplateWithPickupOnlyNoPrinting()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("/Today (?<date>..)/;(.)->Date ${date}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "Today is the 5th.", "The 6th is tomorrow." });
     Assert.AreEqual("Date is\nDate is\n", results);
 }
Beispiel #5
0
 public void WhenDifferentNamedPickups_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"(?<name>[a-z]+) (?<name2>[a-z]+);(?<digit>[0-9]+)~${name}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "ab cd", "89ab" });
     Assert.AreEqual("ab cd\nabab\n", results);
 }
Beispiel #6
0
 public void LimitMatchesResetsWithEachFile()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("a~b;b~c;c~d;d~e");
     commands.MaxReplacements = 1;  // this override value should be used for each file read. Don't use value from previous file scan.
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "abcde", "kcde" });
     Assert.AreEqual("bbcde\nkdde\n", results);
 }
Beispiel #7
0
 public void TemplateWithPickup()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("(?<date>[0-9]+);(.)->Date is ${date}");
     commands.MaxReplacements = 3;
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "Today is the 5th.", "The 6th is tomorrow." });
     Assert.AreEqual("Date is 5\nDate is 6\n", results);
 }
Beispiel #8
0
 public void WhenMatchedNamedAndUnnamedPickups_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"(?<letter>[a-z]+).([0-9]);12~${1}${letter}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "ab 12" });
     Assert.AreEqual("ab 1ab\n", results);
 }
Beispiel #9
0
 public void WhenGlobPickupsWithPattern_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"<isbn>{isbn=[0-9]+}$; report ~ ${isbn}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "<isbn>97809", "report" });
     Assert.AreEqual("<isbn>97809\n97809\n", results);
 }
Beispiel #10
0
 public void WhenSimpleMatch_OnlyPrintMatched()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("(you) -> to");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { " 9you today" });
     Assert.AreEqual("to\n", results);
 }
Beispiel #11
0
 public void WhenReplacing_ReplaceUsingOriginalLineAsSource(string line, string command, string expectedResults)
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(command);
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { line });
     Assert.AreEqual(expectedResults, results);
 }
Beispiel #12
0
 public void WhenTwoPickupSpansLinesWithMultipleReferences_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"^<chap=(?<tag>[a-z]+?)>~; end~chapter=${tag}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "<chap=a><last=z> end" });
     Assert.AreEqual("<last=z> chapter=a\n", results);
 }
Beispiel #13
0
 public void WhenReplacementHasAnchorThatMatches_ExpectChange()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("/^Th/hi~bye; all~gone");
     string newline = engine.ApplyCommandsToInputFileList(commands,
                                 new List<string> { "mTh my hi world", "Thgo hi mytoday" });
     Assert.AreEqual("mTh my hi world\nThgo bye mytoday\n", newline);
 }
Beispiel #14
0
 public void WhenReplacementHasAnchorThatMatchesManySameLine_ExpectMultipleChangesLine()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("/my/hi~bye; all~gone");
     string newline = engine.ApplyCommandsToInputFileList(commands,
                                 new List<string> { "This is my hi world", "go hi today" });
     Assert.AreEqual("Tbyes is my bye world\ngo hi today\n", newline);
 }
Beispiel #15
0
 public void WhenReplacementGiven_ExpectRemoveSpaces()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"\s~");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "a b c", "the   dog  ran. " });
     Assert.AreEqual("abc\nthedogran.\n", newline);
 }
Beispiel #16
0
 public void WhenReplacementGiven_ExpectExpandEveryThirdLetter()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"([a-z]{3})~$1-");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "kgrep works today by" });
     Assert.AreEqual("kgr-ep wor-ks tod-ay by\n", newline);
 }
Beispiel #17
0
 public void WhenReplacementGiven_ExpectEveryOtherLetterSwapped()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"([a-z])([a-z])~$2$1");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "kgrep works today by" });
     Assert.AreEqual("gkerp owkrs otady yb\n", newline);
 }
Beispiel #18
0
 public void WhenRegexSpaceInFrompattern_ExpectSpaces(string input, string repstring, string expect)
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(repstring);
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { input });
     Assert.AreEqual(expect, newline);
 }
Beispiel #19
0
 public void WhenMatchesSpanLines_OnlyPrintMatched()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("([0-9]+)->{$1};s~t");
     commands.MaxReplacements = 1;
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "This is the 10th testing", "following 345." });
     Assert.AreEqual("{10}\n{345}\n", results);
 }
Beispiel #20
0
 public void WhenPickupAndRegexGiven_ExpectBothReplaced()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"^(\w)(.);..(.)~$1${2}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "abc" });
     Assert.AreEqual("cb\n", results);
 }
Beispiel #21
0
 public void WhenPickupRepeats_ExpectReplacedValues()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"^(?<name>[a-z]+)~c${name}${name}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "a" });
     Assert.AreEqual("caa\n", results);
 }
Beispiel #22
0
 public void WhenReplacementsGiven_ExpectAllReplaced()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("a~b; b~c");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "a b c", "a b c", "earth" });
     Assert.AreEqual("c c c\nc c c\necrth\n", newline);
 }
Beispiel #23
0
 public void WhenTwoPickupSpansLines_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"^(?<name>[a-z]+)~blue ${name};(?<digit>[0-9]+) ~${name}; blue~ ${name}${digit}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> {  "ab 89 cd" });
     Assert.AreEqual("ab89 ab ab cd\n", results);
 }
Beispiel #24
0
 public void WhenEmptyReplacement_ExpectNoChange()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("");
     string newline = engine.ApplyCommandsToInputFileList(commands,
                                 new List<string> { "Hello World", "See you later." });
     Assert.AreEqual("Hello World\nSee you later.\n", newline);
 }
Beispiel #25
0
 public void WhenAnchorNotMatched_ExpectNoChange()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("my~hi~bye; all~gone");
     string newline = engine.ApplyCommandsToInputFileList(commands,
                                 new List<string> { "Now is your hi world", "go hi today" });
     Assert.AreEqual("Now is your hi world\ngo hi today\n", newline);
 }
Beispiel #26
0
        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);
        }
Beispiel #27
0
 public void WhenReplacementWithTwoInputLines_ExpectChanges()
 {
     ReplaceTokens engine = new ReplaceTokens() {sw = new WriteToString()};
     ParseCommandFile commands = new ParseCommandFile("a~b");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> {"abc", "daf"});
     Assert.AreEqual("bbc\ndbf\n", newline);
 }
Beispiel #28
0
 public void WhenDelimIsChanged_ExpectChangeWithNewDelim()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("delim=,; hi,bye; here,there");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "hi world", "go home today", "here is it" });
     Assert.AreEqual("bye world\ngo home today\nthere is it\n", newline);
 }
Beispiel #29
0
 public void WhenGlobPickupsSpanThreeLines_ExpectReplacedValue()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile(@"<title>{title}</title>; <isbn>{isbn}$; report ~ ${isbn} ${title}");
     string results = engine.ApplyCommandsToInputFileList(commands, new List<string> { "<isbn>97809", "<title>Answers</title>", "report" });
     Assert.AreEqual("<isbn>97809\n<title>Answers</title>\n97809 Answers\n", results);
 }
Beispiel #30
0
 public void WhenAnchorMatchesFirstLineOnly_ExpectChanges()
 {
     ReplaceTokens engine = new ReplaceTokens() { sw = new WriteToString() };
     ParseCommandFile commands = new ParseCommandFile("/my/hi~bye; all~gone");
     string newline = engine.ApplyCommandsToInputFileList(commands, new List<string> { "Now is my hi world;go hi today" });
     Assert.AreEqual("Now is my bye world\ngo hi today\n", newline);
 }