Esempio n. 1
0
        public void AddContext_Ambiguity()
        {
            var p = PatchList.Parse("@@ -3 +3,2 @@\n-e\n+at\n")[0];

            p.AddContext("The quick brown fox jumps.  The quick brown fox crashes.");
            Assert.AreEqual("@@ -1,27 +1,28 @@\n Th\n-e\n+at\n  quick brown fox jumps. \n", p.ToString(),
                            "patch_addContext: Ambiguity.");
        }
        public void ToText_Test2()
        {
            var strp    = "@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n";
            var patches = PatchList.Parse(strp);
            var result  = patches.ToText();

            Assert.Equal(strp, result);
        }
Esempio n. 3
0
        public void AddContext_NotEnoughLeadingContext()
        {
            var p = PatchList.Parse("@@ -3 +3,2 @@\n-e\n+at\n")[0];

            p.AddContext("The quick brown fox jumps.");
            Assert.AreEqual("@@ -1,7 +1,8 @@\n Th\n-e\n+at\n  qui\n", p.ToString(),
                            "patch_addContext: Not enough leading context.");
        }
Esempio n. 4
0
        public void AddContext_NotEnoughTrailingContext()
        {
            var p = PatchList.Parse("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];

            p.AddContext("The quick brown fox jumps.");
            Assert.AreEqual("@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.ToString(),
                            "patch_addContext: Not enough trailing context.");
        }
Esempio n. 5
0
        public void AddContext_SimpleCase()
        {
            var p = PatchList.Parse("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];

            p.AddContext("The quick brown fox jumps over the lazy dog.");
            Assert.AreEqual("@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n", p.ToString(),
                            "patch_addContext: Simple case.");
        }
        public void ToText_Test1()
        {
            var strp    = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n";
            var patches = PatchList.Parse(strp);
            var result  = patches.ToText();

            Assert.Equal(strp, result);
        }
        public void AddContext_Ambiguity()
        {
            var p       = PatchList.Parse("@@ -3 +3,2 @@\n-e\n+at\n")[0];
            var builder = p.Diffs.ToBuilder();

            (int s1, int l1, int s2, int l2) = builder.AddContext("The quick brown fox jumps.  The quick brown fox crashes.", p.Start1, p.Length1, p.Start2, p.Length2);
            p = new Patch(s1, l1, s2, l2, builder.ToImmutable());
            Assert.Equal("@@ -1,27 +1,28 @@\n Th\n-e\n+at\n  quick brown fox jumps. \n", p.ToString());
        }
        public void AddContext_SimpleCase()
        {
            var p       = PatchList.Parse("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];
            var builder = p.Diffs.ToBuilder();

            (int s1, int l1, int s2, int l2) = builder.AddContext("The quick brown fox jumps over the lazy dog.", p.Start1, p.Length1, p.Start2, p.Length2);
            p = new Patch(s1, l1, s2, l2, builder.ToImmutable());
            Assert.Equal("@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n", p.ToString());
        }
        public void AddContext_NotEnoughTrailingContext()
        {
            var p       = PatchList.Parse("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];
            var builder = p.Diffs.ToBuilder();

            (int s1, int l1, int s2, int l2) = builder.AddContext("The quick brown fox jumps.", p.Start1, p.Length1, p.Start2, p.Length2);
            p = new Patch(s1, l1, s2, l2, builder.ToImmutable());
            Assert.Equal("@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.ToString());
        }
Esempio n. 10
0
        private static string PatchFile(string source, string diffText)
        {
            string fileText = File.ReadAllText(source);
            var    patches  = PatchList.Parse(diffText);

            var(patchedText, results) = patches.Apply(fileText);

            // all patches must apply or the source wasn't a proper match
            return(results.Aggregate(true, (l, r) => l & r) ? patchedText : string.Empty);
        }
        public void Compute_CharacterDecoding()
        {
            var diffs = new List <Diff>
            {
                Diff.Delete("`1234567890-=[]\\;',./"),
                Diff.Insert("~!@#$%^&*()_+{}|:\"<>?")
            };

            Assert.Equal(diffs,
                         PatchList.Parse("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n")[0]
                         .Diffs);
        }
 public void Parse_WhenBadPatch_Throws()
 {
     PatchList.Parse("Bad\nPatch\n");
 }
Esempio n. 13
0
 public void FromTextTest2()
 {
     Assert.AreEqual("@@ -1 +1 @@\n-a\n+b\n", PatchList.Parse("@@ -1 +1 @@\n-a\n+b\n")[0].ToString(),
                     "patch_fromText: #2.");
 }
Esempio n. 14
0
 public void FromTextTest3()
 {
     Assert.AreEqual("@@ -1,3 +0,0 @@\n-abc\n", PatchList.Parse("@@ -1,3 +0,0 @@\n-abc\n")[0].ToString(),
                     "patch_fromText: #3.");
 }
 public void Parse_WhenBadPatch_Throws()
 {
     Assert.Throws <ArgumentException>(() => PatchList.Parse("Bad\nPatch\n"));
 }
 public void FromTextTest4()
 {
     Assert.Equal("@@ -0,0 +1,3 @@\n+abc\n", PatchList.Parse("@@ -0,0 +1,3 @@\n+abc\n")[0].ToString());
 }
 public void FromTextTest3()
 {
     Assert.Equal("@@ -1,3 +0,0 @@\n-abc\n", PatchList.Parse("@@ -1,3 +0,0 @@\n-abc\n")[0].ToString());
 }
 public void FromTextTest2()
 {
     Assert.Equal("@@ -1 +1 @@\n-a\n+b\n", PatchList.Parse("@@ -1 +1 @@\n-a\n+b\n")[0].ToString());
 }
        public void FromTextTest1()
        {
            var strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n %0alaz\n";

            Assert.Equal(strp, PatchList.Parse(strp)[0].ToString());
        }
        public void Parse_EmptyString_YieldsEmptyList()
        {
            var patches = PatchList.Parse("");

            Assert.False(patches.Any());
        }
Esempio n. 21
0
 public void FromTextTest4()
 {
     Assert.AreEqual("@@ -0,0 +1,3 @@\n+abc\n", PatchList.Parse("@@ -0,0 +1,3 @@\n+abc\n")[0].ToString(),
                     "patch_fromText: #4.");
 }