nicTest.diff_match_patchTest.patch_makeTest C# (CSharp) Method

patch_makeTest() private method

private patch_makeTest ( ) : void
return void
    public void patch_makeTest() {
      diff_match_patchTest dmp = new diff_match_patchTest();
      List<Patch> patches;
      patches = dmp.patch_make("", "");
      Assert.AreEqual("", dmp.patch_toText(patches), "patch_make: 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.patch_make(text2, text1);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: 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.patch_make(text1, text2);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: Text1+Text2 inputs.");

      List<Diff> diffs = dmp.diff_main(text1, text2, false);
      patches = dmp.patch_make(diffs);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: Diff input.");

      patches = dmp.patch_make(text1, diffs);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: Text1+Diff inputs.");

      patches = dmp.patch_make(text1, text2, diffs);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: Text1+Text2+Diff inputs (deprecated).");

      patches = dmp.patch_make("`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?");
      Assert.AreEqual("@@ -1,21 +1,21 @@\n-%601234567890-=%5b%5d%5c;',./\n+~!@#$%25%5e&*()_+%7b%7d%7c:%22%3c%3e?\n",
          dmp.patch_toText(patches),
          "patch_toText: Character encoding.");

      diffs = new List<Diff> {
          new Diff(Operation.DELETE, "`1234567890-=[]\\;',./"),
          new Diff(Operation.INSERT, "~!@#$%^&*()_+{}|:\"<>?")};
      CollectionAssert.AreEqual(diffs,
          dmp.patch_fromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n") [0].diffs,
          "patch_fromText: 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.patch_make(text1, text2);
      Assert.AreEqual(expectedPatch, dmp.patch_toText(patches), "patch_make: Long string with repeats.");

      // Test null inputs -- not needed because nulls can't be passed in C#.
    }