X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fcebe%2Fmarkdown%2Ftests%2FParserTest.php;fp=vendor%2Fcebe%2Fmarkdown%2Ftests%2FParserTest.php;h=e710061e526295bdd37297feefa4e0fb99c28641;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/cebe/markdown/tests/ParserTest.php b/vendor/cebe/markdown/tests/ParserTest.php new file mode 100644 index 000000000..e710061e5 --- /dev/null +++ b/vendor/cebe/markdown/tests/ParserTest.php @@ -0,0 +1,86 @@ + + * @group default + */ +class ParserTest extends \PHPUnit_Framework_TestCase +{ + public function testMarkerOrder() + { + $parser = new TestParser(); + $parser->markers = [ + '[' => 'parseMarkerA', + '[[' => 'parseMarkerB', + ]; + + $this->assertEquals("

Result is A

\n", $parser->parse('Result is [abc]')); + $this->assertEquals("

Result is B

\n", $parser->parse('Result is [[abc]]')); + $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]')); + $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]')); + + $parser = new TestParser(); + $parser->markers = [ + '[[' => 'parseMarkerB', + '[' => 'parseMarkerA', + ]; + + $this->assertEquals("

Result is A

\n", $parser->parse('Result is [abc]')); + $this->assertEquals("

Result is B

\n", $parser->parse('Result is [[abc]]')); + $this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]')); + $this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]')); + } + + public function testMaxNestingLevel() + { + $parser = new TestParser(); + $parser->markers = [ + '[' => 'parseMarkerC', + ]; + + $parser->maximumNestingLevel = 3; + $this->assertEquals("(C-a(C-b(C-c)))", $parser->parseParagraph('[a[b[c]]]')); + $parser->maximumNestingLevel = 2; + $this->assertEquals("(C-a(C-b[c]))", $parser->parseParagraph('[a[b[c]]]')); + $parser->maximumNestingLevel = 1; + $this->assertEquals("(C-a[b[c]])", $parser->parseParagraph('[a[b[c]]]')); + } +} + +class TestParser extends Parser +{ + public $markers = []; + + protected function inlineMarkers() + { + return $this->markers; + } + + protected function parseMarkerA($text) + { + return [['text', 'A'], strrpos($text, ']') + 1]; + } + + protected function parseMarkerB($text) + { + return [['text', 'B'], strrpos($text, ']') + 1]; + } + + protected function parseMarkerC($text) + { + $terminatingMarkerPos = strrpos($text, ']'); + $inside = $this->parseInline(substr($text, 1, $terminatingMarkerPos - 1)); + return [['text', '(C-' . $this->renderAbsy($inside) . ')'], $terminatingMarkerPos + 1]; + } +}