DiffOpAdd example


  private function hunkOp(int $mode, array $source, array $target): DiffOp {
    switch ($mode) {
      case Differ::OLD:
        return new DiffOpCopy($source);

      case self::CHANGED:
        return new DiffOpChange($source$target);

      case Differ::ADDED:
        return new DiffOpAdd($source);

      case Differ::REMOVED:
        return new DiffOpDelete($source);

    }
    throw new \InvalidArgumentException("Invalid \$mode {$mode} specified");
  }

}
$add = [];
      while ($yi < $n_to && $this->ychanged[$yi]) {
        $add[] = $to_lines[$yi++];
      }
      if ($delete && $add) {
        $edits[] = new DiffOpChange($delete$add);
      }
      elseif ($delete) {
        $edits[] = new DiffOpDelete($delete);
      }
      elseif ($add) {
        $edits[] = new DiffOpAdd($add);
      }
    }
    return $edits;
  }

  /** * Returns the whole line if it's small enough, or a hash otherwise. */
  protected function _line_hash($line) {
    if (mb_strlen($line) > $this::MAX_XREF_LENGTH) {
      return hash('crc32b', $line);
    }

  public function testDiffInfiniteLoop() {
    $this->expectDeprecation('Drupal\Component\Diff\Engine\DiffEngine is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use sebastianbergmann/diff instead. See https://www.drupal.org/node/3337942');
    $from = explode("\n", file_get_contents(__DIR__ . '/fixtures/file1.txt'));
    $to = explode("\n", file_get_contents(__DIR__ . '/fixtures/file2.txt'));
    $diff_engine = new DiffEngine();
    $diff = $diff_engine->diff($from$to);
    $this->assertCount(4, $diff);
    $this->assertEquals($diff[0]new DiffOpDelete([' - image.style.max_650x650']));
    $this->assertEquals($diff[1]new DiffOpCopy([' - image.style.max_325x325']));
    $this->assertEquals($diff[2]new DiffOpAdd([' - image.style.max_650x650', '_core:', ' default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM']));
    $this->assertEquals($diff[3]new DiffOpCopy(['fallback_image_style: max_325x325', '']));
  }

}
/** * @return array * - Expected output in terms of return class. A list of class names * expected to be returned by DiffEngine::diff(). * - An array of strings to change from. * - An array of strings to change to. */
  public function provideTestDiff(): array {
    return [
      'empty' => [[][][]],
      'add' => [[new DiffOpAdd(['a'])][]['a']],
      'copy' => [[new DiffOpCopy(['a'])]['a']['a']],
      'change' => [[new DiffOpChange(['a']['b'])]['a']['b']],
      'copy-and-change' => [
        [
          new DiffOpCopy(['a']),
          new DiffOpChange(['b']['c']),
        ],
        ['a', 'b'],
        ['a', 'c'],
      ],
      'copy-change-copy' => [
        [
$this->closing = FALSE;
  }

  /** * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no * replacement. * * @see https://www.drupal.org/node/3337942 */
  public function reverse() {
    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
    return new DiffOpAdd($this->orig);
  }

}
Home | Imprint | This part of the site doesn't use cookies.