MarkdownInputTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace League\CommonMark\Tests\Unit\Input;
  12. use League\CommonMark\Exception\UnexpectedEncodingException;
  13. use League\CommonMark\Input\MarkdownInput;
  14. use PHPUnit\Framework\TestCase;
  15. final class MarkdownInputTest extends TestCase
  16. {
  17. public function testConstructorAndGetter(): void
  18. {
  19. $markdown = new MarkdownInput('# Hello World!');
  20. $this->assertSame('# Hello World!', $markdown->getContent());
  21. }
  22. public function testInvalidContent(): void
  23. {
  24. $this->expectException(UnexpectedEncodingException::class);
  25. $markdown = new MarkdownInput(\chr(250));
  26. }
  27. public function testGetLines(): void
  28. {
  29. $markdown = new MarkdownInput("# Hello World!\n\nThis is just a test.\n");
  30. $lines = $markdown->getLines();
  31. $this->assertSame(\iterator_to_array($lines), [
  32. 1 => '# Hello World!',
  33. 2 => '',
  34. 3 => 'This is just a test.',
  35. ]);
  36. }
  37. public function testLineOffset(): void
  38. {
  39. $markdown = new MarkdownInput("# Hello World!\n\nThis is just a test.\n", 3);
  40. $lines = $markdown->getLines();
  41. $this->assertSame(\iterator_to_array($lines), [
  42. 4 => '# Hello World!',
  43. 5 => '',
  44. 6 => 'This is just a test.',
  45. ]);
  46. }
  47. public function testGetLineCount(): void
  48. {
  49. $markdown = new MarkdownInput("# Hello World!\n\nThis is just a test.\n");
  50. $this->assertSame(3, $markdown->getLineCount());
  51. }
  52. }