[svn r16525] update Text Diff 1.0.0 to Text Diff 1.1.0

skala
Juan Carlos Raña 17 years ago
parent 3a27acc3c3
commit d3450058a0
  1. 42
      main/inc/lib/pear/Text/Diff.php
  2. 7
      main/inc/lib/pear/Text/Diff/Engine/native.php
  3. 2
      main/inc/lib/pear/Text/Diff/Engine/shell.php
  4. 33
      main/inc/lib/pear/Text/Diff/Engine/string.php
  5. 2
      main/inc/lib/pear/Text/Diff/Engine/xdiff.php
  6. 2
      main/inc/lib/pear/Text/Diff/Mapped.php
  7. 2
      main/inc/lib/pear/Text/Diff/Renderer.php
  8. 2
      main/inc/lib/pear/Text/Diff/Renderer/context.php
  9. 2
      main/inc/lib/pear/Text/Diff/Renderer/inline.php
  10. 2
      main/inc/lib/pear/Text/Diff/Renderer/unified.php
  11. 2
      main/inc/lib/pear/Text/Diff/ThreeWay.php
  12. 2
      main/inc/lib/pear/Text/Diff3.php
  13. 3
      main/inc/lib/pear/Text/docs/examples/1.txt
  14. 3
      main/inc/lib/pear/Text/docs/examples/2.txt
  15. 39
      main/inc/lib/pear/Text/docs/examples/diff.php
  16. 3
      main/inc/lib/pear/Text/tests/1.txt
  17. 3
      main/inc/lib/pear/Text/tests/2.txt
  18. 4
      main/inc/lib/pear/Text/tests/3.txt
  19. 3
      main/inc/lib/pear/Text/tests/4.txt
  20. 5
      main/inc/lib/pear/Text/tests/5.txt
  21. 7
      main/inc/lib/pear/Text/tests/6.txt
  22. 11
      main/inc/lib/pear/Text/tests/context.patch
  23. 25
      main/inc/lib/pear/Text/tests/context.phpt
  24. 31
      main/inc/lib/pear/Text/tests/context2.phpt
  25. 62
      main/inc/lib/pear/Text/tests/diff.phpt
  26. 19
      main/inc/lib/pear/Text/tests/inline.phpt
  27. 37
      main/inc/lib/pear/Text/tests/inline2.phpt
  28. 30
      main/inc/lib/pear/Text/tests/pear_bug12740.phpt
  29. 30
      main/inc/lib/pear/Text/tests/pear_bug4879.phpt
  30. 45
      main/inc/lib/pear/Text/tests/pear_bug6251.phpt
  31. 18
      main/inc/lib/pear/Text/tests/pear_bug6428.phpt
  32. 145
      main/inc/lib/pear/Text/tests/string.phpt
  33. 7
      main/inc/lib/pear/Text/tests/unified.patch
  34. 21
      main/inc/lib/pear/Text/tests/unified.phpt
  35. 26
      main/inc/lib/pear/Text/tests/unified2.phpt

@ -6,7 +6,7 @@
* The original PHP version of this code was written by Geoffrey T. Dairiki
* <dairiki@dairiki.org>, and is used/adapted with his permission.
*
* $Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $
* $Horde: framework/Text_Diff/Diff.php,v 1.11.2.11 2008/02/24 10:57:46 jan Exp $
*
* Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org>
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
@ -63,6 +63,46 @@ class Text_Diff {
{
return $this->_edits;
}
/**
* returns the number of new (added) lines in a given diff.
*
* @since Text_Diff 1.1.0
* @since Horde 3.2
*
* @return integer The number of new lines
*/
function countAddedLines()
{
$count = 0;
foreach ($this->_edits as $edit) {
if (is_a($edit, 'Text_Diff_Op_add') ||
is_a($edit, 'Text_Diff_Op_change')) {
$count += $edit->nfinal();
}
}
return $count;
}
/**
* Returns the number of deleted (removed) lines in a given diff.
*
* @since Text_Diff 1.1.0
* @since Horde 3.2
*
* @return integer The number of deleted lines
*/
function countDeletedLines()
{
$count = 0;
foreach ($this->_edits as $edit) {
if (is_a($edit, 'Text_Diff_Op_delete') ||
is_a($edit, 'Text_Diff_Op_change')) {
$count += $edit->norig();
}
}
return $count;
}
/**
* Computes a reversed diff.

@ -1,9 +1,8 @@
<?php
/**
* $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.10 2008/01/04 10:27:53 jan Exp $
* Class used internally by Text_Diff to actually compute the diffs.
*
* Class used internally by Text_Diff to actually compute the diffs. This
* class is implemented using native PHP code.
* This class is implemented using native PHP code.
*
* The algorithm used here is mostly lifted from the perl module
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
@ -19,6 +18,8 @@
* Geoffrey T. Dairiki <dairiki@dairiki.org>. The original PHP version of this
* code was written by him, and is used/adapted with his permission.
*
* $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.7.2.4 2008/01/04 10:38:10 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did

@ -5,7 +5,7 @@
* This class uses the Unix `diff` program via shell_exec to compute the
* differences between the two input arrays.
*
* $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.8 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.6.2.3 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2007-2008 The Horde Project (http://www.horde.org/)
*

@ -10,7 +10,7 @@
* echo $renderer->render($diff);
* </code>
*
* $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.5.2.5 2008/09/10 08:31:58 jan Exp $
*
* Copyright 2005 Örjan Persson <o@42mm.org>
* Copyright 2005-2008 The Horde Project (http://www.horde.org/)
@ -48,17 +48,20 @@ class Text_Diff_Engine_string {
$unified = strpos($diff, '---');
if ($context === $unified) {
return PEAR::raiseError('Type of diff could not be detected');
} elseif ($context === false || $context === false) {
} elseif ($context === false || $unified === false) {
$mode = $context !== false ? 'context' : 'unified';
} else {
$mode = $context < $unified ? 'context' : 'unified';
}
}
// split by new line and remove the diff header
// Split by new line and remove the diff header, if there is one.
$diff = explode("\n", $diff);
array_shift($diff);
array_shift($diff);
if (($mode == 'context' && strpos($diff[0], '***') === 0) ||
($mode == 'unified' && strpos($diff[0], '---') === 0)) {
array_shift($diff);
array_shift($diff);
}
if ($mode == 'context') {
return $this->parseContextDiff($diff);
@ -85,7 +88,7 @@ class Text_Diff_Engine_string {
do {
$diff1[] = substr($diff[$i], 1);
} while (++$i < $end && substr($diff[$i], 0, 1) == ' ');
$edits[] = &new Text_Diff_Op_copy($diff1);
$edits[] = new Text_Diff_Op_copy($diff1);
break;
case '+':
@ -93,7 +96,7 @@ class Text_Diff_Engine_string {
do {
$diff1[] = substr($diff[$i], 1);
} while (++$i < $end && substr($diff[$i], 0, 1) == '+');
$edits[] = &new Text_Diff_Op_add($diff1);
$edits[] = new Text_Diff_Op_add($diff1);
break;
case '-':
@ -107,9 +110,9 @@ class Text_Diff_Engine_string {
$diff2[] = substr($diff[$i++], 1);
}
if (count($diff2) == 0) {
$edits[] = &new Text_Diff_Op_delete($diff1);
$edits[] = new Text_Diff_Op_delete($diff1);
} else {
$edits[] = &new Text_Diff_Op_change($diff1, $diff2);
$edits[] = new Text_Diff_Op_change($diff1, $diff2);
}
break;
@ -175,7 +178,7 @@ class Text_Diff_Engine_string {
$array[] = substr($diff[$j++], 2);
}
if (count($array) > 0) {
$edits[] = &new Text_Diff_Op_copy($array);
$edits[] = new Text_Diff_Op_copy($array);
}
if ($i < $max_i) {
@ -189,21 +192,21 @@ class Text_Diff_Engine_string {
$diff2[] = substr($diff[$j++], 2);
}
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '!');
$edits[] = &new Text_Diff_Op_change($diff1, $diff2);
$edits[] = new Text_Diff_Op_change($diff1, $diff2);
break;
case '+':
do {
$diff1[] = substr($diff[$i], 2);
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '+');
$edits[] = &new Text_Diff_Op_add($diff1);
$edits[] = new Text_Diff_Op_add($diff1);
break;
case '-':
do {
$diff1[] = substr($diff[$i], 2);
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '-');
$edits[] = &new Text_Diff_Op_delete($diff1);
$edits[] = new Text_Diff_Op_delete($diff1);
break;
}
}
@ -215,14 +218,14 @@ class Text_Diff_Engine_string {
do {
$diff2[] = substr($diff[$j++], 2);
} while ($j < $max_j && substr($diff[$j], 0, 1) == '+');
$edits[] = &new Text_Diff_Op_add($diff2);
$edits[] = new Text_Diff_Op_add($diff2);
break;
case '-':
do {
$diff2[] = substr($diff[$j++], 2);
} while ($j < $max_j && substr($diff[$j], 0, 1) == '-');
$edits[] = &new Text_Diff_Op_delete($diff2);
$edits[] = new Text_Diff_Op_delete($diff2);
break;
}
}

@ -5,7 +5,7 @@
* This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
* to compute the differences between the two input arrays.
*
* $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.4.2.3 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*

@ -1,6 +1,6 @@
<?php
/**
* $Horde: framework/Text_Diff/Diff/Mapped.php,v 1.5 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/Mapped.php,v 1.3.2.3 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2007-2008 The Horde Project (http://www.horde.org/)
*

@ -5,7 +5,7 @@
* This class renders the diff in classic diff format. It is intended that
* this class be customized via inheritance, to obtain fancier outputs.
*
* $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.21 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.5.10.10 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*

@ -4,7 +4,7 @@
*
* This class renders the diff in classic "context diff" format.
*
* $Horde: framework/Text_Diff/Diff/Renderer/context.php,v 1.5 2008/01/04 10:07:51 jan Exp $
* $Horde: framework/Text_Diff/Diff/Renderer/context.php,v 1.3.2.3 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*

@ -2,7 +2,7 @@
/**
* "Inline" diff renderer.
*
* $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.21 2008/01/04 10:07:51 jan Exp $
* $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.4.10.14 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*

@ -4,7 +4,7 @@
*
* This class renders the diff in classic "unified diff" format.
*
* $Horde: framework/Text_Diff/Diff/Renderer/unified.php,v 1.10 2008/01/04 10:07:51 jan Exp $
* $Horde: framework/Text_Diff/Diff/Renderer/unified.php,v 1.3.10.6 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
*

@ -2,7 +2,7 @@
/**
* A class for computing three way diffs.
*
* $Horde: framework/Text_Diff/Diff/ThreeWay.php,v 1.5 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff/ThreeWay.php,v 1.3.2.3 2008/01/04 10:37:27 jan Exp $
*
* Copyright 2007-2008 The Horde Project (http://www.horde.org/)
*

@ -2,7 +2,7 @@
/**
* A class for computing three way diffs.
*
* $Horde: framework/Text_Diff/Diff3.php,v 1.8 2008/01/04 10:07:50 jan Exp $
* $Horde: framework/Text_Diff/Diff3.php,v 1.2.10.6 2008/01/04 10:37:26 jan Exp $
*
* Copyright 2007-2008 The Horde Project (http://www.horde.org/)
*

@ -0,0 +1,3 @@
This line is the same.
This line is different in 1.txt
This line is the same.

@ -0,0 +1,3 @@
This line is the same.
This line is different in 2.txt
This line is the same.

@ -0,0 +1,39 @@
#!/usr/bin/php
<?php
/**
* Text_Diff example script.
*
* Take two files from the command line args and produce a unified
* diff of them.
*
* @package Text_Diff
*/
require_once 'Text/Diff.php';
require_once 'Text/Diff/Renderer.php';
require_once 'Text/Diff/Renderer/unified.php';
/* Make sure we have enough arguments. */
if (count($argv) < 3) {
echo "Usage: diff.php <file1> <file2>\n\n";
exit;
}
/* Make sure both files exist. */
if (!is_readable($argv[1])) {
echo "$argv[1] not found or not readable.\n\n";
}
if (!is_readable($argv[2])) {
echo "$argv[2] not found or not readable.\n\n";
}
/* Load the lines of each file. */
$lines1 = file($argv[1]);
$lines2 = file($argv[2]);
/* Create the Diff object. */
$diff = new Text_Diff('auto', array($lines1, $lines2));
/* Output the diff in unified format. */
$renderer = new Text_Diff_Renderer_unified();
echo $renderer->render($diff);

@ -0,0 +1,3 @@
This line is the same.
This line is different in 1.txt
This line is the same.

@ -0,0 +1,3 @@
This line is the same.
This line is different in 2.txt
This line is the same.

@ -0,0 +1,4 @@
This line is the same.
This line is different in 1.txt
This line is the same.
This line is new in 3.txt

@ -0,0 +1,3 @@
This line is the same.
This line is different in 4.txt
This line is the same.

@ -0,0 +1,5 @@
This is a test.
Adding random text to simulate files.
Various Content.
More Content.
Testing diff and renderer.

@ -0,0 +1,7 @@
This is a test.
Adding random text to simulate files.
Inserting a line.
Various Content.
Replacing content.
Testing similarities and renderer.
Append content.

@ -0,0 +1,11 @@
*** 1.txt 2005-03-21 13:37:59.000000000 +0100
--- 2.txt 2005-03-21 13:38:00.000000000 +0100
***************
*** 1,3 ****
This line is the same.
! This line is different in 1.txt
This line is the same.
--- 1,3 ----
This line is the same.
! This line is different in 2.txt
This line is the same.

@ -0,0 +1,25 @@
--TEST--
Text_Diff: Context renderer
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/context.php';
$lines1 = file(dirname(__FILE__) . '/1.txt');
$lines2 = file(dirname(__FILE__) . '/2.txt');
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_context();
echo $renderer->render($diff);
?>
--EXPECT--
***************
*** 1,3 ****
This line is the same.
! This line is different in 1.txt
This line is the same.
--- 1,3 ----
This line is the same.
! This line is different in 2.txt
This line is the same.

@ -0,0 +1,31 @@
--TEST--
Text_Diff: Context renderer 2
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/context.php';
$lines1 = file(dirname(__FILE__) . '/5.txt');
$lines2 = file(dirname(__FILE__) . '/6.txt');
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_context();
echo $renderer->render($diff);
?>
--EXPECT--
***************
*** 1,5 ****
This is a test.
Adding random text to simulate files.
Various Content.
! More Content.
! Testing diff and renderer.
--- 1,7 ----
This is a test.
Adding random text to simulate files.
+ Inserting a line.
Various Content.
! Replacing content.
! Testing similarities and renderer.
! Append content.

@ -0,0 +1,62 @@
--TEST--
Text_Diff: Basic diff operation
--FILE--
<?php
include_once 'Text/Diff.php';
$lines1 = file(dirname(__FILE__) . '/1.txt');
$lines2 = file(dirname(__FILE__) . '/2.txt');
$diff = &new Text_Diff($lines1, $lines2);
echo strtolower(print_r($diff, true));
?>
--EXPECT--
text_diff object
(
[_edits] => array
(
[0] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
[1] => text_diff_op_change object
(
[orig] => array
(
[0] => this line is different in 1.txt
)
[final] => array
(
[0] => this line is different in 2.txt
)
)
[2] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
)
)

@ -0,0 +1,19 @@
--TEST--
Text_Diff: Inline renderer
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/inline.php';
$lines1 = file(dirname(__FILE__) . '/1.txt');
$lines2 = file(dirname(__FILE__) . '/2.txt');
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_inline();
echo $renderer->render($diff);
?>
--EXPECT--
This line is the same.
This line is different in <del>1.txt</del><ins>2.txt</ins>
This line is the same.

@ -0,0 +1,37 @@
--TEST--
Text_Diff: Inline renderer 2
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/inline.php';
$lines1 = array(
"This is a test.\n",
"Adding random text to simulate files.\n",
"Various Content.\n",
"More Content.\n",
"Testing diff and renderer.\n"
);
$lines2 = array(
"This is a test.\n",
"Adding random text to simulate files.\n",
"Inserting a line.\n",
"Various Content.\n",
"Replacing content.\n",
"Testing similarities and renderer.\n",
"Append content.\n"
);
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_inline();
echo $renderer->render($diff);
?>
--EXPECT--
This is a test.
Adding random text to simulate files.
<ins>Inserting a line.</ins>
Various Content.
<del>More Content.</del><ins>Replacing content.</ins>
Testing <del>diff</del><ins>similarities</ins> and renderer.<ins>
Append content.</ins>

@ -0,0 +1,30 @@
--TEST--
Text_Diff: PEAR Bug #12740 (failed assertion)
--FILE--
<?php
require dirname(__FILE__) . '/../Diff.php';
require dirname(__FILE__) . '/../Diff/Renderer/inline.php';
$a = <<<QQ
<li>The tax credit amounts to 30% of the cost of the system, with a
maximum of 2,000. This credit is separate from the 500 home improvement
credit.</li>
<h3>Fuel Cells<a
href="12341234213421341234123412341234123421341234213412342134213423"
class="anchor" title="Link to this section"><br />
<li>Your fuel 123456789</li>
QQ;
$b = <<<QQ
<li> of gas emissions by 2050</li>
<li>Raise car fuel economy to 50 mpg by 2017</li>
<li>Increase access to mass transit systems</li>
QQ;
$diff = new Text_Diff(explode("\n", $b), explode("\n", $a));
$renderer = new Text_Diff_Renderer_inline();
$renderer->render($diff);
?>
--EXPECT--

@ -0,0 +1,30 @@
--TEST--
Text_Diff: PEAR Bug #4879 (inline renderer hangs on numbers in input string)
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/inline.php';
$oldtext = <<<EOT
Common text
Bob had 1 apple, Alice had 2.
Bon appetit!
EOT;
$newtext = <<< EOT
Common text
Bob had 10 apples, Alice had 1.
Bon appetit!
EOT;
$oldpieces = explode ("\n", $oldtext);
$newpieces = explode ("\n", $newtext);
$diff = &new Text_Diff ($oldpieces, $newpieces);
$renderer = &new Text_Diff_Renderer_inline();
echo $renderer->render($diff);
?>
--EXPECT--
Common text
Bob had <del>1 apple,</del><ins>10 apples,</ins> Alice had <del>2.</del><ins>1.</ins>
Bon appetit!

@ -0,0 +1,45 @@
--TEST--
Text_Diff: PEAR Bug #6251 (too much trailing context)
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/unified.php';
$oldtext = <<<EOT
Original Text
ss
ttt
EOT;
$newtext = <<< EOT
Modified Text
ss
ttt
EOT;
$oldpieces = explode ("\n", $oldtext);
$newpieces = explode ("\n", $newtext);
$diff = &new Text_Diff ($oldpieces, $newpieces);
$renderer = &new Text_Diff_Renderer_unified(array('leading_context_lines' => 3, 'trailing_context_lines' => 3));
// We need to use var_dump, as the test runner strips trailing empty lines.
var_dump($renderer->render($diff));
?>
--EXPECT--
string(54) "@@ -1,5 +1,5 @@
-Original Text
+Modified Text
"

@ -0,0 +1,18 @@
--TEST--
Text_Diff: PEAR Bug #6428 (problem with single digits after space)
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/inline.php';
$from = array('Line 1', 'Another line');
$to = array('Line 1', 'Another line');
$diff = &new Text_Diff ($from, $to);
$renderer = &new Text_Diff_Renderer_inline();
echo $renderer->render($diff);
?>
--EXPECT--
Line <del>1</del><ins> 1</ins>
Another line

@ -0,0 +1,145 @@
--TEST--
Text_Diff: Text_Diff_Engine_string test.
--FILE--
<?php
require_once 'PEAR.php';
require_once 'Text/Diff.php';
$unified = file_get_contents(dirname(__FILE__) . '/unified.patch');
$diff_u = new Text_Diff('string', array($unified));
echo strtolower(print_r($diff_u, true));
$unified2 = file_get_contents(dirname(__FILE__) . '/unified2.patch');
$diff_u2 = new Text_Diff('string', array($unified2));
var_export(is_a($diff_u2->getDiff(), 'PEAR_Error'));
echo "\n";
$diff_u2 = new Text_Diff('string', array($unified2, 'unified'));
echo strtolower(print_r($diff_u2, true));
$context = file_get_contents(dirname(__FILE__) . '/context.patch');
$diff_c = new Text_Diff('string', array($context));
echo strtolower(print_r($diff_c, true));
?>
--EXPECT--
text_diff object
(
[_edits] => array
(
[0] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
[1] => text_diff_op_change object
(
[orig] => array
(
[0] => this line is different in 1.txt
)
[final] => array
(
[0] => this line is different in 2.txt
)
)
[2] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
)
)
true
text_diff object
(
[_edits] => array
(
[0] => text_diff_op_change object
(
[orig] => array
(
[0] => for the first time in u.s. history number of private contractors and troops are equal
)
[final] => array
(
[0] => number of private contractors and troops are equal for first time in u.s. history
)
)
)
)
text_diff object
(
[_edits] => array
(
[0] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
[1] => text_diff_op_change object
(
[orig] => array
(
[0] => this line is different in 1.txt
)
[final] => array
(
[0] => this line is different in 2.txt
)
)
[2] => text_diff_op_copy object
(
[orig] => array
(
[0] => this line is the same.
)
[final] => array
(
[0] => this line is the same.
)
)
)
)

@ -0,0 +1,7 @@
--- 1.txt 2005-03-21 13:37:59.000000000 +0100
+++ 2.txt 2005-03-21 13:38:00.000000000 +0100
@@ -1,3 +1,3 @@
This line is the same.
-This line is different in 1.txt
+This line is different in 2.txt
This line is the same.

@ -0,0 +1,21 @@
--TEST--
Text_Diff: Unified renderer
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/unified.php';
$lines1 = file(dirname(__FILE__) . '/1.txt');
$lines2 = file(dirname(__FILE__) . '/2.txt');
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_unified();
echo $renderer->render($diff);
?>
--EXPECT--
@@ -1,3 +1,3 @@
This line is the same.
-This line is different in 1.txt
+This line is different in 2.txt
This line is the same.

@ -0,0 +1,26 @@
--TEST--
Text_Diff: Unified renderer 2
--FILE--
<?php
include_once 'Text/Diff.php';
include_once 'Text/Diff/Renderer/unified.php';
$lines1 = file(dirname(__FILE__) . '/5.txt');
$lines2 = file(dirname(__FILE__) . '/6.txt');
$diff = &new Text_Diff($lines1, $lines2);
$renderer = &new Text_Diff_Renderer_unified();
echo $renderer->render($diff);
?>
--EXPECT--
@@ -1,5 +1,7 @@
This is a test.
Adding random text to simulate files.
+Inserting a line.
Various Content.
-More Content.
-Testing diff and renderer.
+Replacing content.
+Testing similarities and renderer.
+Append content.
Loading…
Cancel
Save