3 namespace Drupal\Tests\Component\Diff;
5 use Drupal\Component\Diff\Diff;
6 use Drupal\Component\Diff\DiffFormatter;
7 use PHPUnit\Framework\TestCase;
10 * Test DiffFormatter classes.
12 * @coversDefaultClass \Drupal\Component\Diff\DiffFormatter
16 class DiffFormatterTest extends TestCase {
20 * - Expected formatted diff output.
21 * - First array of text to diff.
22 * - Second array of text to diff.
24 public function provideTestDiff() {
26 'empty' => ['', [], []],
29 ['line1', 'line2', 'line3'],
30 ['line1', 'line2', 'line2a', 'line3'],
34 ['line1', 'line2', 'line2a', 'line3'],
35 ['line1', 'line2', 'line3'],
38 "3c3\n< line2a\n---\n> line2b\n",
39 ['line1', 'line2', 'line2a', 'line3'],
40 ['line1', 'line2', 'line2b', 'line3'],
46 * Tests whether op classes returned by DiffEngine::diff() match expectations.
49 * @dataProvider provideTestDiff
51 public function testDiff($expected, $from, $to) {
52 $diff = new Diff($from, $to);
53 $formatter = new DiffFormatter();
54 $output = $formatter->format($diff);
55 $this->assertEquals($expected, $output);