ParserTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Diff package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Diff;
  11. use PHPUnit_Framework_TestCase;
  12. class ParserTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @var Parser
  16. */
  17. private $parser;
  18. protected function setUp()
  19. {
  20. $this->parser = new Parser;
  21. }
  22. public function testParse()
  23. {
  24. $content = file_get_contents(__DIR__ . '/fixtures/patch.txt');
  25. $diffs = $this->parser->parse($content);
  26. $this->assertCount(1, $diffs);
  27. $chunks = $diffs[0]->getChunks();
  28. $this->assertCount(1, $chunks);
  29. $this->assertEquals(20, $chunks[0]->getStart());
  30. $this->assertCount(5, $chunks[0]->getLines());
  31. }
  32. public function testParseWithMultipleChunks()
  33. {
  34. $content = file_get_contents(__DIR__ . '/fixtures/patch2.txt');
  35. $diffs = $this->parser->parse($content);
  36. $this->assertCount(1, $diffs);
  37. $chunks = $diffs[0]->getChunks();
  38. $this->assertCount(3, $chunks);
  39. $this->assertEquals(20, $chunks[0]->getStart());
  40. $this->assertEquals(320, $chunks[1]->getStart());
  41. $this->assertEquals(600, $chunks[2]->getStart());
  42. $this->assertCount(5, $chunks[0]->getLines());
  43. $this->assertCount(5, $chunks[1]->getLines());
  44. $this->assertCount(5, $chunks[2]->getLines());
  45. }
  46. }