From aeb1c3c9ffa6e0c52bda4c266fd00d4d21e43224 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Thu, 16 Mar 2023 03:21:34 +0800 Subject: [PATCH] fix: (Combined) unmerge-able block shouldn't be repeated Signed-off-by: Jack Cherng --- src/Renderer/Html/Combined.php | 2 +- tests/Renderer/Html/CombinedTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Renderer/Html/Combined.php b/src/Renderer/Html/Combined.php index 8b7a700a..4b7077ba 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 9a629252..9d99fa61 100644 --- a/tests/Renderer/Html/CombinedTest.php +++ b/tests/Renderer/Html/CombinedTest.php @@ -45,4 +45,27 @@ public function testHtmlEscapeForOpEq(): void static::assertStringNotContainsString('', $result); static::assertStringNotContainsString('', $result); } + + /** + * 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.", + ); + } }