static void Main(string[] args)
        {
            var diffs = new List <Diff>
            {
                Diff.Insert(" "),
                Diff.Equal("a"),
                Diff.Insert("nd"),
                Diff.Equal(" [[Pennsylvania]]"),
                Diff.Delete(" and [[New")
            };

            var patch1 = Patch.FromDiffs(diffs);

            Console.WriteLine(diffs.Text1());
            Console.WriteLine(diffs.Text2());

            var patch2 = Patch.Compute(diffs.Text1(), diffs.Text2(), 0, 4);

            Console.WriteLine(patch1.ToText());
            Console.WriteLine(patch2.ToText());

            //Debug.Assert(patch1.SequenceEqual(patch2));

            ImmutableList <int> someList = Enumerable.Range(0, 10).ToImmutableList();
            var record1 = new MyRecord(someList);
            var record2 = new MyRecord(someList);

            Console.WriteLine(record1 == record2);
        }
        public void Compute_CharacterEncoding()
        {
            var patches = Patch.Compute("`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?");

            Assert.Equal(
                "@@ -1,21 +1,21 @@\n-%601234567890-=%5b%5d%5c;',./\n+~!@#$%25%5e&*()_+%7b%7d%7c:%22%3c%3e?\n",
                patches.ToText());
        }
        public void Apply_NoSideEffects()
        {
            var patches  = Patch.Compute("", "test");
            var patchStr = patches.ToText();

            patches.Apply("");
            Assert.Equal(patchStr, patches.ToText());
        }
        public void Apply_NoSideEffectsWithMajorDelete()
        {
            var patches  = Patch.Compute("The quick brown fox jumps over the lazy dog.", "Woof");
            var patchStr = patches.ToText();

            patches.Apply("The quick brown fox jumps over the lazy dog.");
            Assert.Equal(patchStr, patches.ToText());
        }
예제 #5
0
        public void Apply_NoSideEffects()
        {
            var patches  = Patch.Compute("", "test");
            var patchStr = patches.ToText();

            patches.Apply("");
            Assert.AreEqual(patchStr, patches.ToText(), "patch_apply: No side effects.");
        }
        public void SplitMaxTest2()
        {
            var patches   = Patch.Compute("abcdef1234567890123456789012345678901234567890123456789012345678901234567890uvwxyz", "abcdefuvwxyz");
            var oldToText = patches.ToText();
            var patches2  = patches.SplitMax().ToImmutableList();

            Assert.Equal(oldToText, patches2.ToText());
        }
예제 #7
0
        public void Apply_BigDeleteSmallChange()
        {
            var patches   = Patch.Compute("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
            var results   = patches.Apply("x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y");
            var boolArray = results.Item2;
            var resultStr = results.Item1 + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, small change.");
        }
예제 #8
0
        public void Apply_EdgeExactMatch()
        {
            var patches   = Patch.Compute("", "test");
            var results   = patches.Apply("");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0];

            Assert.AreEqual("test\tTrue", resultStr, "patch_apply: Edge exact match.");
        }
예제 #9
0
        public void SplitMaxTest4()
        {
            var patches = Patch.Compute("abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1", "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1");

            patches.SplitMax();
            Assert.AreEqual(
                "@@ -2,32 +2,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n@@ -29,32 +29,32 @@\n bcdefghij , h : \n-0\n+1\n  , t : 1 abcdef\n",
                patches.ToText());
        }
예제 #10
0
        public void SplitMaxTest3()
        {
            var patches = Patch.Compute("1234567890123456789012345678901234567890123456789012345678901234567890", "abc");

            patches.SplitMax();
            Assert.AreEqual(
                "@@ -1,32 +1,4 @@\n-1234567890123456789012345678\n 9012\n@@ -29,32 +1,4 @@\n-9012345678901234567890123456\n 7890\n@@ -57,14 +1,3 @@\n-78901234567890\n+abc\n",
                patches.ToText());
        }
예제 #11
0
        public void SplitMaxTest1()
        {
            var patches = Patch.Compute("abcdefghijklmnopqrstuvwxyz01234567890", "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0");

            patches.SplitMax();
            Assert.AreEqual(
                "@@ -1,32 +1,46 @@\n+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\n uv\n+X\n wx\n+X\n yz\n+X\n 012345\n@@ -25,13 +39,18 @@\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n",
                patches.ToText());
        }
예제 #12
0
        // While VS team did publish the GIT patch DIFF, that's not usable by the DiffMatchPatch library
        // (or any other I could find on short notice). So this is used to generate the DIFF applied.
        //
        // The resulting intrin0_h.diff is already part of this project so not likely needed, but
        // this is retained as a reference for how it was created)
        private static int GenerateDiffFile(GenerateOptions o)
        {
            string unpatched = File.ReadAllText(o.Unpatched);
            string patched   = File.ReadAllText(o.Patched);

            // compute and write the diff file for inclusion
            File.WriteAllText("intrin0_h.diff", Patch.Compute(unpatched, patched).ToText( ));
            return(0);
        }
예제 #13
0
        public void Apply_EdgePartialMatch()
        {
            var patches   = Patch.Compute("y", "y123");
            var results   = patches.Apply("x");
            var boolArray = results.Item2;
            var resultStr = results.Item1 + "\t" + boolArray[0];

            Assert.AreEqual("x123\tTrue", resultStr, "patch_apply: Edge partial match.");
        }
예제 #14
0
        public void Apply_NearEdgeExactMatch()
        {
            var patches   = Patch.Compute("XY", "XtestY");
            var results   = patches.Apply("XY");
            var boolArray = results.Item2;
            var resultStr = results.Item1 + "\t" + boolArray[0];

            Assert.AreEqual("XtestY\tTrue", resultStr, "patch_apply: Near edge exact match.");
        }
예제 #15
0
        public void Apply_BigDeleteBigChange2()
        {
            var patches   = Patch.Compute("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
            var results   = patches.Apply("x12345678901234567890---------------++++++++++---------------12345678901234567890y", MatchSettings.Default, new PatchSettings(0.6f, 4));
            var boolArray = results.Item2;
            var resultStr = results.Item1 + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, big change 2.");
        }
        public void AddPadding_Empty()
        {
            var patches = Patch.Compute("", "");

            Assert.Equal("", patches.ToText());
            var patches2 = patches.AddPadding(PatchList.NullPadding()).ToImmutableList();

            Assert.Equal("", patches2.ToText());
        }
        public void Apply_EdgePartialMatch()
        {
            var patches   = Patch.Compute("y", "y123");
            var results   = patches.Apply("x");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0];

            Assert.Equal("x123\tTrue", resultStr);
        }
        public void Apply_NearEdgeExactMatch()
        {
            var patches   = Patch.Compute("XY", "XtestY");
            var results   = patches.Apply("XY");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0];

            Assert.Equal("XtestY\tTrue", resultStr);
        }
예제 #19
0
        public void Apply_EmptyString()
        {
            var patches   = Patch.Compute("", "");
            var results   = patches.Apply("Hello world.");
            var boolArray = results.Item2;
            var resultStr = results.Item1 + "\t" + boolArray.Length;

            Assert.AreEqual("Hello world.\t0", resultStr, "patch_apply: Null case.");
        }
        public void Apply_BigDeleteBigChange2()
        {
            var patches   = Patch.Compute("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
            var results   = patches.Apply("x12345678901234567890---------------++++++++++---------------12345678901234567890y", MatchSettings.Default, new PatchSettings(0.6f, 4));
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.Equal("xabcy\tTrue\tTrue", resultStr);
        }
        public void Apply_CompensateForFailedPatch()
        {
            var patches   = Patch.Compute("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890");
            var results   = patches.Apply("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890", new MatchSettings(0.0f, 0));
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.Equal("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tFalse\tTrue", resultStr);
        }
        public void Apply_FailedMatch()
        {
            var patches   = Patch.Compute("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
            var results   = patches.Apply("I am the very model of a modern major general.");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.Equal("I am the very model of a modern major general.\tFalse\tFalse", resultStr);
        }
        public void Apply_BigDeleteSmallChange()
        {
            var patches   = Patch.Compute("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
            var results   = patches.Apply("x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.Equal("xabcy\tTrue\tTrue", resultStr);
        }
        public void Apply_PartialMatch()
        {
            var patches   = Patch.Compute("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
            var results   = patches.Apply("The quick red rabbit jumps over the tired tiger.");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.Equal("That quick red rabbit jumped over a tired tiger.\tTrue\tTrue", resultStr);
        }
        public void Apply_EmptyString()
        {
            var patches   = Patch.Compute("", "");
            var results   = patches.Apply("Hello world.");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray.Length;

            Assert.Equal("Hello world.\t0", resultStr);
        }
예제 #26
0
        public void Apply_ExactMatch()
        {
            var patches   = Patch.Compute("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
            var results   = patches.Apply("The quick brown fox jumps over the lazy dog.");
            var boolArray = results.results;
            var resultStr = results.newText + "\t" + boolArray[0] + "\t" + boolArray[1];

            Assert.AreEqual("That quick brown fox jumped over a lazy dog.\tTrue\tTrue", resultStr,
                            "patch_apply: Exact match.");
        }
        public void AddPadding_BothEdgesFull()
        {
            var patches = Patch.Compute("", "test");

            Assert.Equal("@@ -0,0 +1,4 @@\n+test\n", patches.ToText());
            var patches2 = patches.AddPadding(PatchList.NullPadding()).ToImmutableList();

            Assert.Equal("@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n",
                         patches2.ToText());
        }
        public void Compute_FromTextAndDiffs_Succeeds()
        {
            var text1         = "The quick brown fox jumps over the lazy dog.";
            var text2         = "That quick brown fox jumped over a lazy dog.";
            var diffs         = Diff.Compute(text1, text2, 0, false);
            var expectedPatch =
                "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n-the\n+a\n  laz\n";
            var patches = Patch.Compute(text1, diffs).ToList();

            Assert.Equal(expectedPatch, patches.ToText());
        }
        public void AddPadding_BothEdgesNone()
        {
            var patches = Patch.Compute("XXXXYYYY", "XXXXtestYYYY");

            Assert.Equal("@@ -1,8 +1,12 @@\n XXXX\n+test\n YYYY\n",
                         patches.ToText());
            var patches2 = patches.AddPadding(PatchList.NullPadding()).ToImmutableList();

            Assert.Equal("@@ -5,8 +5,12 @@\n XXXX\n+test\n YYYY\n",
                         patches2.ToText());
        }
        public void AddPadding_BothEdgesPartial()
        {
            var patches = Patch.Compute("XY", "XtestY");

            Assert.Equal("@@ -1,2 +1,6 @@\n X\n+test\n Y\n",
                         patches.ToText());
            var patches2 = patches.AddPadding(PatchList.NullPadding()).ToImmutableList();

            Assert.Equal("@@ -2,8 +2,12 @@\n %02%03%04X\n+test\n Y%01%02%03\n",
                         patches2.ToText());
        }