|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of graze/console-diff-renderer. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @license https://github.com/graze/console-diff-renderer/blob/master/LICENSE.md |
|
11
|
|
|
* @link https://github.com/graze/console-diff-renderer |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Graze\DiffRenderer\Test\Unit\Diff; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\DiffRenderer\Diff\FirstDiff; |
|
17
|
|
|
use Graze\DiffRenderer\Test\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class FirstDiffTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @dataProvider firstDifferenceData |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $left |
|
25
|
|
|
* @param string $right |
|
26
|
|
|
* @param int $pos |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testFirstDifference($left, $right, $pos) |
|
29
|
|
|
{ |
|
30
|
|
|
$diff = new FirstDiff(); |
|
31
|
|
|
$this->assertEquals($pos, $diff->firstDifference($left, $right)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function firstDifferenceData() |
|
38
|
|
|
{ |
|
39
|
|
|
return [ |
|
40
|
|
|
['abcdef', 'abcdef', -1], |
|
41
|
|
|
['abcdef', 'abcde', 5], |
|
42
|
|
|
['abcdef', 'bcdef', 0], |
|
43
|
|
|
['', 'abcdef', 0], |
|
44
|
|
|
['abcdef', '', 0], |
|
45
|
|
|
['<complex> other things </complex>', '<complex> other thingies </complex>', 21], |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @dataProvider lineDifferenceData |
|
51
|
|
|
* |
|
52
|
|
|
* @param string[] $old |
|
53
|
|
|
* @param string[] $new |
|
54
|
|
|
* @param array $expected |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testLineDifference(array $old, array $new, array $expected) |
|
57
|
|
|
{ |
|
58
|
|
|
$diff = new FirstDiff(); |
|
59
|
|
|
$this->assertEquals($expected, $diff->lines($old, $new)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function lineDifferenceData() |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
[ |
|
69
|
|
|
['first', 'second'], |
|
70
|
|
|
['first', 'second', 'third'], |
|
71
|
|
|
[ |
|
72
|
|
|
null, |
|
73
|
|
|
null, |
|
74
|
|
|
['col' => 0, 'str' => 'third'], |
|
75
|
|
|
], |
|
76
|
|
|
], |
|
77
|
|
|
[ |
|
78
|
|
|
['first', 'second'], |
|
79
|
|
|
['first'], |
|
80
|
|
|
[ |
|
81
|
|
|
null, |
|
82
|
|
|
['col' => 0, 'str' => ''], |
|
83
|
|
|
], |
|
84
|
|
|
], |
|
85
|
|
|
[ |
|
86
|
|
|
['first', 'second'], |
|
87
|
|
|
['first mod', 'secmod'], |
|
88
|
|
|
[ |
|
89
|
|
|
['col' => 5, 'str' => ' mod'], |
|
90
|
|
|
['col' => 3, 'str' => 'mod'], |
|
91
|
|
|
], |
|
92
|
|
|
], |
|
93
|
|
|
[ |
|
94
|
|
|
['first bits', 'second bits'], |
|
95
|
|
|
['first thing bits', 'second thing bits'], |
|
96
|
|
|
[ |
|
97
|
|
|
['col' => 6, 'str' => 'thing bits'], |
|
98
|
|
|
['col' => 7, 'str' => 'thing bits'], |
|
99
|
|
|
], |
|
100
|
|
|
], |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|