Skip to content

Commit

Permalink
fix: (Combined) unmerge-able block shouldn't be repeated
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
jfcherng committed Mar 15, 2023
1 parent 63bbde6 commit 3582a09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Renderer/Html/Combined.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions tests/Renderer/Html/CombinedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,27 @@ public function testHtmlEscapeForOpEq(): void
static::assertThat($result, static::logicalNot(static::stringContains('<tag>')));
static::assertThat($result, static::logicalNot(static::stringContains('</tag>')));
}

/**
* 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."
);
}
}

0 comments on commit 3582a09

Please sign in to comment.