Passed
Push — master ( 1863b6...b24285 )
by Steve
32s
created

RangeDifferencerTest::testFindDifferences_2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace SN\RangeDifferencer;
12
13
use PHPUnit\Framework\TestCase;
14
use SN\RangeDifferencer\Tag\TagComparator;
15
16
/**
17
 * RangeDifferencer Tests
18
 */
19
class RangeDifferencerTest extends TestCase
20
{
21
    public function testFindDifferences_1(): void
22
    {
23
        $oldText = '<p> This is a green book about food</p>';
24
        $newText = '<p> This is a <b>big</b> blue book</p>';
25
        $left = new TagComparator($oldText);
26
        $right = new TagComparator($newText);
27
28
        $diffs = RangeDifferencer::findDifferences($left, $right);
29
30
        $this->assertSame(2, \count($diffs));
31
        $this->assertSame('RangeDifference {CHANGE/RIGHT, Left: (8, 1) Right: (8, 5)}', $diffs[0]->__toString());
32
        $this->assertSame('RangeDifference {CHANGE/RIGHT, Left: (11, 4) Right: (15, 0)}', $diffs[1]->__toString());
33
    }
34
35
    public function testFindDifferences_2(): void
36
    {
37
        $oldText = '<p> This is a <b>big</b> blue book</p>';
38
        $newText = '<p> This is a <b>big</b> blue book</p>';
39
        $left = new TagComparator($oldText);
40
        $right = new TagComparator($newText);
41
42
        $diffs = RangeDifferencer::findDifferences($left, $right);
43
44
        $this->assertSame(0, \count($diffs));
45
    }
46
47
    public function testFindRanges_1(): void
48
    {
49
        $oldText = '<p> This is a green book about food</p>';
50
        $newText = '<p> This is a <b>big</b> blue book</p>';
51
        $left = new TagComparator($oldText);
52
        $right = new TagComparator($newText);
53
54
        $diffs = RangeDifferencer::findRanges($left, $right);
55
56
        $this->assertSame(5, \count($diffs));
57
        $this->assertSame('RangeDifference {NOCHANGE, Left: (0, 8) Right: (0, 8)}', $diffs[0]->__toString());
58
        $this->assertSame('RangeDifference {CHANGE/RIGHT, Left: (8, 1) Right: (8, 5)}', $diffs[1]->__toString());
59
        $this->assertSame('RangeDifference {NOCHANGE, Left: (9, 2) Right: (13, 2)}', $diffs[2]->__toString());
60
        $this->assertSame('RangeDifference {CHANGE/RIGHT, Left: (11, 4) Right: (15, 0)}', $diffs[3]->__toString());
61
        $this->assertSame('RangeDifference {NOCHANGE, Left: (15, 1) Right: (15, 1)}', $diffs[4]->__toString());
62
    }
63
64
    public function testFindRanges3(): void
65
    {
66
        $ancestorText = '<p> This is a book </p>';
67
        $oldText = '<p> This is a green book about food</p>';
68
        $newText = '<p> This is a <b>big</b> blue book</p>';
69
        $ancestor = new TagComparator($ancestorText);
70
        $left = new TagComparator($oldText);
71
        $right = new TagComparator($newText);
72
73
        $diffs = RangeDifferencer::findDifferences3($ancestor, $left, $right);
74
75
        $this->assertSame(3, \count($diffs));
76
        $this->assertSame('RangeDifference {CONFLICT, Left: (8, 2) Right: (8, 6) Ancestor: (8, 0)}', $diffs[0]->__toString());
77
        $this->assertSame('RangeDifference {CHANGE/RIGHT, Left: (11, 1) Right: (15, 0) Ancestor: (9, 1)}', $diffs[1]->__toString());
78
        $this->assertSame('RangeDifference {LEFT, Left: (12, 3) Right: (15, 0) Ancestor: (10, 0)}', $diffs[2]->__toString());
79
    }
80
}
81