public void diff_textTest() { diff_match_patchTest dmp = new diff_match_patchTest(); // Compute the source and destination texts. List<Diff> diffs = new List<Diff> { new Diff(Operation.EQUAL, "jump"), new Diff(Operation.DELETE, "s"), new Diff(Operation.INSERT, "ed"), new Diff(Operation.EQUAL, " over "), new Diff(Operation.DELETE, "the"), new Diff(Operation.INSERT, "a"), new Diff(Operation.EQUAL, " lazy")}; Assert.AreEqual("jumps over the lazy", dmp.DiffText1(diffs)); Assert.AreEqual("jumped over a lazy", dmp.DiffText2(diffs)); }
public void diff_deltaTest() { diff_match_patchTest dmp = new diff_match_patchTest(); // Convert a diff into delta string. List<Diff> diffs = new List<Diff> { new Diff(Operation.EQUAL, "jump"), new Diff(Operation.DELETE, "s"), new Diff(Operation.INSERT, "ed"), new Diff(Operation.EQUAL, " over "), new Diff(Operation.DELETE, "the"), new Diff(Operation.INSERT, "a"), new Diff(Operation.EQUAL, " lazy"), new Diff(Operation.INSERT, "old dog")}; string text1 = dmp.DiffText1(diffs); Assert.AreEqual("jumps over the lazy", text1); string delta = dmp.DiffToDelta(diffs); Assert.AreEqual("=4\t-1\t+ed\t=6\t-3\t+a\t=5\t+old dog", delta); // Convert delta string into a diff. CollectionAssert.AreEqual(diffs, dmp.DiffFromDelta(text1, delta)); // Generates error (19 < 20). try { dmp.DiffFromDelta(text1 + "x", delta); Assert.Fail("DiffFromDelta: Too long."); } catch (ArgumentException) { // Exception expected. } // Generates error (19 > 18). try { dmp.DiffFromDelta(text1.Substring(1), delta); Assert.Fail("DiffFromDelta: Too short."); } catch (ArgumentException) { // Exception expected. } // Generates error (%c3%xy invalid Unicode). try { dmp.DiffFromDelta("", "+%c3%xy"); Assert.Fail("DiffFromDelta: Invalid character."); } catch (ArgumentException) { // Exception expected. } // Test deltas with special characters. char zero = (char)0; char one = (char)1; char two = (char)2; diffs = new List<Diff> { new Diff(Operation.EQUAL, "\u0680 " + zero + " \t %"), new Diff(Operation.DELETE, "\u0681 " + one + " \n ^"), new Diff(Operation.INSERT, "\u0682 " + two + " \\ |")}; text1 = dmp.DiffText1(diffs); Assert.AreEqual("\u0680 " + zero + " \t %\u0681 " + one + " \n ^", text1); delta = dmp.DiffToDelta(diffs); // Lowercase, due to UrlEncode uses lower. Assert.AreEqual("=7\t-7\t+%da%82 %02 %5c %7c", delta, "DiffToDelta: Unicode."); CollectionAssert.AreEqual(diffs, dmp.DiffFromDelta(text1, delta), "DiffFromDelta: Unicode."); // Verify pool of unchanged characters. diffs = new List<Diff> { new Diff(Operation.INSERT, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ")}; string text2 = dmp.DiffText2(diffs); Assert.AreEqual("A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", text2, "DiffText2: Unchanged characters."); delta = dmp.DiffToDelta(diffs); Assert.AreEqual("+A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", delta, "DiffToDelta: Unchanged characters."); // Convert delta string into a diff. CollectionAssert.AreEqual(diffs, dmp.DiffFromDelta("", delta), "DiffFromDelta: Unchanged characters."); }