public void PatchAddContextTest() { diff_match_patchTest dmp = new diff_match_patchTest(); dmp.Patch_Margin = 4; Patch p; p = dmp.PatchFromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n") [0]; dmp.PatchAddContext(p, "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(), "PatchAddContext: Simple case."); p = dmp.PatchFromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0]; dmp.PatchAddContext(p, "The quick brown fox jumps."); Assert.AreEqual("@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.ToString(), "PatchAddContext: Not enough trailing context."); p = dmp.PatchFromText("@@ -3 +3,2 @@\n-e\n+at\n")[0]; dmp.PatchAddContext(p, "The quick brown fox jumps."); Assert.AreEqual("@@ -1,7 +1,8 @@\n Th\n-e\n+at\n qui\n", p.ToString(), "PatchAddContext: Not enough leading context."); p = dmp.PatchFromText("@@ -3 +3,2 @@\n-e\n+at\n")[0]; dmp.PatchAddContext(p, "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(), "PatchAddContext: Ambiguity."); }
public void PatchMakeTest() { diff_match_patchTest dmp = new diff_match_patchTest(); List<Patch> patches; patches = dmp.PatchMake("", ""); Assert.AreEqual("", dmp.PatchToText(patches), "PatchMake: Null case."); string text1 = "The quick brown fox jumps over the lazy dog."; string text2 = "That quick brown fox jumped over a lazy dog."; string expectedPatch = "@@ -1,8 +1,7 @@\n Th\n-at\n+e\n qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n over \n-a\n+the\n laz\n"; // The second patch must be "-21,17 +21,18", not "-22,17 +21,18" due to rolling context. patches = dmp.PatchMake(text2, text1); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Text2+Text1 inputs."); 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"; patches = dmp.PatchMake(text1, text2); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Text1+Text2 inputs."); List<Diff> diffs = dmp.DiffMain(text1, text2, false); patches = dmp.PatchMake(diffs); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Diff input."); patches = dmp.PatchMake(text1, diffs); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Text1+Diff inputs."); patches = dmp.PatchMake(text1, text2, diffs); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Text1+Text2+Diff inputs (deprecated)."); patches = dmp.PatchMake("`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?"); Assert.AreEqual("@@ -1,21 +1,21 @@\n-%601234567890-=%5b%5d%5c;',./\n+~!@#$%25%5e&*()_+%7b%7d%7c:%22%3c%3e?\n", dmp.PatchToText(patches), "PatchToText: Character encoding."); diffs = new List<Diff> { new Diff(Operation.DELETE, "`1234567890-=[]\\;',./"), new Diff(Operation.INSERT, "~!@#$%^&*()_+{}|:\"<>?")}; CollectionAssert.AreEqual(diffs, dmp.PatchFromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n") [0].diffs, "PatchFromText: Character decoding."); text1 = ""; for (int x = 0; x < 100; x++) { text1 += "abcdef"; } text2 = text1 + "123"; expectedPatch = "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"; patches = dmp.PatchMake(text1, text2); Assert.AreEqual(expectedPatch, dmp.PatchToText(patches), "PatchMake: Long string with repeats."); // Test null inputs -- not needed because nulls can't be passed in C#. }
public void PatchToTextTest() { diff_match_patchTest dmp = new diff_match_patchTest(); string strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"; List<Patch> patches; patches = dmp.PatchFromText(strp); string result = dmp.PatchToText(patches); Assert.AreEqual(strp, result); strp = "@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\n@@ -7,9 +7,9 @@\n obar\n-,\n+.\n tes\n"; patches = dmp.PatchFromText(strp); result = dmp.PatchToText(patches); Assert.AreEqual(strp, result); }
public void PatchFromTextTest() { diff_match_patchTest dmp = new diff_match_patchTest(); Assert.IsTrue(dmp.PatchFromText("").Count == 0, "PatchFromText: #0."); string strp = "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0alaz\n"; Assert.AreEqual(strp, dmp.PatchFromText(strp)[0].ToString(), "PatchFromText: #1."); Assert.AreEqual("@@ -1 +1 @@\n-a\n+b\n", dmp.PatchFromText("@@ -1 +1 @@\n-a\n+b\n")[0].ToString(), "PatchFromText: #2."); Assert.AreEqual("@@ -1,3 +0,0 @@\n-abc\n", dmp.PatchFromText("@@ -1,3 +0,0 @@\n-abc\n") [0].ToString(), "PatchFromText: #3."); Assert.AreEqual("@@ -0,0 +1,3 @@\n+abc\n", dmp.PatchFromText("@@ -0,0 +1,3 @@\n+abc\n") [0].ToString(), "PatchFromText: #4."); // Generates error. try { dmp.PatchFromText("Bad\nPatch\n"); Assert.Fail("PatchFromText: #5."); } catch (ArgumentException) { // Exception expected. } }