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
8 namespace cebe\markdown\tests;
10 use cebe\markdown\Parser;
13 * Test case for the parser base class.
15 * @author Carsten Brandt <mail@cebe.cc>
18 class ParserTest extends \PHPUnit_Framework_TestCase
20 public function testMarkerOrder()
22 $parser = new TestParser();
24 '[' => 'parseMarkerA',
25 '[[' => 'parseMarkerB',
28 $this->assertEquals("<p>Result is A</p>\n", $parser->parse('Result is [abc]'));
29 $this->assertEquals("<p>Result is B</p>\n", $parser->parse('Result is [[abc]]'));
30 $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]'));
31 $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]'));
33 $parser = new TestParser();
35 '[[' => 'parseMarkerB',
36 '[' => 'parseMarkerA',
39 $this->assertEquals("<p>Result is A</p>\n", $parser->parse('Result is [abc]'));
40 $this->assertEquals("<p>Result is B</p>\n", $parser->parse('Result is [[abc]]'));
41 $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]'));
42 $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]'));
45 public function testMaxNestingLevel()
47 $parser = new TestParser();
49 '[' => 'parseMarkerC',
52 $parser->maximumNestingLevel = 3;
53 $this->assertEquals("(C-a(C-b(C-c)))", $parser->parseParagraph('[a[b[c]]]'));
54 $parser->maximumNestingLevel = 2;
55 $this->assertEquals("(C-a(C-b[c]))", $parser->parseParagraph('[a[b[c]]]'));
56 $parser->maximumNestingLevel = 1;
57 $this->assertEquals("(C-a[b[c]])", $parser->parseParagraph('[a[b[c]]]'));
61 class TestParser extends Parser
65 protected function inlineMarkers()
67 return $this->markers;
70 protected function parseMarkerA($text)
72 return [['text', 'A'], strrpos($text, ']') + 1];
75 protected function parseMarkerB($text)
77 return [['text', 'B'], strrpos($text, ']') + 1];
80 protected function parseMarkerC($text)
82 $terminatingMarkerPos = strrpos($text, ']');
83 $inside = $this->parseInline(substr($text, 1, $terminatingMarkerPos - 1));
84 return [['text', '(C-' . $this->renderAbsy($inside) . ')'], $terminatingMarkerPos + 1];