1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either htmlress or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Markdown tests from DaringFireball
17 # See <https://daringfireball.net/projects/markdown/>.
18 module test_markdown_daring
is test
22 class TestMarkdownDaring
23 super TestMarkdownHtml
26 fun test_daring_encoding
is test
do
28 AT&T has an ampersand in their name.
30 AT&T is another way to write it.
38 Here's a [link][1] with an ampersand in the URL.
40 Here's a link with an ampersand in the link text: [AT&T][2].
42 Here's an inline [link](/script?foo=1&bar=2).
44 Here's an inline [link](</script?foo=1&bar=2>).
47 [1]: http://example.com/?foo=1&bar=2
48 [2]: http://att.com/ "AT&T"
52 <p>AT&T has an ampersand in their name.</p>
53 <p>AT&T is another way to write it.</p>
54 <p>This & that.</p>
57 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
58 <p>Here's a link with an ampersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
59 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
60 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
62 assert md_to_html
(md
) == html
65 fun test_daring_autolinks
is test
do
67 Link: <http://example.com/>.
69 With an ampersand: <http://example.com/?foo=1&bar=2>
72 * <http://example.com/>
75 > Blockquoted: <http://example.com/>
77 Auto-links should not occur here: `<http://example.com/>`
79 or here: <http://example.com/>
83 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
84 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
87 <li><a href="http://example.com/">http://example.com/</a></li>
91 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
93 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
94 <pre><code>or here: <http://example.com/>
97 assert md_to_html
(md
) == html
100 fun test_daring_escape
is test
do
102 These should all get escaped:
137 These should not, because they occur within a code block:
171 Nor should these, which occur in code spans:
205 These should get escaped, even though they're matching pairs for
206 other Markdown constructs:
214 This is a code span with a literal backslash-backtick sequence: `` \` ``
216 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
218 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
221 <p>These should all get escaped:</p>
225 <p>Underscore: \_</p>
226 <p>Left brace: \{</p>
227 <p>Right brace: \}</p>
228 <p>Left bracket: \[</p>
229 <p>Right bracket: \]</p>
230 <p>Left paren: \(</p>
231 <p>Right paren: \)</p>
232 <p>Greater-than: ></p>
238 <p>These should not, because they occur within a code block:</p>
239 <pre><code>Backslash: \\
271 <p>Nor should these, which occur in code spans:</p>
272 <p>Backslash: <code>\\</code></p>
273 <p>Backtick: <code>\`</code></p>
274 <p>Asterisk: <code>\*</code></p>
275 <p>Underscore: <code>\_</code></p>
276 <p>Left brace: <code>\{</code></p>
277 <p>Right brace: <code>\}</code></p>
278 <p>Left bracket: <code>\[</code></p>
279 <p>Right bracket: <code>\]</code></p>
280 <p>Left paren: <code>\(</code></p>
281 <p>Right paren: <code>\)</code></p>
282 <p>Greater-than: <code>\></code></p>
283 <p>Hash: <code>\#</code></p>
284 <p>Period: <code>\.</code></p>
285 <p>Bang: <code>\!</code></p>
286 <p>Plus: <code>\+</code></p>
287 <p>Minus: <code>\-</code></p>
288 <p>These should get escaped, even though they're matching pairs for
289 other Markdown constructs:</p>
293 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
294 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
295 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
298 assert md_to_html
(md
) == html
301 fun test_daring_blockquotes
is test
do
319 <pre><code>sub status {
320 print "working";
324 <pre><code>sub status {
325 return "working";
330 assert md_to_html
(md
) == html
333 fun test_daring_code_blocks
is test
do
335 code block on the first line
339 code block indented by spaces
343 the lines in this block
344 all contain trailing spaces
348 code block on the last line
352 <pre><code>code block on the first line
355 <pre><code>code block indented by spaces
358 <pre><code>the lines in this block
359 all contain trailing spaces
362 <pre><code>code block on the last line
365 assert md_to_html
(md
) == html
368 fun test_daring_rules
is test
do
480 assert md_to_html
(md
) == html
483 fun test_daring_code_spans
is test
do
485 `<test a="` content of attribute `">`
487 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
489 Here's how you put `` `backticks` `` in a code span.
493 <p><code><test a="</code> content of attribute <code>"></code></p>
494 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
495 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
497 assert md_to_html
(md
) == html
500 fun test_daring_images
is test
do
502 ![Alt text](/path/to/img.jpg)
504 ![Alt text](/path/to/img.jpg "Optional title")
506 Inline within a paragraph: [alt text](/url/).
508 ![alt text](/url/ "title preceded by two spaces")
510 ![alt text](/url/ "title has spaces afterward" )
514 ![alt text](</url/> "with a title").
518 ![this is a stupid URL](http://example.com/(parens).jpg)
527 [bar]: /url/ "Title here"
531 <p><img src="/path/to/img.jpg" alt="Alt text" /></p>
532 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
533 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
534 <p><img src="/url/" alt="alt text" title="title preceded by two spaces" /></p>
535 <p><img src="/url/" alt="alt text" title="title has spaces afterward" /></p>
536 <p><img src="/url/" alt="alt text" /></p>
537 <p><img src="/url/" alt="alt text" title="with a title" />.</p>
538 <p><img src="" alt="Empty" /></p>
539 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL" /></p>
540 <p><img src="/url/" alt="alt text" /></p>
541 <p><img src="/url/" alt="alt text" title="Title here" /></p>
543 assert md_to_html
(md
) == html
546 fun test_daring_links1
is test
do
550 [URL and title](/url/ "title").
552 [URL and title](/url/ "title preceded by two spaces").
554 [URL and title](/url/ "title preceded by a tab").
556 [URL and title](/url/ "title has spaces afterward" ).
558 [URL wrapped in angle brackets](</url/>).
560 [URL w/ angle brackets + title](</url/> "Here's the title").
564 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
566 (With outer parens and [parens in url](/foo(bar)))
569 [With parens in the URL](/foo(bar) "and a title")
571 (With outer parens and [parens in url](/foo(bar) "and a title"))
575 <p>Just a <a href="/url/">URL</a>.</p>
576 <p><a href="/url/" title="title">URL and title</a>.</p>
577 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
578 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
579 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
580 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
581 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
582 <p><a href="">Empty</a>.</p>
583 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
584 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
585 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
586 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
588 assert md_to_html
(md
) == html
591 fun test_daring_links2
is test
do
602 With [embedded [brackets]][b].
611 Indented [four][] times.
626 [this][this] should work
628 So should [this][this].
642 [Something in brackets like [this][] should work]
646 In this case, [this](/somethingelse/) points to something else.
648 Backslashing should suppress \\\[this] and [this\\\].
655 Here's one where the [link
656 breaks] across lines.
658 Here's another where the [link
659 breaks] across lines, but with a line-ending space.
666 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
667 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
668 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
669 <p>With <a href="/url/">embedded [brackets]</a>.</p>
670 <p>Indented <a href="/url">once</a>.</p>
671 <p>Indented <a href="/url">twice</a>.</p>
672 <p>Indented <a href="/url">thrice</a>.</p>
673 <pre><code>Indented [four][] times.
675 <pre><code>[four]: /url
678 <p><a href="foo">this</a> should work</p>
679 <p>So should <a href="foo">this</a>.</p>
680 <p>And <a href="foo">this</a>.</p>
681 <p>And <a href="foo">this</a>.</p>
682 <p>And <a href="foo">this</a>.</p>
683 <p>But not [that][].</p>
686 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
687 <p>[Same with <a href="foo">this</a>.]</p>
688 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
689 <p>Backslashing should suppress [this] and [this].</p>
691 <p>Here's one where the <a href="/url/">link
692 breaks</a> across lines.</p>
693 <p>Here's another where the <a href="/url/">link
694 breaks</a> across lines, but with a line-ending space.</p>
696 assert md_to_html
(md
) == html
699 fun test_daring_links3
is test
do
701 This is the [simple case].
703 [simple case]: /simple
711 break] with a line-ending space.
716 [this][that] and the [other]
724 <p>This is the <a href="/simple">simple case</a>.</p>
725 <p>This one has a <a href="/foo">line
727 <p>This one has a <a href="/foo">line
728 break</a> with a line-ending space.</p>
729 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
731 assert md_to_html
(md
) == html
734 fun test_daring_nested
is test
do
752 assert md_to_html
(md
) == html
755 fun test_daring_tidyness
is test
do
757 > A list within a blockquote:
766 <p>A list within a blockquote:</p>
774 assert md_to_html
(md
) == html
777 fun test_daring_list
is test
do
867 Item 2. graf two. The quick brown fox jumped over the lazy dog's
891 Same thing but with paragraphs:
905 <p>Asterisks tight:</p>
911 <p>Asterisks loose:</p>
943 <p>Minuses tight:</p>
949 <p>Minuses loose:</p>
974 <p>Loose using tabs:</p>
986 <p>and using spaces:</p>
998 <p>Multiple paragraphs:</p>
1001 <p>Item 1, graf one.</p>
1002 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
1024 <p>Here's another:</p>
1036 <p>Same thing but with paragraphs:</p>
1054 assert md_to_html
(md
) == html
1057 fun test_daring_strong_em
is test
do
1059 ***This is strong and em.***
1061 So is ***this*** word.
1063 ___This is strong and em.___
1065 So is ___this___ word.
1069 <p><em><strong>This is strong and em.</strong></em></p>
1070 <p>So is <em><strong>this</strong></em> word.</p>
1071 <p><em><strong>This is strong and em.</strong></em></p>
1072 <p>So is <em><strong>this</strong></em> word.</p>
1074 assert md_to_html
(md
) == html
1077 fun test_daring_tabs
is test
do
1079 + this is a list item
1082 + this is a list item
1083 indented with spaces
1087 this code block is indented by one tab
1091 this code block is indented by two tabs
1095 + this is an example list item
1098 + this is an example list item
1099 indented with spaces
1105 <p>this is a list item
1106 indented with tabs</p>
1109 <p>this is a list item
1110 indented with spaces</p>
1114 <pre><code>this code block is indented by one tab
1117 <pre><code> this code block is indented by two tabs
1120 <pre><code>+ this is an example list item
1123 + this is an example list item
1124 indented with spaces
1127 assert md_to_html
(md
) == html
1130 fun test_daring_inline_html1
is test
do
1132 Here's a simple block:
1138 This should be a code block, though:
1158 This should just be an HTML comment:
1173 Just plain comment, with trailing spaces on the line:
1203 <p>Here's a simple block:</p>
1207 <p>This should be a code block, though:</p>
1208 <pre><code><div>
1212 <p>As should this:</p>
1213 <pre><code><div>foo</div>
1223 <p>This should just be an HTML comment:</p>
1231 <pre><code><!-- Comment -->
1233 <p>Just plain comment, with trailing spaces on the line:</p>
1236 <pre><code><hr />
1249 assert md_to_html
(md
) == html
1252 fun test_daring_inline_html2
is test
do
1254 Simple block on one line:
1258 And nested without indentation:
1270 And with attributes:
1277 This was broken in 1.0.2b7:
1279 <div class="inlinepage">
1280 <div class="toggleableend">
1287 <p>Simple block on one line:</p>
1289 <p>And nested without indentation:</p>
1299 <p>And with attributes:</p>
1304 <p>This was broken in 1.0.2b7:</p>
1305 <div class="inlinepage">
1306 <div class="toggleableend">
1311 assert md_to_html
(md
) == html
1314 fun test_daring_inline_html3
is test
do
1318 <!-- This is a simple comment -->
1321 This is another comment.
1326 <!-- one comment block -- -- with two comments -->
1332 <p>Paragraph one.</p>
1333 <!-- This is a simple comment -->
1335 This is another comment.
1337 <p>Paragraph two.</p>
1338 <!-- one comment block -- -- with two comments -->
1341 assert md_to_html
(md
) == html