wiclear-2007-07-19/inc/classes/test/test_diff.php
<?
# ***** BEGIN LICENSE BLOCK *****
# This file is part of WiClear.
# Copyright (c) 2004-2007 David Jobet. All rights
# reserved.
#
# WiClear is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# WiClear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# ***** END LICENSE BLOCK *****
// text the diff algorithm with a few examples
require "../diff.class.php";
function displayList($list)
{
echo "<ol>";
foreach ($list as $line)
{
echo "<li>".$line->line."</li>";
}
echo "</ol>";
}
function test($text1, $text2)
{
$differ = new diff($text1, $text2);
displayList($differ->list1);
displayList($differ->list2);
echo $differ->toHtml("", "");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>DIFF</title>
<link rel="stylesheet" type="text/css" href="test_diff_style.css" media="screen"/>
</head>
<body>
<?
$text1 =
"Bon ben voila un petit peu de contenu pour tester un peu ce diff de mes deux ...\n".
"Pis en voila un peu plus parce que bon enfin ...";
$text2 =
"Bon ben voila un petit peu de contenu pour tester un peu ce diff de mes deux ...\n".
"Pis en voila un peu plus parce que bon enfin ...\n".
"Et pis bon, on va en rajouter un peu pour voir";
test($text1, $text2);
$text1 =
"ceci est un texte\n".
"ceci est un autre texte\n".
"voila un autre bout";
$text2 =
"ceci est un texte\n".
"ceci n\'est pas un autre texte\n".
"voila un autre bout\n".
"et encore une autre";
test($text1, $text2);
$text1 =
"ceci est un texte\n".
"ceci n\'est pas un autre texte\n".
"ceci est un autre texte\n".
"voila un autre bout";
$text2 =
"ceci est un texte\n".
"ceci n\'est pas un autre texte\n".
"voila un autre bout\n".
"et encore une autre";
test($text1, $text2);
$text1 =
"ceci n\'est pas un autre texte\n".
"ceci est un autre texte\n".
"voila un autre bout";
$text2 =
"ceci est un texte\n".
"ceci n\'est pas un autre texte\n".
"voila un autre bout\n".
"et encore une autre";
test($text1, $text2);
$text1 =
"ceci est un texte\n".
"ceci n\'est pas un autre texte\n".
"ceci est un autre texte\n".
"voila un autre bout";
$text2 =
"ceci n\'est pas un autre texte\n".
"voila un autre bout\n".
"et encore une autre";
test($text1, $text2);
$text1 =
"Common\n".
"Common\n".
"Common\n".
"Diff0\n".
"Common";
$text2 =
"Common\n".
"Common\n".
"Common\n".
"Diff1\n".
"Diff2\n".
"Common";
test($text1, $text2);
$text1 =
"Common\n".
"Common\n".
"Common\n".
"Diff0\n".
"Diff1\n".
"Common";
$text2 =
"Common\n".
"Common\n".
"Common\n".
"Diff2\n".
"Common";
test($text1, $text2);
$text1 =
"Common\n".
"Common\n".
"Common\n".
"Diff0\n".
"Diff1\n".
"Common";
$text2 =
"Common\n".
"Common\n".
"Common\n".
"Diff2\n".
"Diff3\n".
"Common";
test($text1, $text2);
$text1 =
"Common0\n".
"Common1\n".
"Common2\n".
"Diff0\n".
"Common";
$text2 =
"Common0\n".
"Common1\n".
"Common2\n".
"Diff1\n".
"Common";
test($text1, $text2);
// last example is not properly handled by current diff algorithm
$text1 =
"Common0\n".
"Common1\n".
"Common2\n".
"Diff0\n".
"Common3\n".
"Common4\n".
"Common5";
$text2 =
"Common0\n".
"Common1\n".
"Common2\n".
"Diff0\n". // algo find this line to be identical
"Diff1\n".
"Diff0\n". // wherever it should find this one as the number of change would then be smaller
"Common3\n".
"Common4\n".
"Common5";
test($text1, $text2);
?>
</body>
</html>