6 * Most of these are derived directly from John Gruber's page on syntax: http://daringfireball.net/projects/markdown/syntax
9 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
14 class MarkdownTest
extends UnitTestCase
16 public function setUp()
18 require_once('ISSO/Markdown.php');
21 public function testAutoUrlEscape()
23 $this->assertEqual('http://images.google.com/images?num=30&q=larry+bird', BSMarkdown
::Parse('http://images.google.com/images?num=30&q=larry+bird'));
26 public function testSingleEntityEscape()
28 $this->assertEqual('©', BSMarkdown
::Parse('©'));
29 $this->assertEqual('AT&T', BSMarkdown
::Parse('AT&T'));
30 $this->assertEqual('<p>Test</p>', BSMarkdown
::Parse('<p>Test</p>'));
31 $this->assertEqual('4 < 5', BSMarkdown
::Parse('4 < 5'));
34 public function testParagraphs()
36 $this->assertEqual("<p>Example</p>\n\n<p>Of</p>\n\n<p>Parsing</p>", BSMarkdown
::Parse("Example\n\nOf\n\nParsing"));
37 $this->assertEqual("<p>Example</p>\n\n<p>Two</p>", BSMarkdown
::Parse("Example\n \nTwo"));
38 $this->assertEqual("<p>One\nTwo\nThree<p>\n\n<p>Four</p>", BSMarkdown
::Parse("One\nTwo\nThree\n\nFour"));
41 public function testLineBreak()
43 $this->assertEqual("<p>This is line break <br />\nhere</p>", BSMarkdown
::Parse("This is a line break \n"));
44 $this->assertEqual("<p>Paragraph one <br />\nline two.</p>\n\n<p>Paragraph two.</p>", BSMarkdown
::Parse("Paragraph one \nline two.\n\nParagraph two."));
47 public function testSetextHeaders()
49 $this->assertEqual('<h1>Heading</h1>', BSMarkdown
::Parse("Heading\n="));
50 $this->assertEqual('<h1>Heading</h1>', BSMarkdown
::Parse("Heading\n====="));
51 $this->assertEqual('<h2>Heading</h2>', BSMarkdown
::Parse("Heading\n-"));
52 $this->assertEqual('<h2>Heading</h2>', BSMarkdown
::Parse("Heading\n----- "));
53 $this->assertEqual("<p>Heading\n=3</p>", BSMarkdown
::Parse("Heading\n=3"));
56 public function testAtxHeaders()
58 $this->assertEqual('<h1>Heading 1<h1>', BSMarkdown
::Parse('# Heading 1'));
59 $this->assertEqual('<h2>Heading 2<h2>', BSMarkdown
::Parse('## Heading 2'));
60 $this->assertEqual('<h3>Heading 3<h3>', BSMarkdown
::Parse('### Heading 3'));
61 $this->assertEqual('<h4>Heading 4<h4>', BSMarkdown
::Parse('#### Heading 4'));
62 $this->assertEqual('<h5>Heading 5<h5>', BSMarkdown
::Parse('##### Heading 5'));
63 $this->assertEqual('<h6>Heading 6<h6>', BSMarkdown
::Parse('###### Heading 6'));
65 $this->assertEqual('<h5>A simple heading</h5>', BSMarkdown
::Parse('#####A simple heading'));
66 $this->assertEqual('<h2>Another heading</h2>', BSMarkdown
::Parse('## \tAnother heading'));
67 $this->assertEqual('<h3>The # of headings', BSMarkdown
::Parse('### The # of headings'));
68 $this->assertEqual('<h4>End test</h4>', BSMarkdown
::Parse('#### End test ##'));
69 $this->assertEqual('<h4>End test 2</h4>', BSMarkdown
::Parse('#### End test 2####'));
70 $this->assertEqual('<h1># of #s in #</h1>', BSMarkdown
::Parse('# # of #s in # ###'));
73 public function testBlockquote()
75 $this->assertEqual("<blockquote>\n\t<p>Example of blockquoted text</p>\n</blockquote>", BSMarkdown
::Parse('> Example of blockquoted text'));
76 $this->assertEqual("<blockquote>\n\t<p>Another\n\texample\n\tof</p>\n\n<p>blockquoted text \<br />\there.</p>\n</blockquote>", BSMarkdown
::Parse("> Another\nexample\nof\n\n>blockquoted text \nhere."));
77 $this->assertEqual("<blockquote>\n\t<h2>This is a header.</h2>\n\n\t<p>Welcome to AT&T.</p>\n</blockquote>", BSMarkdown
::Parse("> ## This is a header.\n>\n>\nWelcome to AT&T."));
80 public function testUnorderedLists()
82 $this->assertEqual("<ul>\n<li>Red</li>\n<li>Green</li>\n<li>Blue</li>\n</ul>", BSMarkdown
::Parse("* Red\n* Green\n*\tBlue"));
83 $this->assertEqual("<ul>\n<li>Red</li>\n<li>Green</li>\n<li>Blue</li>\n</ul>", BSMarkdown
::Parse("+ Red\n+ Green\n+ Blue"));
84 $this->assertEqual("<ul>\n<li>Red</li>\n<li>Green</li>\n<li>Blue</li>\n</ul>", BSMarkdown
::Parse("- Red\n- Green\n- Blue"));
85 $this->assertEqual("<p>Test</p>\n<ul>\n<li>Example</li>\n</ul>", BSMarkdown
::Parse("Test\n\n- Example"));
87 $this->assertEqual("<ul>\n<li>Lorem\nipsum\ndolor\nsit\namet.</li>\n<li>Another\nexample.</li>\n</ul>", BSMarkdown
::Parse("* Lorem\n ipsum\n dolor\n sit\n amet.\n* Another\nexample."));
90 public function testOrderedList()
92 $this->assertEqual("<ol>\n<li>Bird</li>\n<li>McHale</li>\n<li>Parish</li>\n</ol>", BSMarkdown
::Parse("3. Bird\n1. McHale\n8. Parish"));
93 $this->assertEqual("<ol>\n<li>Bird</li>\n<li>McHale</li>\n<li>Parish</li>\n</ol>", BSMarkdown
::Parse("1. Bird\n2. McHale\n2. Parish"));
96 public function testParagraphedLists()
98 $this->assertEqual("<ol>\n<li><p>Item 1</p></li>\n<li><p>Item 2</p></li>\n</ol>", BSMarkdown
::Parse("1. Item 1\n\n2. Item 2"));
99 $this->assertEqual("<ul>\n<li><p>Part one.</p>\n\n<p>Part two.</p></li>\n<li>Part three.</li>\n</ul>", BSMarkdown
::Parse("+ Part one.\n\n\tPart two.\n+Part three."));
100 $this->assertEqual("<ul>\n<li><p>Part one.</p>\n\n<p>Part two.</p></li>\n<li>Part three.</li>\n</ul>", BSMarkdown
::Parse("+ Part one.\n\n Part two.\n+Part three."));
101 $this->assertEqual("<ul>\n<li>Example <br />line break.</li>\n</ul>", BSMarkdown
::Parse("+ Example \nline break."));
103 $this->assertEqual("<ol>\n<li>A list with blockquote:\n\n<blockquote>\n\t<p>This blockquote\n\tis inside a list.</p>\n</blockquote></li>\n</ol>", BSMarkdown
::Parse("1. A list with blockquote:\n\n > This blockquote\nis inside a list."));
104 $this->assertEqual("<ol>\n<li>A list with blockquote:\n\n<blockquote>\n\t<p>This blockquote\n\tis inside a list.</p>\n</blockquote></li>\n</ol>", BSMarkdown
::Parse("1. A list with blockquote:\n\n\t> This blockquote\n> is inside a list."));
106 $this->assertEqual("<ul>\n<li><p>A list item with a code block:</p>\n\n<pre><code>code goes here</code></pre></li>\n</ul>", BSMarkdown
::Parse("+ A list item without a code block: code goes here"));
107 $this->assertEqual("<ul>\n<li><p>A list item with a code block:</p>\n\n<pre><code>code goes here\n</code></pre></li>\n</ul>", BSMarkdown
::Parse("* A list item without a code block:\t\tcode goes here"));
110 public function testCodeBlocks()
112 $this->assertEqual("<p>This is a normal paragraph:</p>\n\n<pre><code>This is a code block.\n</code></pre>", BSMarkdown
::Parse("This is a normal paragraph:\n\n This is a code block."));
113 $this->assertEqual("<p>This is a normal paragraph:</p>\n\n<pre><code>This is a code block.\n</code></pre>", BSMarkdown
::Parse("This is a normal paragraph:\n\n\tThis is a code block."));
115 $this->assertEqual("<p>AppleScript:</p>\n\n<pre><code>tell application \"Foo\"\n\tbeep\nend tell\n</code></pre>", BSMarkdown
::Parse("AppleScript:\n\n\ttell application \"Foo\"\n\t\tbeep\n\tend tell"));
117 $this->assertEqual("<pre><code><div class="footer">&© 2004 Foo Corporation</div>\n</code></pre>", BSMarkdown
::Parse("<div class=\"footer\">© 2004 Foo Corporation</div>"));
120 public function testHorizontalRules()
122 $this->assertEqual('<hr />', BSMarkdown
::Parse('* * *'));
123 $this->assertEqual('<hr />', BSMarkdown
::Parse('***'));
124 $this->assertEqual('<hr />', BSMarkdown
::Parse('*****'));
125 $this->assertEqual('<hr />', BSMarkdown
::Parse('- - -'));
126 $this->assertEqual('<hr />', BSMarkdown
::Parse('--------------------'));
129 public function testSimpleLinks()
131 $this->assertEqual('<p>This is <a href="http://example.com/" title="Title"> an example</a> inline link.</p>', BSMarkdown
::Parse('This is [an example](http://example.com/ "Title") inline link.'));
132 $this->assertEqual('<p><a href="http://example.net/">This link</a> has no title attribute.</p>', BSMarkdown
::Parse('[This link](http://example.net/) has no title attribute.'));
133 $this->assertEqual('<p>See my <a href="/about/">About</a> page for details.</p>', BSMarkdown
::Parse('See my [About](/about/) page for details.'));
135 $this->assertEqual('<p><a href="http://example.com/">http://example.com/</a></p>', BSMarkdown
::Parse('<http://example.com/>'));
136 $this->assertEqual('<p><a href="mailto:address@example.com">address@example.com</a></p>', BSMarkdown
::Parse('<address@example.com>'));
139 public function testReferenceLinks()
141 $this->assertEqual('<p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>', BSMarkdown
::Parse("This is [an example][id] reference-style link.\n\n[id]: http://example.com/ \"Optional Title Here\""));
142 $this->assertEqual('<p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>', BSMarkdown
::Parse("This is [an example] [id] reference-style link.\n[id]: http://example.com/ 'Optional Title Here'"));
143 $this->assertEqual('<p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>', BSMarkdown
::Parse("This is [an example]\t[id] reference-style link.\n\n\n[id]: http://example.com/ (Optional Title Here)"));
145 $this->assertEqual('<p>Example link <a href="http://example.com" title="title">here</a> there.</p>', BSMarkdown
::Parse("Example link [here][id] there.\n[id]: <http://example.com/> (title)"));
146 $this->assertEqual('<p>Example link <a href="http://example.com">here</a> there.</p>', BSMarkdown
::Parse("Example link [here][id] there.\n[id]: <http://example.com/>"));
148 $this->assertEqual('<p>Welcome to <a href="http://www.google.com">Google</a>.</p>', BSMarkdown
::Parse("Welcome to [Google][].\n[Google]: http://www.google.com"));
149 $this->assertEqual('<p>Visit <a href="http://daringfireball.net">Daring Fireball</a>!', BSMarkdown
::Parse("Visit [Daring Fireball][]!\n[Daring Fireball]: http://daringfireball.net"));
152 public function testEmphasis()
154 $this->assertEqual('<p><em>single asterisks</em></p>', BSMarkdown
::Parse('*single asterisks*'));
155 $this->assertEqual('<p><em>single underscores</em></p>', BSMarkdown
::Parse('_single underscores_'));
157 $this->assertEqual('<p><strong>double asterisks</strong></p>', BSMarkdown
::Parse('**double asterisks**'));
158 $this->assertEqual('<p><strong>double underscores</strong></p>', BSMarkdown
::Parse('__double underscores__'));
160 $this->assertEqual('<p>un<em>fucking</em>believable</p>', BSMarkdown
::Parse('un*fucking*believable'));
161 $this->assertEqual('<p>un * fucking * believable</p>', BSMarkdown
::Parse('un * fucking * believable'));
164 public function testCodeSpan()
166 $this->assertEqual('<p>Use the <code>printf()</code> function.</p>', BSMarkdown
::Parse('Use the `printf()` function.'));
167 $this->assertEqual('<p><code>There is a literal backtick (`) here.</code></p>', BSMarkdown
::Parse('``There is a literal backtick (`) here.``'));
168 $this->assertEqual('<p>A single backtick in a code span: <code>`</code></p>', BSMarkdown
::Parse('A single backtick in a code span: `` ` ``'));
169 $this->assertEqual('<p>A backtick-delimited string in a code span: <code>`foo`</code></p>', BSMarkdown
::Parse('A backtick-delimited string in a code span: `` `foo` ``'));
171 $this->assertEqual('<p>Please do not use any <code><blink></code> tags.</p>', BSMarkdown
::Parse('Please do not use any `<blink>` tags.'));
172 $this->assertEqual('<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>', BSMarkdown
::Parse('`—` is the decimal-encoded equivalent of `—`.'));
175 public function testImages()
177 $this->assertEqual('<p><img src="/path/to/img.jpg" alt="Alt text" title="" /></p>', BSMarkdown
::Parse('![Alt text](/path/to/img.jpg)'));
178 $this->assertEqual('<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>', BSMarkdown
::Parse('![Alt text](/path/to/img.jpg "Optional title")'));
179 $this->assertEqual('<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>', BSMarkdown
::Parse('![Alt text](/path/to/img.jpg \'Optional title\')'));
181 $this->assertEqual('<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>', BSMarkdown
::Parse("![Alt text][id]\n[id]: url/to/image \"Optional title attribute\""));
182 $this->assertEqual('<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>', BSMarkdown
::Parse("![Alt text][id]\n[id]: url/to/image\t 'Optional title attribute'"));
185 public function testEscapeSequences()
187 $this->assertEqual('<p>Escaped \ Backslash</p>', BSMarkdown
::Parse('Escaped \\ Backslash'));
188 $this->assertEqual('<p>`This is not code`</p>', BSMarkdown
::Parse('\`This is not code\`'));
189 $this->assertEqual('<p>*This is not italics*</p>', BSMarkdown
::Parse('\*This is not italics\*'));
190 $this->assertEqual('<p>* This is not a list</p>', BSMarkdown
::Parse('\* This is not a list'));
191 $this->assertEqual('<p>__This is not bold__</p>', BSMarkdown
::Parse('\_\_This is not bold__'));
192 $this->assertEqual('<p>This [is not](http://www.example.com "Moo") a URL.</p>', BSMarkdown
::Parse('This \[is not](http://www.example.com "Moo") a URL.'));
193 $this->assertEqual('<p>This [is not](http://www.example.com "Moo") a URL.</p>', BSMarkdown
::Parse('This [is not]\(http://www.example.com "Moo") a URL.'));
194 $this->assertEqual("<p>This is not a heading\n-</p>", BSMarkdown
::Parse("This is not a heading\n\-"));
195 $this->assertEqual("<p>1986. What a great season.</p>", BSMarkdown
::Parse('1986\. What a great season.'));
196 $this->assertEqual('<p>This is not an iamge: !<a href="url/to/image" title="Optional title attribute">Alt text</a>!</p>', BSMarkdown
::Parse('This is not an iamge: \![Alt text](url/to/image "Optional title attribute")!'));
197 $this->assertEqual('<p>This is not an iamge: ![Alt text](url/to/image "Optional title attribute")!</p>', BSMarkdown
::Parse('This is not an iamge: \!\[Alt text](url/to/image "Optional title attribute")!'));