diff --git a/src/Renderer/Html/Combined.php b/src/Renderer/Html/Combined.php index fa00f066..3909abfe 100644 --- a/src/Renderer/Html/Combined.php +++ b/src/Renderer/Html/Combined.php @@ -239,7 +239,7 @@ protected function renderTableBlockReplace(array $block): string $this->renderTableBlockDelete($block) . $this->renderTableBlockInsert($block); - continue; + break; } $ret .= $this->renderTableRow('rep', SequenceMatcher::OP_REP, $mergedLine); diff --git a/tests/Renderer/Html/CombinedTest.php b/tests/Renderer/Html/CombinedTest.php index d4e1e2cc..f76dcd10 100644 --- a/tests/Renderer/Html/CombinedTest.php +++ b/tests/Renderer/Html/CombinedTest.php @@ -47,4 +47,27 @@ public function testHtmlEscapeForOpEq(): void static::assertThat($result, static::logicalNot(static::stringContains(''))); static::assertThat($result, static::logicalNot(static::stringContains(''))); } + + /** + * Test unmerge-able block. + * + * @see https://github.com/jfcherng/php-diff/issues/69 + */ + public function testSimpleUnmergeableBlock(): void + { + $result = DiffHelper::calculate("111\n222\n333\n", "444\n555\n666\n", 'Combined'); + + static::assertSame( + [1, 1, 1, 1, 1, 1], + [ + \substr_count($result, '111'), + \substr_count($result, '222'), + \substr_count($result, '333'), + \substr_count($result, '444'), + \substr_count($result, '555'), + \substr_count($result, '666'), + ], + "Unmerge-able block shouldn't be repeated." + ); + } }