Skip to content

Commit 7945a1b

Browse files
author
Rob Caiger
committed
Added unit tests to test multiple chunks when parsing.
1 parent 2802d8f commit 7945a1b

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

tests/ParserTest.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Diff
4+
*
5+
* Copyright (c) 2001-2014, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @package Diff
38+
* @author Rob Caiger <[email protected]>
39+
* @copyright 2001-2014 Sebastian Bergmann <[email protected]>
40+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
41+
* @link http://www.github.com/sebastianbergmann/diff
42+
*/
43+
44+
namespace SebastianBergmann\Diff;
45+
46+
use PHPUnit_Framework_TestCase;
47+
48+
class ParserTest extends PHPUnit_Framework_TestCase
49+
{
50+
/**
51+
* @var Parser
52+
*/
53+
private $parser;
54+
55+
protected function setUp()
56+
{
57+
$this->parser = new Parser;
58+
}
59+
60+
public function testParse()
61+
{
62+
$content = file_get_contents(__DIR__ . '/fixtures/patch.txt');
63+
64+
$diffs = $this->parser->parse($content);
65+
66+
$this->assertCount(1, $diffs);
67+
68+
$chunks = $diffs[0]->getChunks();
69+
$this->assertCount(1, $chunks);
70+
71+
$this->assertEquals(20, $chunks[0]->getStart());
72+
73+
$this->assertCount(5, $chunks[0]->getLines());
74+
}
75+
76+
public function testParseWithMultipleChunks()
77+
{
78+
$content = file_get_contents(__DIR__ . '/fixtures/patch2.txt');
79+
80+
$diffs = $this->parser->parse($content);
81+
82+
$this->assertCount(1, $diffs);
83+
84+
$chunks = $diffs[0]->getChunks();
85+
$this->assertCount(3, $chunks);
86+
87+
$this->assertEquals(20, $chunks[0]->getStart());
88+
$this->assertEquals(320, $chunks[1]->getStart());
89+
$this->assertEquals(600, $chunks[2]->getStart());
90+
91+
$this->assertCount(5, $chunks[0]->getLines());
92+
$this->assertCount(5, $chunks[1]->getLines());
93+
$this->assertCount(5, $chunks[2]->getLines());
94+
}
95+
}

tests/fixtures/patch.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/Foo.php b/Foo.php
2+
index abcdefg..abcdefh 100644
3+
--- a/Foo.php
4+
+++ b/Foo.php
5+
@@ -20,4 +20,5 @@ class Foo
6+
const ONE = 1;
7+
const TWO = 2;
8+
+ const THREE = 3;
9+
const FOUR = 4;

tests/fixtures/patch2.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/Foo.php b/Foo.php
2+
index abcdefg..abcdefh 100644
3+
--- a/Foo.php
4+
+++ b/Foo.php
5+
@@ -20,4 +20,5 @@ class Foo
6+
const ONE = 1;
7+
const TWO = 2;
8+
+ const THREE = 3;
9+
const FOUR = 4;
10+
11+
@@ -320,4 +320,5 @@ class Foo
12+
const A = 'A';
13+
const B = 'B';
14+
+ const C = 'C';
15+
const D = 'D';
16+
17+
@@ -600,4 +600,5 @@ class Foo
18+
public function doSomething() {
19+
20+
+ return 'foo';
21+
}

0 commit comments

Comments
 (0)