コード例 #1
0
ファイル: BasicTest.php プロジェクト: paulfitz/daff-php
 protected function _quickDiff($data1, $data2)
 {
     $table1 = new coopy_PhpTableView($data1);
     $table2 = new coopy_PhpTableView($data2);
     $data_diff = [];
     $table_diff = new coopy_PhpTableView($data_diff);
     $highlighter = new coopy_TableDiff(coopy_Coopy::compareTables($table1, $table2)->align(), new coopy_CompareFlags());
     $highlighter->hilite($table_diff);
     $diff2html = new coopy_DiffRender();
     $diff2html->usePrettyArrows(false);
     $diff2html->render($table_diff);
     return $diff2html->html();
 }
コード例 #2
0
ファイル: SpeedTest.php プロジェクト: paulfitz/daff-php
 public function testMedium()
 {
     $table1 = harness_Native::table($this->data1);
     $table2 = harness_Native::table($this->data2);
     $flags = new coopy_CompareFlags();
     $flags->unchanged_column_context = 3;
     $align = coopy_Coopy::compareTables($table1, $table2, null)->align();
     $diff = harness_Native::table(new _hx_array(array()));
     $highlighter = new coopy_TableDiff($align, $flags);
     $flags->ordered = false;
     $highlighter->hilite($diff);
     $this->assertEquals(1, 1, _hx_anonymous(array("fileName" => "SpeedTest.hx", "lineNumber" => 59, "className" => "harness.SpeedTest", "methodName" => "testMedium")));
 }
コード例 #3
0
ファイル: RowOrderTest.php プロジェクト: paulfitz/daff-php
 public function testRowOrder()
 {
     $data1 = new _hx_array(array(new _hx_array(array("Country", "Capital")), new _hx_array(array("Ireland", "Dublin")), new _hx_array(array("France", "Paris")), new _hx_array(array("Spain", "Barcelona"))));
     $data2 = new _hx_array(array(new _hx_array(array("Country", "Code", "Capital")), new _hx_array(array("Ireland", "ie", "Dublin")), new _hx_array(array("France", "fr", "Paris")), new _hx_array(array("Spain", "es", "Madrid")), new _hx_array(array("Germany", "de", "Berlin"))));
     $table1 = harness_Native::table($data1);
     $table2 = harness_Native::table($data2);
     $alignment = coopy_Coopy::compareTables($table1, $table2, null)->align();
     $data_diff = new _hx_array(array());
     $table_diff = harness_Native::table($data_diff);
     $flags = new coopy_CompareFlags();
     $flags->always_show_order = true;
     $flags->never_show_order = false;
     $highlighter = new coopy_TableDiff($alignment, $flags);
     $highlighter->hilite($table_diff);
     $this->assertEquals("-:4", $table_diff->getCell(0, 6), _hx_anonymous(array("fileName" => "RowOrderTest.hx", "lineNumber" => 26, "className" => "harness.RowOrderTest", "methodName" => "testRowOrder")));
 }
コード例 #4
0
ファイル: BugTest.php プロジェクト: paulfitz/daff-php
 /**
  * Test rows are ordered correctly when a row is removed
  */
 public function testIssue11()
 {
     $data1 = [['Country', 'Capital'], ['Ireland', 'Dublin'], ['France', 'Paris'], ['Spain', 'Barcelona']];
     $data2 = [['Country', 'Capital'], ['Ireland', 'Dublin'], ['Spain', 'Madrid']];
     $table1 = new coopy_PhpTableView($data1);
     $table2 = new coopy_PhpTableView($data2);
     $data_diff = [];
     $table_diff = new coopy_PhpTableView($data_diff);
     $highlighter = new coopy_TableDiff(coopy_Coopy::compareTables($table1, $table2)->align(), new coopy_CompareFlags());
     $highlighter->hilite($table_diff);
     foreach ($table_diff->data as $row) {
         $sortedRow = $row;
         ksort($sortedRow, SORT_NUMERIC);
         $this->assertEquals($row, $sortedRow);
     }
 }
コード例 #5
0
ファイル: TypeTest.php プロジェクト: paulfitz/daff-php
 public function testList()
 {
     $data1 = new _hx_array(array(new _hx_array(array("id", "color", "length")), new _hx_array(array(15, "Red", 11.2))));
     $table1 = harness_Native::table($data1);
     $flags = new coopy_CompareFlags();
     $align = coopy_Coopy::compareTables($table1, $table1, null)->align();
     $diff = harness_Native::table(new _hx_array(array()));
     $highlighter = new coopy_TableDiff($align, $flags);
     $flags->always_show_order = true;
     $flags->never_show_order = false;
     $highlighter->hilite($diff);
     if ($diff->getData() !== null) {
         $this->assertTrue(harness_Native::isList($diff->getData()), _hx_anonymous(array("fileName" => "TypeTest.hx", "lineNumber" => 35, "className" => "harness.TypeTest", "methodName" => "testList")));
         $this->assertTrue(harness_Native::isList(harness_Native::row($diff->getData(), 0)), _hx_anonymous(array("fileName" => "TypeTest.hx", "lineNumber" => 36, "className" => "harness.TypeTest", "methodName" => "testList")));
         $this->assertTrue(harness_Native::isList(harness_Native::row($diff->getData(), 1)), _hx_anonymous(array("fileName" => "TypeTest.hx", "lineNumber" => 37, "className" => "harness.TypeTest", "methodName" => "testList")));
     }
 }
コード例 #6
0
ファイル: SmallTableTest.php プロジェクト: paulfitz/daff-php
 public function testIgnore()
 {
     $table1 = harness_Native::table($this->data1);
     $table2 = harness_Native::table($this->data2);
     $flags = new coopy_CompareFlags();
     $flags->columns_to_ignore = new _hx_array(array("key", "version"));
     $alignment = coopy_Coopy::compareTables3($table2, $table1, $table2, $flags)->align();
     $data_diff = new _hx_array(array());
     $table_diff = harness_Native::table($data_diff);
     $highlighter = new coopy_TableDiff($alignment, $flags);
     $highlighter->hilite($table_diff);
     $this->assertEquals($table_diff->get_height(), 1, _hx_anonymous(array("fileName" => "SmallTableTest.hx", "lineNumber" => 68, "className" => "harness.SmallTableTest", "methodName" => "testIgnore")));
     $this->assertEquals($table_diff->get_width(), 3, _hx_anonymous(array("fileName" => "SmallTableTest.hx", "lineNumber" => 69, "className" => "harness.SmallTableTest", "methodName" => "testIgnore")));
     $v = $table1->getCellView();
     $this->assertEquals($v->toString($table_diff->getCell(0, 0)), "@@", _hx_anonymous(array("fileName" => "SmallTableTest.hx", "lineNumber" => 71, "className" => "harness.SmallTableTest", "methodName" => "testIgnore")));
     $this->assertEquals($v->toString($table_diff->getCell(1, 0)), "NAME", _hx_anonymous(array("fileName" => "SmallTableTest.hx", "lineNumber" => 72, "className" => "harness.SmallTableTest", "methodName" => "testIgnore")));
     $this->assertEquals($v->toString($table_diff->getCell(2, 0)), "AGE", _hx_anonymous(array("fileName" => "SmallTableTest.hx", "lineNumber" => 73, "className" => "harness.SmallTableTest", "methodName" => "testIgnore")));
 }
コード例 #7
0
ファイル: BasicTest.php プロジェクト: sp-ruben-simon/daff-php
 public function testThreeWay()
 {
     $flags = new coopy_CompareFlags();
     $table1 = harness_Native::table($this->data1);
     $table2 = harness_Native::table($this->data2);
     $table3 = harness_Native::table($this->data3);
     $table4 = harness_Native::table($this->data4);
     $flags->parent = $table1;
     $out = coopy_Coopy::diff($table2, $table3, $flags);
     $table2b = $table2->hclone();
     coopy_Coopy::patch($table2b, $out, null);
     $this->assertTrue(coopy_SimpleTable::tableIsSimilar($table4, $table2b), _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 130, "className" => "harness.BasicTest", "methodName" => "testThreeWay")));
 }
コード例 #8
0
 public function addMeta($output)
 {
     $a_meta = null;
     $b_meta = null;
     $p_meta = null;
     $a_meta = $this->getMetaTable($this->a);
     $b_meta = $this->getMetaTable($this->b);
     $p_meta = $this->getMetaTable($this->p);
     if ($a_meta === null || $b_meta === null || $p_meta === null) {
         return false;
     }
     if (!$this->checkMeta($this->a, $a_meta)) {
         return false;
     }
     if (!$this->checkMeta($this->b, $b_meta)) {
         return false;
     }
     if (!$this->checkMeta($this->p, $p_meta)) {
         return false;
     }
     if (!$this->flags->show_meta) {
         return false;
     }
     $meta_diff = new coopy_SimpleTable(0, 0);
     $meta_flags = new coopy_CompareFlags();
     $meta_flags->addPrimaryKey("@@");
     $meta_flags->addPrimaryKey("@");
     $meta_flags->unchanged_column_context = 65536;
     $meta_flags->unchanged_context = 0;
     $meta_align = coopy_Coopy::compareTables3($a_meta === $p_meta ? null : $p_meta, $a_meta, $b_meta, $meta_flags)->align();
     $td = new coopy_TableDiff($meta_align, $meta_flags);
     $td->preserve_columns = true;
     $td->hilite($meta_diff);
     if ($td->hasDifference()) {
         $h = $output->get_height();
         $dh = $meta_diff->get_height();
         $offset = null;
         if ($td->hasSchemaDifference()) {
             $offset = 2;
         } else {
             $offset = 1;
         }
         $output->resize($output->get_width(), $h + $dh - $offset);
         $v = $meta_diff->getCellView();
         $_g = $offset;
         while ($_g < $dh) {
             $y = $_g++;
             $_g2 = 1;
             $_g1 = $meta_diff->get_width();
             while ($_g2 < $_g1) {
                 $x = $_g2++;
                 $c = $meta_diff->getCell($x, $y);
                 if ($x === 1) {
                     $c = "@" . _hx_string_or_null($v->toString($c)) . "@" . _hx_string_or_null($v->toString($meta_diff->getCell(0, $y)));
                 }
                 $output->setCell($x - 1, $h + $y - $offset, $c);
                 unset($x, $c);
             }
             unset($_g2, $_g1);
             unset($y);
         }
         if ($this->active_column !== null) {
             if ($td->active_column->length === $meta_diff->get_width()) {
                 $_g11 = 1;
                 $_g3 = $meta_diff->get_width();
                 while ($_g11 < $_g3) {
                     $i = $_g11++;
                     if ($td->active_column->a[$i] >= 0) {
                         $this->active_column[$i - 1] = 1;
                     }
                     unset($i);
                 }
             }
         }
     }
     return false;
 }
コード例 #9
0
 public function apply()
 {
     $this->conflicts = 0;
     $ct = coopy_Coopy::compareTables3($this->parent, $this->local, $this->remote, null);
     $align = $ct->align();
     $this->order = $align->toOrder();
     $this->units = $this->order->getList();
     $this->column_order = $align->meta->toOrder();
     $this->column_units = $this->column_order->getList();
     $allow_insert = $this->flags->allowInsert();
     $allow_delete = $this->flags->allowDelete();
     $allow_update = $this->flags->allowUpdate();
     $view = $this->parent->getCellView();
     $_g = 0;
     $_g1 = $this->units;
     while ($_g < $_g1->length) {
         $row = $_g1[$_g];
         ++$_g;
         if ($row->l >= 0 && $row->r >= 0 && $row->p >= 0) {
             $_g2 = 0;
             $_g3 = $this->column_units;
             while ($_g2 < $_g3->length) {
                 $col = $_g3[$_g2];
                 ++$_g2;
                 if ($col->l >= 0 && $col->r >= 0 && $col->p >= 0) {
                     $pcell = $this->parent->getCell($col->p, $row->p);
                     $rcell = $this->remote->getCell($col->r, $row->r);
                     if (!$view->equals($pcell, $rcell)) {
                         $lcell = $this->local->getCell($col->l, $row->l);
                         if ($view->equals($pcell, $lcell)) {
                             $this->local->setCell($col->l, $row->l, $rcell);
                         } else {
                             $this->local->setCell($col->l, $row->l, coopy_Merger::makeConflictedCell($view, $pcell, $lcell, $rcell));
                             $this->conflicts++;
                         }
                         unset($lcell);
                     }
                     unset($rcell, $pcell);
                 }
                 unset($col);
             }
             unset($_g3, $_g2);
         }
         unset($row);
     }
     $this->shuffleColumns();
     $this->shuffleRows();
     if (null == $this->column_mix_remote) {
         throw new HException('null iterable');
     }
     $__hx__it = $this->column_mix_remote->keys();
     while ($__hx__it->hasNext()) {
         unset($x);
         $x = $__hx__it->next();
         $x2 = $this->column_mix_remote->get($x);
         $_g4 = 0;
         $_g11 = $this->units;
         while ($_g4 < $_g11->length) {
             $unit = $_g11[$_g4];
             ++$_g4;
             if ($unit->l >= 0 && $unit->r >= 0) {
                 $this->local->setCell($x2, $this->row_mix_local->get($unit->l), $this->remote->getCell($x, $unit->r));
             } else {
                 if ($unit->p < 0 && $unit->r >= 0) {
                     $this->local->setCell($x2, $this->row_mix_remote->get($unit->r), $this->remote->getCell($x, $unit->r));
                 }
             }
             unset($unit);
         }
         unset($_g4, $_g11);
         unset($x2);
     }
     if (null == $this->row_mix_remote) {
         throw new HException('null iterable');
     }
     $__hx__it = $this->row_mix_remote->keys();
     while ($__hx__it->hasNext()) {
         unset($y);
         $y = $__hx__it->next();
         $y2 = $this->row_mix_remote->get($y);
         $_g5 = 0;
         $_g12 = $this->column_units;
         while ($_g5 < $_g12->length) {
             $unit1 = $_g12[$_g5];
             ++$_g5;
             if ($unit1->l >= 0 && $unit1->r >= 0) {
                 $this->local->setCell($this->column_mix_local->get($unit1->l), $y2, $this->remote->getCell($unit1->r, $y));
             }
             unset($unit1);
         }
         unset($_g5, $_g12);
         unset($y2);
     }
     return $this->conflicts;
 }
コード例 #10
0
ファイル: Coopy.class.php プロジェクト: paulfitz/daff-php
 static function main()
 {
     $io = new coopy_TableIO();
     $coopy1 = new coopy_Coopy(null);
     return $coopy1->coopyhx($io);
 }
コード例 #11
0
 public function render($tab)
 {
     $tab = coopy_Coopy::tablify($tab);
     if ($tab->get_width() === 0 || $tab->get_height() === 0) {
         return $this;
     }
     $render = $this;
     $render->beginTable();
     $change_row = -1;
     $cell = new coopy_CellInfo();
     $view = $tab->getCellView();
     $corner = $view->toString($tab->getCell(0, 0));
     $off = null;
     if ($corner === "@:@") {
         $off = 1;
     } else {
         $off = 0;
     }
     if ($off > 0) {
         if ($tab->get_width() <= 1 || $tab->get_height() <= 1) {
             return $this;
         }
     }
     $_g1 = 0;
     $_g = $tab->get_height();
     while ($_g1 < $_g) {
         $row = $_g1++;
         $open = false;
         $txt = $view->toString($tab->getCell($off, $row));
         if ($txt === null) {
             $txt = "";
         }
         coopy_DiffRender::examineCell($off, $row, $view, $txt, "", $txt, $corner, $cell, $off);
         $row_mode = $cell->category;
         if ($row_mode === "spec") {
             $change_row = $row;
         }
         if ($row_mode === "header" || $row_mode === "spec" || $row_mode === "index" || $row_mode === "meta") {
             $this->setSection("head");
         } else {
             $this->setSection("body");
         }
         $render->beginRow($row_mode);
         $_g3 = 0;
         $_g2 = $tab->get_width();
         while ($_g3 < $_g2) {
             $c = $_g3++;
             coopy_DiffRender::examineCell($c, $row, $view, $tab->getCell($c, $row), $change_row >= 0 ? $view->toString($tab->getCell($c, $change_row)) : "", $txt, $corner, $cell, $off);
             $render->insertCell(coopy_DiffRender_0($this, $_g, $_g1, $_g2, $_g3, $c, $cell, $change_row, $corner, $off, $open, $render, $row, $row_mode, $tab, $txt, $view), $cell->category_given_tr);
             unset($c);
         }
         unset($_g3, $_g2);
         $render->endRow();
         unset($txt, $row_mode, $row, $open);
     }
     $render->endTable();
     return $this;
 }
コード例 #12
0
ファイル: example.php プロジェクト: paulfitz/daff-php
<?php

if (version_compare(PHP_VERSION, '5.1.0', '<')) {
    exit('Your current PHP version is: ' . PHP_VERSION . '. Haxe/PHP generates code for version 5.1.0 or later');
}
require_once dirname(__FILE__) . '/lib/php/Boot.class.php';
$data1 = [['Country', 'Capital'], ['Ireland', 'Dublin'], ['France', 'Paris'], ['Spain', 'Barcelona']];
$data2 = [['Country', 'Code', 'Capital'], ['Ireland', 'ie', 'Dublin'], ['France', 'fr', 'Paris'], ['Spain', 'es', 'Madrid'], ['Germany', 'de', 'Berlin']];
$table1 = new coopy_PhpTableView($data1);
$table2 = new coopy_PhpTableView($data2);
$alignment = coopy_Coopy::compareTables($table1, $table2)->align();
$data_diff = [];
$table_diff = new coopy_PhpTableView($data_diff);
$flags = new coopy_CompareFlags();
$highlighter = new coopy_TableDiff($alignment, $flags);
$highlighter->hilite($table_diff);
$diff2html = new coopy_DiffRender();
$diff2html->usePrettyArrows(false);
$diff2html->render($table_diff);
$table_diff_html = $diff2html->html();
echo $table_diff_html;
$patcher = new coopy_HighlightPatch($table1, $table_diff);
$patcher->apply();
コード例 #13
0
ファイル: index.php プロジェクト: paulfitz/daff-php
<?php

if (version_compare(PHP_VERSION, '5.1.0', '<')) {
    exit('Your current PHP version is: ' . PHP_VERSION . '. Haxe/PHP generates code for version 5.1.0 or later');
}
require_once dirname(__FILE__) . '/lib/php/Boot.class.php';
coopy_Coopy::main();
コード例 #14
0
ファイル: TableDiff.class.php プロジェクト: paulfitz/daff-php
 public function hilite($output)
 {
     $output = coopy_Coopy::tablify($output);
     return $this->hiliteSingle($output);
 }
コード例 #15
0
ファイル: BasicTest.php プロジェクト: paulfitz/daff-php
 public function testAnsiOutput()
 {
     $table1 = harness_Native::table($this->data1);
     $table2 = harness_Native::table($this->data2);
     $txt = coopy_Coopy::diffAsAnsi($table1, $table2, null);
     $this->assertTrue(_hx_index_of($txt, "Germany", null) >= 0, _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 144, "className" => "harness.BasicTest", "methodName" => "testAnsiOutput")));
 }