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"))); }
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(); }
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"))); }
/** * 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); } }
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"))); } }
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"))); }
public function testNestedOutputHtml() { $table1 = harness_Native::table($this->data1); $table2 = harness_Native::table($this->data2); $alignment = coopy_Coopy::compareTables($table1, $table2, null)->align(); $table_diff1 = harness_Native::table(new _hx_array(array())); $table_diff2 = harness_Native::table(new _hx_array(array())); $flags = new coopy_CompareFlags(); $highlighter1 = new coopy_TableDiff($alignment, $flags); $highlighter1->hilite($table_diff1); $flags->allow_nested_cells = true; $highlighter2 = new coopy_TableDiff($alignment, $flags); $highlighter2->hilite($table_diff2); $render1 = _hx_deref(new coopy_DiffRender())->render($table_diff1)->html(); $render2 = _hx_deref(new coopy_DiffRender())->render($table_diff2)->html(); $this->assertEquals($render1, $render2, _hx_anonymous(array("fileName" => "BasicTest.hx", "lineNumber" => 117, "className" => "harness.BasicTest", "methodName" => "testNestedOutputHtml"))); }
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; }
<?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();
static function diff($local, $remote, $flags = null) { $comp = new coopy_TableComparisonState(); $comp->a = $local; $comp->b = $remote; if ($flags === null) { $flags = new coopy_CompareFlags(); } $comp->compare_flags = $flags; $ct = new coopy_CompareTable($comp); $align = $ct->align(); $td = new coopy_TableDiff($align, $flags); $o = new coopy_SimpleTable(0, 0); $td->hilite($o); return $o; }