当前位置: 首页>>代码示例>>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;未经允许,请勿转载。