本文整理汇总了C#中nicTest.diff_match_patchTest.patch_make方法的典型用法代码示例。如果您正苦于以下问题:C# diff_match_patchTest.patch_make方法的具体用法?C# diff_match_patchTest.patch_make怎么用?C# diff_match_patchTest.patch_make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nicTest.diff_match_patchTest
的用法示例。
在下文中一共展示了diff_match_patchTest.patch_make方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: patch_applyTest
public void patch_applyTest()
{
var dmp = new diff_match_patchTest{Match_Distance = 1000, Match_Threshold = 0.5f, Patch_DeleteThreshold = 0.5f};
List<Patch> patches = dmp.patch_make("", "");
Object[] results = dmp.patch_apply(patches, "Hello world.");
var boolArray = (bool[])results[1];
string resultStr = results[0] + "\t" + boolArray.Length;
Assert.AreEqual("Hello world.\t0", resultStr, "patch_apply: Null case.");
patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
results = dmp.patch_apply(patches, "The quick brown fox jumps over the lazy dog.");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("That quick brown fox jumped over a lazy dog.\tTrue\tTrue", resultStr, "patch_apply: Exact match.");
results = dmp.patch_apply(patches, "The quick red rabbit jumps over the tired tiger.");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("That quick red rabbit jumped over a tired tiger.\tTrue\tTrue", resultStr, "patch_apply: Partial match.");
results = dmp.patch_apply(patches, "I am the very model of a modern major general.");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("I am the very model of a modern major general.\tFalse\tFalse", resultStr, "patch_apply: Failed match.");
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, small change.");
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabc12345678901234567890---------------++++++++++---------------12345678901234567890y\tFalse\tTrue", resultStr, "patch_apply: Big delete, big change 1.");
dmp.Patch_DeleteThreshold = 0.6f;
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, big change 2.");
dmp.Patch_DeleteThreshold = 0.5f;
dmp.Match_Threshold = 0.0f;
dmp.Match_Distance = 0;
patches = dmp.patch_make("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890");
results = dmp.patch_apply(patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tFalse\tTrue", resultStr, "patch_apply: Compensate for failed patch.");
dmp.Match_Threshold = 0.5f;
dmp.Match_Distance = 1000;
patches = dmp.patch_make("", "test");
string patchStr = dmp.patch_toText(patches);
dmp.patch_apply(patches, "");
Assert.AreEqual(patchStr, dmp.patch_toText(patches), "patch_apply: No side effects.");
patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "Woof");
patchStr = dmp.patch_toText(patches);
dmp.patch_apply(patches, "The quick brown fox jumps over the lazy dog.");
Assert.AreEqual(patchStr, dmp.patch_toText(patches), "patch_apply: No side effects with major delete.");
patches = dmp.patch_make("", "test");
results = dmp.patch_apply(patches, "");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("test\tTrue", resultStr, "patch_apply: Edge exact match.");
patches = dmp.patch_make("XY", "XtestY");
results = dmp.patch_apply(patches, "XY");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("XtestY\tTrue", resultStr, "patch_apply: Near edge exact match.");
patches = dmp.patch_make("y", "y123");
results = dmp.patch_apply(patches, "x");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("x123\tTrue", resultStr, "patch_apply: Edge partial match.");
}
示例2: patch_splitMaxTest
public void patch_splitMaxTest()
{
// Assumes that Match_MaxBits is 32.
var dmp = new diff_match_patchTest();
List<Patch> patches = dmp.patch_make("abcdefghijklmnopqrstuvwxyz01234567890", "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0");
dmp.patch_splitMax(patches);
Assert.AreEqual("@@ -1,32 +1,46 @@\n+X\n ab\n+X\n cd\n+X\n ef\n+X\n gh\n+X\n ij\n+X\n kl\n+X\n mn\n+X\n op\n+X\n qr\n+X\n st\n+X\n uv\n+X\n wx\n+X\n yz\n+X\n 012345\[email protected]@ -25,13 +39,18 @@\n zX01\n+X\n 23\n+X\n 45\n+X\n 67\n+X\n 89\n+X\n 0\n", dmp.patch_toText(patches));
patches = dmp.patch_make("abcdef1234567890123456789012345678901234567890123456789012345678901234567890uvwxyz", "abcdefuvwxyz");
string oldToText = dmp.patch_toText(patches);
dmp.patch_splitMax(patches);
Assert.AreEqual(oldToText, dmp.patch_toText(patches));
patches = dmp.patch_make("1234567890123456789012345678901234567890123456789012345678901234567890", "abc");
dmp.patch_splitMax(patches);
Assert.AreEqual("@@ -1,32 +1,4 @@\n-1234567890123456789012345678\n 9012\[email protected]@ -29,32 +1,4 @@\n-9012345678901234567890123456\n 7890\[email protected]@ -57,14 +1,3 @@\n-78901234567890\n+abc\n", dmp.patch_toText(patches));
patches = dmp.patch_make("abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1", "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1");
dmp.patch_splitMax(patches);
Assert.AreEqual("@@ -2,32 +2,32 @@\n bcdefghij , h : \n-0\n+1\n , t : 1 abcdef\[email protected]@ -29,32 +29,32 @@\n bcdefghij , h : \n-0\n+1\n , t : 1 abcdef\n", dmp.patch_toText(patches));
}
示例3: patch_addPaddingTest
public void patch_addPaddingTest()
{
var dmp = new diff_match_patchTest();
List<Patch> patches = dmp.patch_make("", "test");
Assert.AreEqual("@@ -0,0 +1,4 @@\n+test\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges full.");
dmp.patch_addPadding(patches);
Assert.AreEqual("@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges full.");
patches = dmp.patch_make("XY", "XtestY");
Assert.AreEqual("@@ -1,2 +1,6 @@\n X\n+test\n Y\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges partial.");
dmp.patch_addPadding(patches);
Assert.AreEqual("@@ -2,8 +2,12 @@\n %02%03%04X\n+test\n Y%01%02%03\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges partial.");
patches = dmp.patch_make("XXXXYYYY", "XXXXtestYYYY");
Assert.AreEqual("@@ -1,8 +1,12 @@\n XXXX\n+test\n YYYY\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges none.");
dmp.patch_addPadding(patches);
Assert.AreEqual("@@ -5,8 +5,12 @@\n XXXX\n+test\n YYYY\n",
dmp.patch_toText(patches),
"patch_addPadding: Both edges none.");
}
示例4: 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#.
}