comparison vendor/nikic/php-parser/test/PhpParser/Internal/DifferTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\Internal;
4
5 use PHPUnit\Framework\TestCase;
6
7 class DifferTest extends TestCase
8 {
9 private function formatDiffString(array $diff) {
10 $diffStr = '';
11 foreach ($diff as $diffElem) {
12 switch ($diffElem->type) {
13 case DiffElem::TYPE_KEEP:
14 $diffStr .= $diffElem->old;
15 break;
16 case DiffElem::TYPE_REMOVE:
17 $diffStr .= '-' . $diffElem->old;
18 break;
19 case DiffElem::TYPE_ADD:
20 $diffStr .= '+' . $diffElem->new;
21 break;
22 case DiffElem::TYPE_REPLACE:
23 $diffStr .= '/' . $diffElem->old . $diffElem->new;
24 break;
25 default:
26 assert(false);
27 break;
28 }
29 }
30 return $diffStr;
31 }
32
33 /** @dataProvider provideTestDiff */
34 public function testDiff($oldStr, $newStr, $expectedDiffStr) {
35 $differ = new Differ(function($a, $b) { return $a === $b; });
36 $diff = $differ->diff(str_split($oldStr), str_split($newStr));
37 $this->assertSame($expectedDiffStr, $this->formatDiffString($diff));
38 }
39
40 public function provideTestDiff() {
41 return [
42 ['abc', 'abc', 'abc'],
43 ['abc', 'abcdef', 'abc+d+e+f'],
44 ['abcdef', 'abc', 'abc-d-e-f'],
45 ['abcdef', 'abcxyzdef', 'abc+x+y+zdef'],
46 ['axyzb', 'ab', 'a-x-y-zb'],
47 ['abcdef', 'abxyef', 'ab-c-d+x+yef'],
48 ['abcdef', 'cdefab', '-a-bcdef+a+b'],
49 ];
50 }
51
52 /** @dataProvider provideTestDiffWithReplacements */
53 public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr) {
54 $differ = new Differ(function($a, $b) { return $a === $b; });
55 $diff = $differ->diffWithReplacements(str_split($oldStr), str_split($newStr));
56 $this->assertSame($expectedDiffStr, $this->formatDiffString($diff));
57 }
58
59 public function provideTestDiffWithReplacements() {
60 return [
61 ['abcde', 'axyze', 'a/bx/cy/dze'],
62 ['abcde', 'xbcdy', '/axbcd/ey'],
63 ['abcde', 'axye', 'a-b-c-d+x+ye'],
64 ['abcde', 'axyzue', 'a-b-c-d+x+y+z+ue'],
65 ];
66 }
67 }