public function testMake()
{
// Null case.
$patches = $this->p->make("", "");
$this->assertEquals("", $this->p->toText($patches));
$text1 = "The quick brown fox jumps over the lazy dog.";
$text2 = "That quick brown fox jumped over a lazy dog.";
// Text2 + Text1 inputs.
// The second patch must be "-21,17 +21,18", not "-22,17 +21,18" due to rolling context.
$expected = "@@ -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";
$patches = $this->p->make($text2, $text1);
$this->assertEquals($expected, $this->p->toText($patches));
// Text1 + Text2 inputs.
$expected = "@@ -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 = $this->p->make($text1, $text2);
$this->assertEquals($expected, $this->p->toText($patches));
// Diff input.
$diffs = $this->d->main($text1, $text2, false)->getChanges();
$patches = $this->p->make($diffs);
$this->assertEquals($expected, $this->p->toText($patches));
// Text1+Diff inputs.
$patches = $this->p->make($text1, $diffs);
$this->assertEquals($expected, $this->p->toText($patches));
// Text1+Text2+Diff inputs (deprecated).
$patches = $this->p->make($text1, $text2, $diffs);
$this->assertEquals($expected, $this->p->toText($patches));
// Character encoding.
$patches = $this->p->make("`1234567890-=[]\\;',./", "~!@#\$%^&*()_+{}|:\"<>?");
$this->assertEquals("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#\$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n", $this->p->toText($patches));
// Character decoding.
$diffs = array(array(Diff::DELETE, "`1234567890-=[]\\;',./"), array(Diff::INSERT, "~!@#\$%^&*()_+{}|:\"<>?"));
$patches = $this->p->fromText("@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#\$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n");
$this->assertEquals($diffs, $patches[0]->getChanges());
// Long string with repeats.
$text1 = "";
for ($i = 0; $i < 100; $i++) {
$text1 .= "abcdef";
}
$text2 = $text1 . "123";
$expected = "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n";
$patches = $this->p->make($text1, $text2);
$this->assertEquals($expected, $this->p->toText($patches));
// Test null inputs.
try {
$this->p->make(null, null);
$this->fail();
} catch (\InvalidArgumentException $e) {
}
}