Diff example

for ($i = 0; $i < $lineCount; ++$i) {
            if (preg_match('#^---\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i]$fromMatch) &&
                preg_match('#^\\+\\+\\+\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i + 1]$toMatch)) {
                if ($diff !== null) {
                    $this->parseFileDiff($diff$collected);

                    $diffs[]   = $diff;
                    $collected = [];
                }

                $diff = new Diff($fromMatch['file']$toMatch['file']);

                ++$i;
            } else {
                if (preg_match('/^(?:diff --git |index [\da-f\.]+|[+-]{3} [ab])/', $lines[$i])) {
                    continue;
                }

                $collected[] = $lines[$i];
            }
        }

        
      // Cast the result of t() to a string, as the diff engine doesn't know       // about objects.       $source_data = [(string) $this->t('File added')];
    }
    if ($target_data === ['false']) {
      // Deleted file.       // Cast the result of t() to a string, as the diff engine doesn't know       // about objects.       $target_data = [(string) $this->t('File removed')];
    }

    return new Diff($source_data$target_data);
  }

  /** * {@inheritdoc} */
  public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) {
    self::replaceStorageContents($source_storage$snapshot_storage);
  }

  /** * {@inheritdoc} */

    ];
  }

  /** * Tests whether op classes returned by DiffEngine::diff() match expectations. * * @covers ::format * @dataProvider provideTestDiff */
  public function testDiff($expected$from$to) {
    $diff = new Diff($from$to);
    $formatter = new DiffFormatter();
    $output = $formatter->format($diff);
    $this->assertEquals($expected$output);
  }

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