Files
DomFramework/Tests/xdiffTest.php

259 lines
5.0 KiB
PHP

<?php
/** DomFramework
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
*/
/** Test the domframework xdiff part */
class test_xdiff extends PHPUnit_Framework_TestCase
{
// Declaration of $string1 and $string2
// Taken from
// {{{
private $string1 = "This part of the
document has stayed the
same from version to
version. It shouldn't
be shown if it doesn't
change. Otherwise, that
would not be helping to
compress the size of the
changes.
This paragraph contains
text that is outdated.
It will be deleted in the
near future.
It is important to spell
check this dokument. On
the other hand, a
misspelled word isn't
the end of the world.
Nothing in the rest of
this paragraph needs to
be changed. Things can
be added after it.
";
private $string2 = "This is an important
notice! It should
therefore be located at
the beginning of this
document!
This part of the
document has stayed the
same from version to
version. It shouldn't
be shown if it doesn't
change. Otherwise, that
would not be helping to
compress the size of the
changes.
It is important to spell
check this document. On
the other hand, a
misspelled word isn't
the end of the world.
Nothing in the rest of
this paragraph needs to
be changed. Things can
be added after it.
This paragraph contains
important new additions
to this document.
";
// }}}
public function test_diff_normal_1 ()
{
// Mode normal
$xdiff = new xdiff ();
$res = $xdiff->diff ($this->string1, $this->string2);
$this->assertSame ($res, "0a1,6
> This is an important
> notice! It should
> therefore be located at
> the beginning of this
> document!
>
11,15d16
< This paragraph contains
< text that is outdated.
< It will be deleted in the
< near future.
<
17c18
< check this dokument. On
---
> check this document. On
24a26,29
>
> This paragraph contains
> important new additions
> to this document.
");
}
public function test_diff_normal_2 ()
{
// Mode normal
$xdiff = new xdiff ();
$res = $xdiff->diff ("NEWLINE\n".$this->string1, $this->string2);
$this->assertSame ($res, "1c1,6
< NEWLINE
---
> This is an important
> notice! It should
> therefore be located at
> the beginning of this
> document!
>
12,16d16
< This paragraph contains
< text that is outdated.
< It will be deleted in the
< near future.
<
18c18
< check this dokument. On
---
> check this document. On
25a26,29
>
> This paragraph contains
> important new additions
> to this document.
");
}
public function test_diff_normal_3 ()
{
// Mode normal
$xdiff = new xdiff ();
$res = $xdiff->diff ("NEWLINE\n", "\n");
$this->assertSame ($res, "1c1
< NEWLINE
---
>
");
}
public function test_diff_normal_4 ()
{
// Mode normal
$xdiff = new xdiff ();
$res = $xdiff->diff ("\n", "NEWLINE\n");
$this->assertSame ($res, "1c1
<
---
> NEWLINE
");
}
public function test_diff_normal_5 ()
{
// Mode normal
$xdiff = new xdiff ();
$res = $xdiff->diff ("\n", "\n");
$this->assertSame ($res, "");
}
public function test_diff_unified_1 ()
{
// Mode unified
$xdiff = new xdiff ("unified");
$res = $xdiff->diff ($this->string1, $this->string2);
$this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")."
+++ New ".date ("Y-m-d H:i:s.u001 O")."
@@ -0,0 +1,6 @@
+This is an important
+notice! It should
+therefore be located at
+the beginning of this
+document!
+
@@ -11,5 +16,0 @@
-This paragraph contains
-text that is outdated.
-It will be deleted in the
-near future.
-
@@ -17 +18 @@
-check this dokument. On
+check this document. On
@@ -24,0 +26,4 @@
+
+This paragraph contains
+important new additions
+to this document.
");
}
public function test_diff_unified_2 ()
{
// Mode unified
$xdiff = new xdiff ("unified");
$res = $xdiff->diff ("NEWLINE\n".$this->string1, $this->string2);
$this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")."
+++ New ".date ("Y-m-d H:i:s.u001 O")."
@@ -1 +1,6 @@
-NEWLINE
+This is an important
+notice! It should
+therefore be located at
+the beginning of this
+document!
+
@@ -12,5 +16,0 @@
-This paragraph contains
-text that is outdated.
-It will be deleted in the
-near future.
-
@@ -18 +18 @@
-check this dokument. On
+check this document. On
@@ -25,0 +26,4 @@
+
+This paragraph contains
+important new additions
+to this document.
");
}
public function test_diff_unified_3 ()
{
$xdiff = new xdiff ("unified");
$res = $xdiff->diff ("NEWLINE\n", "\n");
$this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")."
+++ New ".date ("Y-m-d H:i:s.u001 O")."
@@ -1 +1 @@
-NEWLINE
+
");
}
public function test_diff_unified_4 ()
{
$xdiff = new xdiff ("unified");
$res = $xdiff->diff ("\n", "NEWLINE\n");
$this->assertSame ($res, "--- Original ".date ("Y-m-d H:i:s.u000 O")."
+++ New ".date ("Y-m-d H:i:s.u001 O")."
@@ -1 +1 @@
-
+NEWLINE
");
}
public function test_diff_unified_5 ()
{
$xdiff = new xdiff ("unified");
$res = $xdiff->diff ("\n", "\n");
$this->assertSame ($res, "");
}
}