LinkParserHelperTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Util;
  12. use League\CommonMark\Parser\Cursor;
  13. use League\CommonMark\Util\LinkParserHelper;
  14. use PHPUnit\Framework\TestCase;
  15. final class LinkParserHelperTest extends TestCase
  16. {
  17. /**
  18. * @dataProvider dataProviderForTestParseLinkDestination
  19. */
  20. public function testParseLinkDestination(string $input, string $expected): void
  21. {
  22. $cursor = new Cursor($input);
  23. $this->assertSame($expected, LinkParserHelper::parseLinkDestination($cursor));
  24. }
  25. /**
  26. * @return iterable<array<string>>
  27. */
  28. public function dataProviderForTestParseLinkDestination(): iterable
  29. {
  30. yield ['www.google.com', 'www.google.com'];
  31. yield ['<www.google.com>', 'www.google.com'];
  32. yield ['<www.google.com> is great', 'www.google.com'];
  33. yield ['\\b\\', '%5Cb%5C']; // Regression test for https://github.com/thephpleague/commonmark/issues/403
  34. }
  35. /**
  36. * @dataProvider dataProviderForTestParseLinkLabel
  37. */
  38. public function testParseLinkLabel(string $input, int $expected): void
  39. {
  40. $cursor = new Cursor($input);
  41. $this->assertSame($expected, LinkParserHelper::parseLinkLabel($cursor));
  42. }
  43. /**
  44. * @return iterable<array<mixed>>
  45. */
  46. public function dataProviderForTestParseLinkLabel(): iterable
  47. {
  48. yield ['[link](http://example.com)', 6];
  49. yield ['[\\]: test', 0];
  50. }
  51. }