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


C# diff_match_patchTest.patch_fromText方法代碼示例

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


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

示例1: patch_addContextTest

        public void patch_addContextTest()
        {
            var dmp = new diff_match_patchTest{Patch_Margin = 4};
            Patch p = dmp.patch_fromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];
            dmp.patch_addContext(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(), "patch_addContext: Simple case.");

            p = dmp.patch_fromText("@@ -21,4 +21,10 @@\n-jump\n+somersault\n")[0];
            dmp.patch_addContext(p, "The quick brown fox jumps.");
            Assert.AreEqual("@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n", p.ToString(), "patch_addContext: Not enough trailing context.");

            p = dmp.patch_fromText("@@ -3 +3,2 @@\n-e\n+at\n")[0];
            dmp.patch_addContext(p, "The quick brown fox jumps.");
            Assert.AreEqual("@@ -1,7 +1,8 @@\n Th\n-e\n+at\n  qui\n", p.ToString(), "patch_addContext: Not enough leading context.");

            p = dmp.patch_fromText("@@ -3 +3,2 @@\n-e\n+at\n")[0];
            dmp.patch_addContext(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(), "patch_addContext: Ambiguity.");
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:19,代碼來源:DiffMatchPatchTest.cs

示例2: patch_makeTest

        public void patch_makeTest()
        {
            var dmp = new diff_match_patchTest();
            List<Patch> 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\[email protected]@ -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\[email protected]@ -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-=[]\\;',./", "[email protected]#$%^&*()_+{}|:\"<>?");
            Assert.AreEqual("@@ -1,21 +1,21 @@\n-%601234567890-=%5b%5d%5c;',./\[email protected]#$%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, "[email protected]#$%^&*()_+{}|:\"<>?")
            };
            CollectionAssert.AreEqual(diffs,
                                      dmp.patch_fromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\[email protected]#$%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#.
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:51,代碼來源:DiffMatchPatchTest.cs

示例3: patch_toTextTest

        public void patch_toTextTest()
        {
            var 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 = dmp.patch_fromText(strp);
            string result = dmp.patch_toText(patches);
            Assert.AreEqual(strp, result);

            strp = "@@ -1,9 +1,9 @@\n-f\n+F\n oo+fooba\[email protected]@ -7,9 +7,9 @@\n obar\n-,\n+.\n  tes\n";
            patches = dmp.patch_fromText(strp);
            result = dmp.patch_toText(patches);
            Assert.AreEqual(strp, result);
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:13,代碼來源:DiffMatchPatchTest.cs

示例4: patch_fromTextTest

        public void patch_fromTextTest()
        {
            var dmp = new diff_match_patchTest();
            Assert.IsTrue(dmp.patch_fromText("").Count == 0, "patch_fromText: #0.");

            const 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.patch_fromText(strp)[0].ToString(), "patch_fromText: #1.");

            Assert.AreEqual("@@ -1 +1 @@\n-a\n+b\n", dmp.patch_fromText("@@ -1 +1 @@\n-a\n+b\n")[0].ToString(), "patch_fromText: #2.");

            Assert.AreEqual("@@ -1,3 +0,0 @@\n-abc\n", dmp.patch_fromText("@@ -1,3 +0,0 @@\n-abc\n")[0].ToString(), "patch_fromText: #3.");

            Assert.AreEqual("@@ -0,0 +1,3 @@\n+abc\n", dmp.patch_fromText("@@ -0,0 +1,3 @@\n+abc\n")[0].ToString(), "patch_fromText: #4.");

            // Generates error.
            try {
                dmp.patch_fromText("Bad\nPatch\n");
                Assert.Fail("patch_fromText: #5.");
            } catch (ArgumentException) {
                // Exception expected.
            }
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:22,代碼來源:DiffMatchPatchTest.cs


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