Nav apraksta

UnifiedDiffOutputBuilderTest.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/diff.
  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\Output;
  11. use PHPUnit\Framework\TestCase;
  12. use SebastianBergmann\Diff\Differ;
  13. /**
  14. * @covers SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder
  15. *
  16. * @uses SebastianBergmann\Diff\Differ
  17. * @uses SebastianBergmann\Diff\Output\AbstractChunkOutputBuilder
  18. * @uses SebastianBergmann\Diff\TimeEfficientLongestCommonSubsequenceCalculator
  19. */
  20. final class UnifiedDiffOutputBuilderTest extends TestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param string $from
  25. * @param string $to
  26. * @param string $header
  27. *
  28. * @dataProvider headerProvider
  29. */
  30. public function testCustomHeaderCanBeUsed(string $expected, string $from, string $to, string $header): void
  31. {
  32. $differ = new Differ(new UnifiedDiffOutputBuilder($header));
  33. $this->assertSame(
  34. $expected,
  35. $differ->diff($from, $to)
  36. );
  37. }
  38. public function headerProvider(): array
  39. {
  40. return [
  41. [
  42. "CUSTOM HEADER\n@@ @@\n-a\n+b\n",
  43. 'a',
  44. 'b',
  45. 'CUSTOM HEADER',
  46. ],
  47. [
  48. "CUSTOM HEADER\n@@ @@\n-a\n+b\n",
  49. 'a',
  50. 'b',
  51. "CUSTOM HEADER\n",
  52. ],
  53. [
  54. "CUSTOM HEADER\n\n@@ @@\n-a\n+b\n",
  55. 'a',
  56. 'b',
  57. "CUSTOM HEADER\n\n",
  58. ],
  59. [
  60. "@@ @@\n-a\n+b\n",
  61. 'a',
  62. 'b',
  63. '',
  64. ],
  65. ];
  66. }
  67. /**
  68. * @param string $expected
  69. * @param string $from
  70. * @param string $to
  71. *
  72. * @dataProvider provideDiffWithLineNumbers
  73. */
  74. public function testDiffWithLineNumbers($expected, $from, $to): void
  75. {
  76. $differ = new Differ(new UnifiedDiffOutputBuilder("--- Original\n+++ New\n", true));
  77. $this->assertSame($expected, $differ->diff($from, $to));
  78. }
  79. public function provideDiffWithLineNumbers(): array
  80. {
  81. return UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers();
  82. }
  83. }