Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

65 lines
1.6KB

  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2014 Carsten Brandt
  4. * @license https://github.com/cebe/markdown/blob/master/LICENSE
  5. * @link https://github.com/cebe/markdown#readme
  6. */
  7. namespace cebe\markdown\tests;
  8. use cebe\markdown\Parser;
  9. /**
  10. * Test case for the parser base class.
  11. *
  12. * @author Carsten Brandt <mail@cebe.cc>
  13. * @group default
  14. */
  15. class ParserTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testMarkerOrder()
  18. {
  19. $parser = new TestParser();
  20. $parser->markers = [
  21. '[' => 'parseMarkerA',
  22. '[[' => 'parseMarkerB',
  23. ];
  24. $this->assertEquals("<p>Result is A</p>\n", $parser->parse('Result is [abc]'));
  25. $this->assertEquals("<p>Result is B</p>\n", $parser->parse('Result is [[abc]]'));
  26. $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]'));
  27. $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]'));
  28. $parser = new TestParser();
  29. $parser->markers = [
  30. '[[' => 'parseMarkerB',
  31. '[' => 'parseMarkerA',
  32. ];
  33. $this->assertEquals("<p>Result is A</p>\n", $parser->parse('Result is [abc]'));
  34. $this->assertEquals("<p>Result is B</p>\n", $parser->parse('Result is [[abc]]'));
  35. $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]'));
  36. $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]'));
  37. }
  38. }
  39. class TestParser extends Parser
  40. {
  41. public $markers = [];
  42. protected function inlineMarkers()
  43. {
  44. return $this->markers;
  45. }
  46. protected function parseMarkerA($text)
  47. {
  48. return [['text', 'A'], strrpos($text, ']') + 1];
  49. }
  50. protected function parseMarkerB($text)
  51. {
  52. return [['text', 'B'], strrpos($text, ']') + 1];
  53. }
  54. }