當前位置: 首頁>>代碼示例>>C#>>正文


C# diff_match_patchTest.diff_text2方法代碼示例

本文整理匯總了C#中nicTest.diff_match_patchTest.diff_text2方法的典型用法代碼示例。如果您正苦於以下問題:C# diff_match_patchTest.diff_text2方法的具體用法?C# diff_match_patchTest.diff_text2怎麽用?C# diff_match_patchTest.diff_text2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nicTest.diff_match_patchTest的用法示例。


在下文中一共展示了diff_match_patchTest.diff_text2方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: diff_deltaTest

        public void diff_deltaTest()
        {
            var dmp = new diff_match_patchTest();
            // Convert a diff into delta string.
            var 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.diff_text1(diffs);
            Assert.AreEqual("jumps over the lazy", text1);

            string delta = dmp.diff_toDelta(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.diff_fromDelta(text1, delta));

            // Generates error (19 < 20).
            try {
                dmp.diff_fromDelta(text1 + "x", delta);
                Assert.Fail("diff_fromDelta: Too long.");
            } catch (ArgumentException) {
                // Exception expected.
            }

            // Generates error (19 > 18).
            try {
                dmp.diff_fromDelta(text1.Substring(1), delta);
                Assert.Fail("diff_fromDelta: Too short.");
            } catch (ArgumentException) {
                // Exception expected.
            }

            // Generates error (%c3%xy invalid Unicode).
            try {
                dmp.diff_fromDelta("", "+%c3%xy");
                Assert.Fail("diff_fromDelta: Invalid character.");
            } catch (ArgumentException) {
                // Exception expected.
            }

            // Test deltas with special characters.
            const char zero = (char)0;
            const char one = (char)1;
            const 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.diff_text1(diffs);
            Assert.AreEqual("\u0680 " + zero + " \t %\u0681 " + one + " \n ^", text1);

            delta = dmp.diff_toDelta(diffs);
            // Lowercase, due to UrlEncode uses lower.
            Assert.AreEqual("=7\t-7\t+%da%82 %02 %5c %7c", delta, "diff_toDelta: Unicode.");

            CollectionAssert.AreEqual(diffs, dmp.diff_fromDelta(text1, delta), "diff_fromDelta: Unicode.");

            // Verify pool of unchanged characters.
            diffs = new List<Diff>{
                new Diff(Operation.Insert, "A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ")
            };
            string text2 = dmp.diff_text2(diffs);
            Assert.AreEqual("A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", text2, "diff_text2: Unchanged characters.");

            delta = dmp.diff_toDelta(diffs);
            Assert.AreEqual("+A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", delta, "diff_toDelta: Unchanged characters.");

            // Convert delta string into a diff.
            CollectionAssert.AreEqual(diffs, dmp.diff_fromDelta("", delta), "diff_fromDelta: Unchanged characters.");
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:78,代碼來源:DiffMatchPatchTest.cs

示例2: diff_textTest

        public void diff_textTest()
        {
            var dmp = new diff_match_patchTest();
            // Compute the source and destination texts.
            var 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.diff_text1(diffs));

            Assert.AreEqual("jumped over a lazy", dmp.diff_text2(diffs));
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:17,代碼來源:DiffMatchPatchTest.cs

示例3: diff_textTest

    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.diff_text1(diffs));

      Assert.AreEqual("jumped over a lazy", dmp.diff_text2(diffs));
    }
開發者ID:wbish,項目名稱:jsondiffpatch.net,代碼行數:15,代碼來源:DiffMatchPatchTest.cs


注:本文中的nicTest.diff_match_patchTest.diff_text2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。