Commit 51390a5e authored by catch's avatar catch
Browse files

Issue #3386482 by alexpott, mondrake: DiffOpOutputBuilder does not correctly...

Issue #3386482 by alexpott, mondrake: DiffOpOutputBuilder does not correctly match the 10.0.x implementation and produces unexpected output

(cherry picked from commit a5c3cdbd)
parent 928467a9
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -61,13 +61,9 @@ public function toOpsArray(array $diff): array {
        if (count($hunkTarget) === 0) {
          $ops[] = $this->hunkOp(Differ::REMOVED, $hunkSource, $hunkTarget);
        }
        elseif (count($hunkSource) === count($hunkTarget)) {
        elseif (count($hunkSource) >= count($hunkTarget)) {
          $ops[] = $this->hunkOp(self::CHANGED, $hunkSource, $hunkTarget);
        }
        elseif (count($hunkSource) > count($hunkTarget)) {
          $ops[] = $this->hunkOp(self::CHANGED, array_slice($hunkSource, 0, count($hunkTarget)), $hunkTarget);
          $ops[] = $this->hunkOp(Differ::REMOVED, array_slice($hunkSource, count($hunkTarget)), []);
        }
        else {
          $ops[] = $this->hunkOp(self::CHANGED, $hunkSource, array_slice($hunkTarget, 0, count($hunkSource)));
          $ops[] = $this->hunkOp(Differ::ADDED, array_slice($hunkTarget, count($hunkSource)), []);
+8 −0
Original line number Diff line number Diff line
@@ -65,6 +65,14 @@ public function provideTestDiff(): array {
        ['a', 'b', 'd'],
        ['a'],
      ],
      'change-copy' => [
        [
          new DiffOpChange(['aa', 'bb', 'cc'], ['a', 'c']),
          new DiffOpCopy(['d']),
        ],
        ['aa', 'bb', 'cc', 'd'],
        ['a', 'c', 'd'],
      ],
    ];
  }