diff --git a/Tests/xdiffTest.php b/Tests/xdiffTest.php index c349d88..9c2907b 100644 --- a/Tests/xdiffTest.php +++ b/Tests/xdiffTest.php @@ -155,12 +155,27 @@ to this document. public function test_diff_normal_5 () { - // Mode normal $xdiff = new xdiff (); $res = $xdiff->diff ("\n", "\n"); $this->assertSame ($res, ""); } + public function test_diff_normal_6 () + { + $xdiff = new xdiff (); + $res = $xdiff->diff ("\n", ""); + $this->assertSame ($res, "1d0 +< \n"); + } + + public function test_diff_normal_7 () + { + $xdiff = new xdiff (); + $res = $xdiff->diff ("", "\n"); + $this->assertSame ($res, "0a1 +> \n"); + } + public function test_diff_unified_1 () { // Mode unified @@ -255,4 +270,24 @@ to this document. $this->assertSame ($res, ""); } + public function test_diff_unified_6 () + { + $xdiff = new xdiff ("unified"); + $res = $xdiff->diff ("\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 +0,0 @@ +-\n"); + } + + public function test_diff_unified_7 () + { + $xdiff = new xdiff ("unified"); + $res = $xdiff->diff ("", "\n"); + $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 @@ ++\n"); + } + } diff --git a/xdiff.php b/xdiff.php index 8f9e885..9510618 100644 --- a/xdiff.php +++ b/xdiff.php @@ -285,7 +285,8 @@ class xdiff $info .= ",0"; $info .= " +"; $info .= $diff["startLine2"]; - $info .= ",".$diff["length"]; + if ($diff["length"] !== 1) + $info .= ",".$diff["length"]; $info .= " @@\n"; $d .= $info; $d .= "+".implode ("+", $diff["chunk"]); @@ -294,7 +295,8 @@ class xdiff { $info = "@@ -"; $info .= $diff["startLine1"]; - $info .= ",".$diff["length"]; + if ($diff["length"] !== 1) + $info .= ",".$diff["length"]; $info .= " +"; $info .= $diff["startLine2"]; $info .= ",0";