コード例 #1
0
/**
 * Runs diff and interprets results into ouwiki_changes object.
 * @param array $file1 Array of lines in file 1. The first line in the file
 *   MUST BE INDEX 1 NOT ZERO!!
 * @param array $file2 Array of lines in file 2, again starting from 1.
 * @return ouwiki_changes Object describing changes
 */
function ouwiki_diff($file1, $file2)
{
    return new ouwiki_changes(ouwiki_diff_internal($file1, $file2), count($file2));
}
コード例 #2
0
 function test_basic_diff()
 {
     // Example from paper
     $file1 = array(1 => 'a', 'b', 'c', 'd', 'e', 'f', 'g');
     $file2 = array(1 => 'w', 'a', 'b', 'x', 'y', 'z', 'e');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 2, 2 => 3, 3 => 0, 4 => 0, 5 => 7, 6 => 0, 7 => 0));
     $this->assertEqual(ouwiki_diff_internal($file2, $file1), array(1 => 0, 2 => 1, 3 => 2, 4 => 0, 5 => 0, 6 => 0, 7 => 5));
     // Add text at beginning
     $file2 = array(1 => '0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 3, 2 => 4, 3 => 5, 4 => 6, 5 => 7, 6 => 8, 7 => 9));
     // Add text at end
     $file2 = array(1 => 'a', 'b', 'c', 'd', 'e', 'f', 'g', '0', '1');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7));
     // Add text in middle
     $file2 = array(1 => 'a', 'b', 'c', '0', '1', 'd', 'e', 'f', 'g');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 1, 2 => 2, 3 => 3, 4 => 6, 5 => 7, 6 => 8, 7 => 9));
     // Delete text at beginning
     $file2 = array(1 => 'c', 'd', 'e', 'f', 'g');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 0, 2 => 0, 3 => 1, 4 => 2, 5 => 3, 6 => 4, 7 => 5));
     // Delete text at end
     $file2 = array(1 => 'a', 'b', 'c', 'd', 'e');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 0, 7 => 0));
     // Delete text in middle
     $file2 = array(1 => 'a', 'b', 'c', 'f', 'g');
     $this->assertEqual(ouwiki_diff_internal($file1, $file2), array(1 => 1, 2 => 2, 3 => 3, 4 => 0, 5 => 0, 6 => 4, 7 => 5));
 }