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 express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Test suites for module `markdown`
16 module test_markdown
is test
18 intrude import markdown
20 class TestMarkdownProcessor
23 fun test_process_empty
is test
do
26 var res
= test
.md_to_html
.write_to_string
30 fun test_process_tabs
is test
do
34 var exp
= """<pre><code>some code
37 var res
= test
.md_to_html
.write_to_string
42 fun test_process_par1
is test
do
44 var exp
= "<p>test</p>\n"
45 var res
= test
.md_to_html
.write_to_string
49 fun test_process_par2
is test
do
63 var res
= test
.md_to_html
.write_to_string
67 fun test_process_par3
is test
do
69 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
70 Aliquam hendrerit mi posuere lectus.
71 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
73 Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
74 id sem consectetuer libero luctus adipiscing.
77 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
78 Aliquam hendrerit mi posuere lectus.
79 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
80 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
81 id sem consectetuer libero luctus adipiscing.</p>
83 var res
= test
.md_to_html
.write_to_string
87 fun test_process_headings_1
is test
do
96 <h1 id="This_is_a_H1">This is a H1</h1>
97 <h2 id="This_is_a_H2">This is a H2</h2>
99 var res
= test
.md_to_html
.write_to_string
103 fun test_process_headings_2
is test
do
111 <h1 id="This_is_a_H1">This is a H1</h1>
112 <h2 id="This_is_a_H2">This is a H2</h2>
113 <h6 id="This_is_a_H6">This is a H6</h6>
115 var res
= test
.md_to_html
.write_to_string
119 fun test_process_headings_3
is test
do
125 ### This is a H3 ######
128 <h1 id="This_is_a_H1">This is a H1</h1>
129 <h2 id="This_is_a_H2">This is a H2</h2>
130 <h3 id="This_is_a_H3">This is a H3</h3>
132 var res
= test
.md_to_html
.write_to_string
136 fun test_process_hr
is test
do
146 ---------------------------------------
148 var exp
= "<hr/>\n<hr/>\n<hr/>\n<hr/>\n<hr/>\n"
149 var res
= test
.md_to_html
.write_to_string
153 fun test_process_bquote1
is test
do
155 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
156 > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
157 > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
159 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
160 > id sem consectetuer libero luctus adipiscing.
162 var exp
= """<blockquote>
163 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
164 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
165 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
166 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
167 id sem consectetuer libero luctus adipiscing.</p>
170 var res
= test
.md_to_html
.write_to_string
174 fun test_process_bquote2
is test
do
176 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
177 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
178 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
180 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
181 id sem consectetuer libero luctus adipiscing.
183 var exp
= """<blockquote>
184 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
185 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
186 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
187 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
188 id sem consectetuer libero luctus adipiscing.</p>
191 var res
= test
.md_to_html
.write_to_string
195 fun test_process_bquote3
is test
do
197 > This is the first level of quoting.
199 > > This is nested blockquote.
201 > Back to the first level.
203 var exp
= """<blockquote>
204 <p>This is the first level of quoting.</p>
206 <p>This is nested blockquote.</p>
208 <p>Back to the first level.</p>
211 var res
= test
.md_to_html
.write_to_string
215 fun test_process_list1
is test
do
227 var res
= test
.md_to_html
.write_to_string
231 fun test_process_list2
is test
do
243 var res
= test
.md_to_html
.write_to_string
247 fun test_process_list3
is test
do
259 var res
= test
.md_to_html
.write_to_string
263 fun test_process_list4
is test
do
275 var res
= test
.md_to_html
.write_to_string
279 fun test_process_list5
is test
do
291 var res
= test
.md_to_html
.write_to_string
295 fun test_process_list6
is test
do
297 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
298 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
299 viverra nec, fringilla in, laoreet vitae, risus.
300 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
301 Suspendisse id sem consectetuer libero luctus adipiscing.
305 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
306 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
307 viverra nec, fringilla in, laoreet vitae, risus.</li>
308 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
309 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
312 var res
= test
.md_to_html
.write_to_string
316 fun test_process_list7
is test
do
318 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
319 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
320 viverra nec, fringilla in, laoreet vitae, risus.
321 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
322 Suspendisse id sem consectetuer libero luctus adipiscing.
326 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
327 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
328 viverra nec, fringilla in, laoreet vitae, risus.</li>
329 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
330 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
333 var res
= test
.md_to_html
.write_to_string
337 fun test_process_list8
is test
do
351 var res
= test
.md_to_html
.write_to_string
355 fun test_process_list9
is test
do
357 1. This is a list item with two paragraphs. Lorem ipsum dolor
358 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
361 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
362 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
365 2. Suspendisse id sem consectetuer libero luctus adipiscing.
369 <li><p>This is a list item with two paragraphs. Lorem ipsum dolor
370 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
371 mi posuere lectus.</p>
372 <p>Vestibulum enim wisi, viverra nec, fringilla in, laoreet
373 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
376 <li><p>Suspendisse id sem consectetuer libero luctus adipiscing.</p>
380 var res
= test
.md_to_html
.write_to_string
384 fun test_process_list10
is test
do
386 * This is a list item with two paragraphs.
388 This is the second paragraph in the list item. You're
389 only required to indent the first line. Lorem ipsum dolor
390 sit amet, consectetuer adipiscing elit.
392 * Another item in the same list.
396 <li><p>This is a list item with two paragraphs.</p>
397 <p>This is the second paragraph in the list item. You're
398 only required to indent the first line. Lorem ipsum dolor
399 sit amet, consectetuer adipiscing elit.</p>
401 <li><p>Another item in the same list.</p>
405 var res
= test
.md_to_html
.write_to_string
409 fun test_process_list11
is test
do
412 * and this is not a list
415 <p>This is a paragraph
416 * and this is not a list</p>
418 var proc
= new MarkdownProcessor
419 proc
.ext_mode
= false
420 var res
= proc
.process
(test
).write_to_string
424 fun test_process_list_ext
is test
do
427 * and this is not a list
430 <p>This is a paragraph</p>
432 <li>and this is not a list</li>
435 var res
= test
.md_to_html
.write_to_string
439 fun test_process_code1
is test
do
441 This is a normal paragraph:
443 This is a code block.
445 var exp
= """<p>This is a normal paragraph:</p>
446 <pre><code>This is a code block.
449 var res
= test
.md_to_html
.write_to_string
453 fun test_process_code2
is test
do
455 Here is an example of AppleScript:
457 tell application "Foo"
462 © 2004 Foo Corporation
466 <p>Here is an example of AppleScript:</p>
467 <pre><code>tell application "Foo"
471 <div class="footer">
472 &copy; 2004 Foo Corporation
476 var res
= test
.md_to_html
.write_to_string
480 fun test_process_code_ext1
is test
do
482 Here is an example of AppleScript:
484 tell application "Foo"
489 © 2004 Foo Corporation
494 <p>Here is an example of AppleScript:</p>
495 <pre><code>tell application "Foo"
499 <div class="footer">
500 &copy; 2004 Foo Corporation
504 var res
= test
.md_to_html
.write_to_string
508 fun test_process_code_ext2
is test
do
510 Here is an example of AppleScript:
512 tell application "Foo"
517 © 2004 Foo Corporation
522 <p>Here is an example of AppleScript:</p>
523 <pre><code>tell application "Foo"
527 <div class="footer">
528 &copy; 2004 Foo Corporation
532 var res
= test
.md_to_html
.write_to_string
536 fun test_process_code_ext3
is test
do
537 var proc
= new MarkdownProcessor
538 proc
.ext_mode
= false
541 Here is an example of AppleScript:
545 <p>Here is an example of AppleScript:
548 var res
= proc
.process
(test
).write_to_string
552 fun test_process_code_ext4
is test
do
554 Here is an example of AppleScript:
558 <p>Here is an example of AppleScript:</p>
562 var res
= test
.md_to_html
.write_to_string
566 fun test_process_code_ext5
is test
do
573 <pre class="nit"><code>print "Hello World!"
576 var res
= test
.md_to_html
.write_to_string
580 fun test_process_code_ext6
is test
do
590 <pre><code>print "Hello"
592 <pre><code>print "World"
595 var res
= test
.md_to_html
.write_to_string
599 fun test_process_code_ext7
is test
do
609 <pre><code>print "Hello"
611 <pre><code>print "World"
614 var res
= test
.md_to_html
.write_to_string
618 fun test_process_nesting1
is test
do
620 > ## This is a header.
622 > 1. This is the first list item.
623 > 2. This is the second list item.
625 > Here's some example code:
627 > return shell_exec("echo $input | $markdown_script");
631 <h2 id="This_is_a_header.">This is a header.</h2>
633 <li>This is the first list item.</li>
634 <li>This is the second list item.</li>
636 <p>Here's some example code:</p>
637 <pre><code>return shell_exec("echo $input | $markdown_script");
641 var res
= test
.md_to_html
.write_to_string
645 fun test_process_nesting2
is test
do
647 * A list item with a blockquote:
649 > This is a blockquote
650 > inside a list item.
654 <li><p>A list item with a blockquote:</p>
656 <p>This is a blockquote
657 inside a list item.</p>
662 var res
= test
.md_to_html
.write_to_string
666 fun test_process_nesting3
is test
do
668 * A list item with a code block:
674 <li><p>A list item with a code block:</p>
675 <pre><code><code goes here>
680 var res
= test
.md_to_html
.write_to_string
684 fun test_process_nesting4
is test
do
701 var res
= test
.md_to_html
.write_to_string
706 # fun test_process_nesting5 is test do
724 # var res = test.md_to_html.write_to_string
728 fun test_process_emph1
is test
do
736 __double underscores__
738 var exp
= """<p><em>single asterisks</em></p>
739 <p><em>single underscores</em></p>
740 <p><strong>double asterisks</strong></p>
741 <p><strong>double underscores</strong></p>
743 var res
= test
.md_to_html
.write_to_string
747 fun test_process_emph2
is test
do
748 var test
= "un*frigging*believable"
749 var exp
= "<p>un<em>frigging</em>believable</p>\n"
750 var res
= test
.md_to_html
.write_to_string
754 fun test_process_emph3
is test
do
755 var proc
= new MarkdownProcessor
756 proc
.ext_mode
= false
757 var test
= "Con_cat_this"
758 var exp
= "<p>Con<em>cat</em>this</p>\n"
759 var res
= proc
.process
(test
).write_to_string
763 fun test_process_emph_ext
is test
do
764 var test
= "Con_cat_this"
765 var exp
= "<p>Con_cat_this</p>\n"
766 var res
= test
.md_to_html
.write_to_string
770 fun test_process_xml1
is test
do
772 This is a regular paragraph.
780 This is another regular paragraph.
783 <p>This is a regular paragraph.</p>
789 <p>This is another regular paragraph.</p>
791 var res
= test
.md_to_html
.write_to_string
795 fun test_process_xml2
is test
do
797 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
799 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
801 var res
= test
.md_to_html
.write_to_string
805 fun test_process_xml3
is test
do
812 var res
= test
.md_to_html
.write_to_string
816 fun test_process_xml4
is test
do
818 <p>This is an example of a block element that should be escaped.</p>
819 <p>Idem for the second paragraph.</p>
822 var res
= test
.md_to_html
.write_to_string
826 fun test_process_xml5
is test
do
828 # Some more XML tests
830 <p>This is an example of a block element that should be escaped.</p>
831 <p>Idem for the second paragraph.</p>
833 With a *md paragraph*!
836 <h1 id="Some_more_XML_tests">Some more XML tests</h1>
837 <p>This is an example of a block element that should be escaped.</p>
838 <p>Idem for the second paragraph.</p>
839 <p>With a <em>md paragraph</em>!</p>
841 var res
= test
.md_to_html
.write_to_string
846 fun test_process_span_code1
is test
do
847 var test
= "Use the `printf()` function."
848 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
849 var res
= test
.md_to_html
.write_to_string
853 fun test_process_span_code2
is test
do
854 var test
= "``There is a literal backtick (`) here.``"
855 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
856 var res
= test
.md_to_html
.write_to_string
860 fun test_process_span_code3
is test
do
862 A single backtick in a code span: `` ` ``
864 A backtick-delimited string in a code span: `` `foo` ``
867 <p>A single backtick in a code span: <code>`</code></p>
868 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
870 var res
= test
.md_to_html
.write_to_string
874 fun test_process_span_code4
is test
do
875 var test
= "Please don't use any `<blink>` tags."
876 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
877 var res
= test
.md_to_html
.write_to_string
881 fun test_process_span_code5
is test
do
882 var test
= "`—` is the decimal-encoded equivalent of `—`."
883 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
884 var res
= test
.md_to_html
.write_to_string
888 fun test_process_escape1
is test
do
889 var test
= "\\*this text is surrounded by literal asterisks\\*"
890 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
891 var res
= test
.md_to_html
.write_to_string
895 fun test_process_escape2
is test
do
896 var test
= "1986\\. What a great season."
897 var exp
= "<p>1986. What a great season.</p>\n"
898 var res
= test
.md_to_html
.write_to_string
902 fun test_process_escape3
is test
do
903 var test
= "Ben & Lux"
904 var exp
= "<p>Ben & Lux</p>\n"
905 var res
= test
.md_to_html
.write_to_string
909 fun test_process_link1
is test
do
911 This is [an example](http://example.com/ "Title") inline link.
913 [This link](http://example.net/) has no title attribute.
915 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
916 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
918 var res
= test
.md_to_html
.write_to_string
922 fun test_process_link2
is test
do
923 var test
= "See my [About](/about/) page for details."
924 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
925 var res
= test
.md_to_html
.write_to_string
929 fun test_process_link3
is test
do
931 This is [an example][id] reference-style link.
933 This is [an example] [id] reference-style link.
937 [id]: http://example.com/ "Optional Title Here"
942 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
943 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
944 <p>Some lorem ipsum</p>
945 <p>Some other lipsum</p>
947 var res
= test
.md_to_html
.write_to_string
951 fun test_process_link4
is test
do
953 This is multiple examples: [foo][1], [bar][2], [baz][3].
955 [1]: http://example.com/ "Optional Title Here"
956 [2]: http://example.com/ 'Optional Title Here'
957 [3]: http://example.com/ (Optional Title Here)
960 <p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">baz</a>.</p>
962 var res
= test
.md_to_html
.write_to_string
966 fun test_process_link5
is test
do
968 This is multiple examples: [foo][a], [bar][A], [a].
970 [a]: http://example.com/ "Optional Title Here"
972 var exp
= """<p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">a</a>.</p>
974 var res
= test
.md_to_html
.write_to_string
978 fun test_process_link6
is test
do
980 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
982 [Google]: http://google.com/ "Google"
983 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
984 [MSN]: http://search.msn.com/ "MSN Search"
986 var exp
= """<p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
988 var res
= test
.md_to_html
.write_to_string
992 fun test_process_link7
is test
do
994 Visit [Daring Fireball][] for more information.
996 [Daring Fireball]: http://daringfireball.net/
998 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
1000 var res
= test
.md_to_html
.write_to_string
1004 fun test_process_link8
is test
do
1006 This one has a [line
1009 This one has a [line
1010 break] with a line-ending space.
1015 <p>This one has a <a href="/foo">line
1017 <p>This one has a <a href="/foo">line
1018 break</a> with a line-ending space.</p>
1020 var res
= test
.md_to_html
.write_to_string
1024 # FIXME unignore test once escape strings fixed
1025 # fun test_process_link9 is test do
1029 # Foo [bar](/url/ "Title with \"quotes\" inside").
1032 # [bar]: /url/ "Title with \"quotes\" inside"
1035 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1036 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1038 # var res = test.md_to_html.write_to_string
1042 fun test_process_img1
is test
do
1044 ![Alt text](/path/to/img.jpg)
1046 ![Alt text](/path/to/img.jpg "Optional title")
1048 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1049 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1051 var res
= test
.md_to_html
.write_to_string
1055 fun test_process_img2
is test
do
1059 [id]: url/to/image "Optional title attribute"
1061 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
1063 var res
= test
.md_to_html
.write_to_string
1067 fun test_process_strike
is test
do
1068 var proc
= new MarkdownProcessor
1069 proc
.ext_mode
= false
1070 var test
= "This is how you ~~strike text~~"
1071 var exp
= "<p>This is how you ~~strike text~~</p>\n"
1072 var res
= proc
.process
(test
).write_to_string
1076 fun test_process_strike_ext
is test
do
1077 var test
= "This is how you ~~strike text~~"
1078 var exp
= "<p>This is how you <del>strike text</del></p>\n"
1079 var res
= test
.md_to_html
.write_to_string
1083 fun test_escape_bad_html
is test
do
1084 var test
= "-1 if < , +1 if > and 0 otherwise"
1085 var exp
= "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
1086 var res
= test
.md_to_html
.write_to_string
1090 fun test_daring_encoding
is test
do
1092 AT&T has an ampersand in their name.
1094 AT&T is another way to write it.
1102 Here's a [link] [1] with an ampersand in the URL.
1104 Here's a link with an amersand in the link text: [AT&T] [2].
1106 Here's an inline [link](/script?foo=1&bar=2).
1108 Here's an inline [link](</script?foo=1&bar=2>).
1111 [1]: http://example.com/?foo=1&bar=2
1112 [2]: http://att.com/ "AT&T"
1116 <p>AT&T has an ampersand in their name.</p>
1117 <p>AT&T is another way to write it.</p>
1118 <p>This & that.</p>
1121 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
1122 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
1123 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1124 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1126 var res
= test
.md_to_html
.write_to_string
1131 fun test_daring_autolinks
is test
do
1133 Link: <http://example.com/>.
1135 With an ampersand: <http://example.com/?foo=1&bar=2>
1138 * <http://example.com/>
1141 > Blockquoted: <http://example.com/>
1143 Auto-links should not occur here: `<http://example.com/>`
1145 or here: <http://example.com/>
1149 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
1150 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
1153 <li><a href="http://example.com/">http://example.com/</a></li>
1157 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
1159 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
1160 <pre><code>or here: <http://example.com/>
1163 var res
= test
.md_to_html
.write_to_string
1167 fun test_daring_escape
is test
do
1169 These should all get escaped:
1204 These should not, because they occur within a code block:
1238 Nor should these, which occur in code spans:
1272 These should get escaped, even though they're matching pairs for
1273 other Markdown constructs:
1281 This is a code span with a literal backslash-backtick sequence: `` \` ``
1283 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1285 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1288 <p>These should all get escaped:</p>
1289 <p>Backslash: \\</p>
1292 <p>Underscore: \_</p>
1293 <p>Left brace: \{</p>
1294 <p>Right brace: \}</p>
1295 <p>Left bracket: \[</p>
1296 <p>Right bracket: \]</p>
1297 <p>Left paren: \(</p>
1298 <p>Right paren: \)</p>
1299 <p>Greater-than: \></p>
1305 <p>These should not, because they occur within a code block:</p>
1306 <pre><code>Backslash: \\
1338 <p>Nor should these, which occur in code spans:</p>
1339 <p>Backslash: <code>\\</code></p>
1340 <p>Backtick: <code>\`</code></p>
1341 <p>Asterisk: <code>\*</code></p>
1342 <p>Underscore: <code>\_</code></p>
1343 <p>Left brace: <code>\{</code></p>
1344 <p>Right brace: <code>\}</code></p>
1345 <p>Left bracket: <code>\[</code></p>
1346 <p>Right bracket: <code>\]</code></p>
1347 <p>Left paren: <code>\(</code></p>
1348 <p>Right paren: <code>\)</code></p>
1349 <p>Greater-than: <code>\></code></p>
1350 <p>Hash: <code>\#</code></p>
1351 <p>Period: <code>\.</code></p>
1352 <p>Bang: <code>\!</code></p>
1353 <p>Plus: <code>\+</code></p>
1354 <p>Minus: <code>\-</code></p>
1355 <p>These should get escaped, even though they're matching pairs for
1356 other Markdown constructs:</p>
1358 <p>_underscores_</p>
1360 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1361 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1362 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1365 var res
= test
.md_to_html
.write_to_string
1369 fun test_daring_blockquotes
is test
do
1387 <pre><code>sub status {
1392 <pre><code>sub status {
1398 var res
= test
.md_to_html
.write_to_string
1402 fun test_daring_code_blocks
is test
do
1404 code block on the first line
1408 code block indented by spaces
1412 the lines in this block
1413 all contain trailing spaces
1417 code block on the last line
1421 <pre><code>code block on the first line
1423 <p>Regular text.</p>
1424 <pre><code>code block indented by spaces
1426 <p>Regular text.</p>
1427 <pre><code>the lines in this block
1428 all contain trailing spaces
1430 <p>Regular Text.</p>
1431 <pre><code>code block on the last line
1434 var res
= test
.md_to_html
.write_to_string
1438 fun test_daring_code_spans
is test
do
1440 `<test a="` content of attribute `">`
1442 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1444 Here's how you put `` `backticks` `` in a code span.
1448 <p><code><test a="</code> content of attribute <code>"></code></p>
1449 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1450 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1452 var res
= test
.md_to_html
.write_to_string
1456 fun test_daring_pars
is test
do
1457 var proc
= new MarkdownProcessor
1458 proc
.ext_mode
= false
1461 In Markdown 1.0.0 and earlier. Version
1462 8. This line turns into a list item.
1463 Because a hard-wrapped line in the
1464 middle of a paragraph looked like a
1467 Here's one with a bullet.
1472 <p>In Markdown 1.0.0 and earlier. Version
1473 8. This line turns into a list item.
1474 Because a hard-wrapped line in the
1475 middle of a paragraph looked like a
1477 <p>Here's one with a bullet.
1480 var res
= proc
.process
(test
).write_to_string
1484 fun test_daring_rules
is test
do
1596 var res
= test
.md_to_html
.write_to_string
1600 fun test_daring_images
is test
do
1602 ![Alt text](/path/to/img.jpg)
1604 ![Alt text](/path/to/img.jpg "Optional title")
1606 Inline within a paragraph: [alt text](/url/).
1608 ![alt text](/url/ "title preceded by two spaces")
1610 ![alt text](/url/ "title has spaces afterward" )
1612 ![alt text](</url/>)
1614 ![alt text](</url/> "with a title").
1618 ![this is a stupid URL](http://example.com/(parens).jpg)
1627 [bar]: /url/ "Title here"
1631 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1632 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1633 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1634 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1635 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1636 <p><img src="/url/" alt="alt text"/></p>
1637 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1638 <p><img src="" alt="Empty"/></p>
1639 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1640 <p><img src="/url/" alt="alt text"/></p>
1641 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1643 var res
= test
.md_to_html
.write_to_string
1647 fun test_daring_inline_html1
is test
do
1649 Here's a simple block:
1655 This should be a code block, though:
1675 This should just be an HTML comment:
1690 Just plain comment, with trailing spaces on the line:
1712 <hr class="foo" id="bar" />
1714 <hr class="foo" id="bar"/>
1716 <hr class="foo" id="bar" >
1720 <p>Here's a simple block:</p>
1724 <p>This should be a code block, though:</p>
1725 <pre><code><div>
1729 <p>As should this:</p>
1730 <pre><code><div>foo</div>
1740 <p>This should just be an HTML comment:</p>
1748 <pre><code><!-- Comment -->
1750 <p>Just plain comment, with trailing spaces on the line:</p>
1753 <pre><code><hr />
1762 <hr class="foo" id="bar" />
1763 <hr class="foo" id="bar"/>
1764 <hr class="foo" id="bar" >
1766 var res
= test
.md_to_html
.write_to_string
1770 fun test_daring_inline_html2
is test
do
1772 Simple block on one line:
1776 And nested without indentation:
1788 And with attributes:
1795 This was broken in 1.0.2b7:
1797 <div class="inlinepage">
1798 <div class="toggleableend">
1805 <p>Simple block on one line:</p>
1807 <p>And nested without indentation:</p>
1817 <p>And with attributes:</p>
1822 <p>This was broken in 1.0.2b7:</p>
1823 <div class="inlinepage">
1824 <div class="toggleableend">
1829 var res
= test
.md_to_html
.write_to_string
1833 fun test_daring_inline_html3
is test
do
1837 <!-- This is a simple comment -->
1840 This is another comment.
1845 <!-- one comment block -- -- with two comments -->
1851 <p>Paragraph one.</p>
1852 <!-- This is a simple comment -->
1854 This is another comment.
1856 <p>Paragraph two.</p>
1857 <!-- one comment block -- -- with two comments -->
1860 var res
= test
.md_to_html
.write_to_string
1864 fun test_daring_links1
is test
do
1866 Just a [URL](/url/).
1868 [URL and title](/url/ "title").
1870 [URL and title](/url/ "title preceded by two spaces").
1872 [URL and title](/url/ "title preceded by a tab").
1874 [URL and title](/url/ "title has spaces afterward" ).
1876 [URL wrapped in angle brackets](</url/>).
1878 [URL w/ angle brackets + title](</url/> "Here's the title").
1882 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1884 (With outer parens and [parens in url](/foo(bar)))
1887 [With parens in the URL](/foo(bar) "and a title")
1889 (With outer parens and [parens in url](/foo(bar) "and a title"))
1893 <p>Just a <a href="/url/">URL</a>.</p>
1894 <p><a href="/url/" title="title">URL and title</a>.</p>
1895 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1896 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1897 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1898 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1899 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1900 <p><a href="">Empty</a>.</p>
1901 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1902 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1903 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1904 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1906 var res
= test
.md_to_html
.write_to_string
1910 fun test_daring_links2
is test
do
1922 With [embedded [brackets]] [b].
1929 Indented [thrice][].
1931 Indented [four][] times.
1946 [this] [this] should work
1948 So should [this][this].
1962 [Something in brackets like [this][] should work]
1966 In this case, [this](/somethingelse/) points to something else.
1968 Backslashing should suppress \\\[this] and [this\\\].
1975 Here's one where the [link
1976 breaks] across lines.
1978 Here's another where the [link
1979 breaks] across lines, but with a line-ending space.
1982 [link breaks]: /url/
1986 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1987 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1988 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1989 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1990 <p>Indented <a href="/url">once</a>.</p>
1991 <p>Indented <a href="/url">twice</a>.</p>
1992 <p>Indented <a href="/url">thrice</a>.</p>
1993 <p>Indented [four][] times.</p>
1994 <pre><code>[four]: /url
1997 <p><a href="foo">this</a> should work</p>
1998 <p>So should <a href="foo">this</a>.</p>
1999 <p>And <a href="foo">this</a>.</p>
2000 <p>And <a href="foo">this</a>.</p>
2001 <p>And <a href="foo">this</a>.</p>
2002 <p>But not [that] [].</p>
2003 <p>Nor [that][].</p>
2005 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
2006 <p>[Same with <a href="foo">this</a>.]</p>
2007 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
2008 <p>Backslashing should suppress [this] and [this].</p>
2010 <p>Here's one where the <a href="/url/">link
2011 breaks</a> across lines.</p>
2012 <p>Here's another where the <a href="/url/">link
2013 breaks</a> across lines, but with a line-ending space.</p>
2015 var res
= test
.md_to_html
.write_to_string
2019 fun test_daring_links3
is test
do
2021 This is the [simple case].
2023 [simple case]: /simple
2027 This one has a [line
2030 This one has a [line
2031 break] with a line-ending space.
2036 [this] [that] and the [other]
2044 <p>This is the <a href="/simple">simple case</a>.</p>
2045 <p>This one has a <a href="/foo">line
2047 <p>This one has a <a href="/foo">line
2048 break</a> with a line-ending space.</p>
2049 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
2051 var res
= test
.md_to_html
.write_to_string
2055 fun test_daring_nested
is test
do
2073 var res
= test
.md_to_html
.write_to_string
2077 fun test_daring_list
is test
do
2163 Multiple paragraphs:
2165 1. Item 1, graf one.
2167 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2191 Same thing but with paragraphs:
2204 <h2 id="Unordered">Unordered</h2>
2205 <p>Asterisks tight:</p>
2211 <p>Asterisks loose:</p>
2213 <li><p>asterisk 1</p>
2215 <li><p>asterisk 2</p>
2217 <li><p>asterisk 3</p>
2221 <p>Pluses tight:</p>
2227 <p>Pluses loose:</p>
2237 <p>Minuses tight:</p>
2243 <p>Minuses loose:</p>
2252 <h2 id="Ordered">Ordered</h2>
2265 <p>Loose using tabs:</p>
2274 <p>and using spaces:</p>
2283 <p>Multiple paragraphs:</p>
2285 <li><p>Item 1, graf one.</p>
2286 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2294 <h2 id="Nested">Nested</h2>
2304 <p>Here's another:</p>
2315 <p>Same thing but with paragraphs:</p>
2330 var res
= test
.md_to_html
.write_to_string
2334 fun test_daring_strong_em
is test
do
2336 ***This is strong and em.***
2338 So is ***this*** word.
2340 ___This is strong and em.___
2342 So is ___this___ word.
2346 <p><strong><em>This is strong and em.</em></strong></p>
2347 <p>So is <strong><em>this</em></strong> word.</p>
2348 <p><strong><em>This is strong and em.</em></strong></p>
2349 <p>So is <strong><em>this</em></strong> word.</p>
2351 var res
= test
.md_to_html
.write_to_string
2355 fun test_daring_tabs
is test
do
2357 + this is a list item
2360 + this is a list item
2361 indented with spaces
2365 this code block is indented by one tab
2369 this code block is indented by two tabs
2373 + this is an example list item
2376 + this is an example list item
2377 indented with spaces
2382 <li><p>this is a list item
2383 indented with tabs</p>
2385 <li><p>this is a list item
2386 indented with spaces</p>
2390 <pre><code>this code block is indented by one tab
2393 <pre><code> this code block is indented by two tabs
2396 <pre><code>+ this is an example list item
2399 + this is an example list item
2400 indented with spaces
2403 var res
= test
.md_to_html
.write_to_string
2407 fun test_daring_tidyness
is test
do
2409 > A list within a blockquote:
2418 <p>A list within a blockquote:</p>
2426 var res
= test
.md_to_html
.write_to_string
2436 # A dummy location for testing purposes.
2437 var loc
= new MDLocation(0, 0, 0, 0)
2439 fun test_has_blocks
is test
do
2440 var subject
= new MDBlock(loc
)
2441 assert not subject
.has_blocks
2442 subject
.first_block
= new MDBlock(loc
)
2443 assert subject
.has_blocks
2446 fun test_count_blocks
is test
do
2447 var subject
= new MDBlock(loc
)
2448 assert subject
.count_blocks
== 0
2449 subject
.first_block
= new MDBlock(loc
)
2450 assert subject
.count_blocks
== 1
2451 subject
.first_block
.next
= new MDBlock(loc
)
2452 assert subject
.count_blocks
== 2
2455 fun test_has_lines
is test
do
2456 var subject
= new MDBlock(loc
)
2457 assert not subject
.has_lines
2458 subject
.first_line
= new MDLine(loc
, "")
2459 assert subject
.has_lines
2462 fun test_count_lines
is test
do
2463 var subject
= new MDBlock(loc
)
2464 assert subject
.count_lines
== 0
2465 subject
.first_line
= new MDLine(loc
, "")
2466 assert subject
.count_lines
== 1
2467 subject
.first_line
.next
= new MDLine(loc
, "")
2468 assert subject
.count_lines
== 2
2471 fun test_split
is test
do
2472 var line1
= new MDLine(loc
, "line1")
2473 var line2
= new MDLine(loc
, "line2")
2474 var line3
= new MDLine(loc
, "line3")
2475 var subject
= new MDBlock(loc
)
2476 subject
.add_line line1
2477 subject
.add_line line2
2478 subject
.add_line line3
2479 var block
= subject
.split
(line2
)
2480 assert subject
.count_blocks
== 1
2481 assert subject
.count_lines
== 1
2482 assert subject
.first_line
== line3
2483 assert block
.count_blocks
== 0
2484 assert block
.count_lines
== 2
2485 assert block
.first_line
== line1
2486 assert block
.last_line
== line2
2489 fun test_add_line
is test
do
2490 var subject
= new MDBlock(loc
)
2491 assert subject
.count_lines
== 0
2492 subject
.add_line
new MDLine(loc
, "")
2493 assert subject
.count_lines
== 1
2494 subject
.add_line
new MDLine(loc
, "")
2495 assert subject
.count_lines
== 2
2498 fun test_remove_line
is test
do
2499 var line1
= new MDLine(loc
, "line1")
2500 var line2
= new MDLine(loc
, "line2")
2501 var line3
= new MDLine(loc
, "line3")
2502 var subject
= new MDBlock(loc
)
2503 subject
.add_line line1
2504 subject
.add_line line2
2505 subject
.add_line line3
2506 subject
.remove_line
(line2
)
2507 assert subject
.count_lines
== 2
2508 subject
.remove_line
(line1
)
2509 assert subject
.count_lines
== 1
2510 assert subject
.first_line
== line3
2511 assert subject
.last_line
== line3
2514 fun test_transform_headline1
is test
do
2515 var subject
= new MDBlock(loc
)
2516 var kind
= new BlockHeadline(subject
)
2517 subject
.add_line
new MDLine(loc
, " # Title 1 ")
2518 kind
.transform_headline
(subject
)
2519 assert kind
.depth
== 1
2520 assert subject
.first_line
.value
== "Title 1"
2523 fun test_transform_headline2
is test
do
2524 var subject
= new MDBlock(loc
)
2525 var kind
= new BlockHeadline(subject
)
2526 subject
.add_line
new MDLine(loc
, " #####Title 5 ")
2527 kind
.transform_headline
(subject
)
2528 assert kind
.depth
== 5
2529 assert subject
.first_line
.value
== "Title 5"
2532 fun test_remove_quote_prefix
is test
do
2533 var subject
= new MDBlock(loc
)
2534 var kind
= new BlockQuote(subject
)
2535 subject
.add_line
new MDLine(loc
, " > line 1")
2536 subject
.add_line
new MDLine(loc
, " > line 2")
2537 subject
.add_line
new MDLine(loc
, " > line 3")
2538 kind
.remove_block_quote_prefix
(subject
)
2539 assert subject
.first_line
.value
== "line 1"
2540 assert subject
.first_line
.next
.value
== "line 2"
2541 assert subject
.first_line
.next
.next
.value
== "line 3"
2544 fun test_remove_leading_empty_lines_1
is test
do
2545 var block
= new MDBlock(loc
)
2546 block
.add_line
new MDLine(loc
, "")
2547 block
.add_line
new MDLine(loc
, "")
2548 block
.add_line
new MDLine(loc
, "")
2549 block
.add_line
new MDLine(loc
, "")
2550 block
.add_line
new MDLine(loc
, " text")
2551 block
.add_line
new MDLine(loc
, "")
2552 assert block
.remove_leading_empty_lines
2553 assert block
.first_line
.value
== " text"
2556 fun test_remove_leading_empty_lines_2
is test
do
2557 var block
= new MDBlock(loc
)
2558 block
.add_line
new MDLine(loc
, " text")
2559 block
.remove_leading_empty_lines
2560 assert block
.first_line
.value
== " text"
2563 fun test_remove_trailing_empty_lines_1
is test
do
2564 var block
= new MDBlock(loc
)
2565 block
.add_line
new MDLine(loc
, "")
2566 block
.add_line
new MDLine(loc
, "text")
2567 block
.add_line
new MDLine(loc
, "")
2568 block
.add_line
new MDLine(loc
, "")
2569 block
.add_line
new MDLine(loc
, "")
2570 block
.add_line
new MDLine(loc
, "")
2571 assert block
.remove_trailing_empty_lines
2572 assert block
.last_line
.value
== "text"
2575 fun test_remove_trailing_empty_lines_2
is test
do
2576 var block
= new MDBlock(loc
)
2577 block
.add_line
new MDLine(loc
, "text ")
2578 assert not block
.remove_trailing_empty_lines
2579 assert block
.last_line
.value
== "text "
2582 fun test_remove_surrounding_empty_lines
is test
do
2583 var block
= new MDBlock(loc
)
2584 block
.add_line
new MDLine(loc
, "")
2585 block
.add_line
new MDLine(loc
, "text")
2586 block
.add_line
new MDLine(loc
, "")
2587 block
.add_line
new MDLine(loc
, "")
2588 block
.add_line
new MDLine(loc
, "")
2589 block
.add_line
new MDLine(loc
, "")
2590 assert block
.remove_surrounding_empty_lines
2591 assert block
.first_line
.value
== "text"
2592 assert block
.last_line
.value
== "text"
2599 # A dummy location for testing purposes.
2600 var loc
= new MDLocation(0, 0, 0, 0)
2604 fun test_is_empty
is test
do
2605 subject
= new MDLine(loc
, "")
2606 assert subject
.is_empty
2607 subject
= new MDLine(loc
, " ")
2608 assert subject
.is_empty
2609 subject
= new MDLine(loc
, "test")
2610 assert not subject
.is_empty
2611 subject
= new MDLine(loc
, " test")
2612 assert not subject
.is_empty
2615 fun test_leading
is test
do
2616 subject
= new MDLine(loc
, "")
2617 assert subject
.leading
== 0
2618 subject
= new MDLine(loc
, " ")
2619 assert subject
.leading
== 4
2620 subject
= new MDLine(loc
, "test")
2621 assert subject
.leading
== 0
2622 subject
= new MDLine(loc
, " test")
2623 assert subject
.leading
== 4
2626 fun test_trailing
is test
do
2627 subject
= new MDLine(loc
, "")
2628 assert subject
.trailing
== 0
2629 subject
= new MDLine(loc
, " ")
2630 assert subject
.trailing
== 0
2631 subject
= new MDLine(loc
, "test ")
2632 assert subject
.trailing
== 3
2633 subject
= new MDLine(loc
, " test ")
2634 assert subject
.trailing
== 1
2637 fun test_line_type
is test
do
2638 var v
= new MarkdownProcessor
2639 subject
= new MDLine(loc
, "")
2640 assert v
.line_kind
(subject
) isa LineEmpty
2641 subject
= new MDLine(loc
, " ")
2642 assert v
.line_kind
(subject
) isa LineEmpty
2643 subject
= new MDLine(loc
, "text ")
2644 assert v
.line_kind
(subject
) isa LineOther
2645 subject
= new MDLine(loc
, " # Title")
2646 assert v
.line_kind
(subject
) isa LineHeadline
2647 subject
= new MDLine(loc
, " ### Title")
2648 assert v
.line_kind
(subject
) isa LineHeadline
2649 subject
= new MDLine(loc
, " code")
2650 assert v
.line_kind
(subject
) isa LineCode
2651 subject
= new MDLine(loc
, " Title ")
2652 subject
.next
= new MDLine(loc
, "== ")
2653 assert v
.line_kind
(subject
) isa LineHeadline1
2654 subject
= new MDLine(loc
, " Title ")
2655 subject
.next
= new MDLine(loc
, "-- ")
2656 assert v
.line_kind
(subject
) isa LineHeadline2
2657 subject
= new MDLine(loc
, " * * * ")
2658 assert v
.line_kind
(subject
) isa LineHR
2659 subject
= new MDLine(loc
, " *** ")
2660 assert v
.line_kind
(subject
) isa LineHR
2661 subject
= new MDLine(loc
, "- -- ")
2662 assert v
.line_kind
(subject
) isa LineHR
2663 subject
= new MDLine(loc
, "--------- ")
2664 assert v
.line_kind
(subject
) isa LineHR
2665 subject
= new MDLine(loc
, " >")
2666 assert v
.line_kind
(subject
) isa LineBlockquote
2667 subject
= new MDLine(loc
, "<p></p>")
2668 assert v
.line_kind
(subject
) isa LineXML
2669 subject
= new MDLine(loc
, "<p>")
2670 assert v
.line_kind
(subject
) isa LineOther
2671 subject
= new MDLine(loc
, " * foo")
2672 assert v
.line_kind
(subject
) isa LineUList
2673 subject
= new MDLine(loc
, "- foo")
2674 assert v
.line_kind
(subject
) isa LineUList
2675 subject
= new MDLine(loc
, "+ foo")
2676 assert v
.line_kind
(subject
) isa LineUList
2677 subject
= new MDLine(loc
, "1. foo")
2678 assert v
.line_kind
(subject
) isa LineOList
2679 subject
= new MDLine(loc
, " 11111. foo")
2680 assert v
.line_kind
(subject
) isa LineOList
2683 fun test_line_type_ext
is test
do
2684 var v
= new MarkdownProcessor
2685 subject
= new MDLine(loc
, " ~~~")
2686 assert v
.line_kind
(subject
) isa LineFence
2687 subject
= new MDLine(loc
, " ```")
2688 assert v
.line_kind
(subject
) isa LineFence
2689 subject
= new MDLine(loc
, "~~~raw")
2690 assert v
.line_kind
(subject
) isa LineFence
2693 fun test_count_chars
is test
do
2694 subject
= new MDLine(loc
, "")
2695 assert subject
.count_chars
('*') == 0
2696 subject
= new MDLine(loc
, "* ")
2697 assert subject
.count_chars
('*') == 1
2698 subject
= new MDLine(loc
, " * text")
2699 assert subject
.count_chars
('*') == 0
2700 subject
= new MDLine(loc
, " * * *")
2701 assert subject
.count_chars
('*') == 3
2702 subject
= new MDLine(loc
, "text ** ")
2703 assert subject
.count_chars
('*') == 0
2706 fun test_count_chars_start
is test
do
2707 subject
= new MDLine(loc
, "")
2708 assert subject
.count_chars_start
('*') == 0
2709 subject
= new MDLine(loc
, "* ")
2710 assert subject
.count_chars_start
('*') == 1
2711 subject
= new MDLine(loc
, " * text")
2712 assert subject
.count_chars_start
('*') == 1
2713 subject
= new MDLine(loc
, " * * * text")
2714 assert subject
.count_chars_start
('*') == 3
2715 subject
= new MDLine(loc
, "text ** ")
2716 assert subject
.count_chars_start
('*') == 0
2720 class TestHTMLDecorator
2723 fun test_headlines
is test
do
2737 var proc
= new MarkdownProcessor
2738 var decorator
= proc
.decorator
.as(HTMLDecorator)
2741 for id
, headline
in decorator
.headlines
do
2742 res
+= "{headline.title}:{id}\n"
2761 class TestTokenLocation
2764 fun test_token_location1
is test
do
2765 var string
= "**Hello** `World`"
2767 "TokenStrongStar at 1,1--1,1",
2768 "TokenStrongStar at 1,8--1,8",
2769 "TokenCodeSingle at 1,11--1,11",
2770 "TokenCodeSingle at 1,17--1,17"]
2771 (new TestTokenProcessor(stack
)).process
(string
)
2774 fun test_token_location2
is test
do
2775 var string
= "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
2777 "TokenStrongStar at 1,1--1,1",
2778 "TokenStrongStar at 1,8--1,8",
2779 "TokenCodeSingle at 2,1--2,1",
2780 "TokenCodeSingle at 2,7--2,7",
2781 "TokenEmStar at 3,1--3,1",
2782 "TokenEmStar at 3,9--3,9",
2783 "TokenLink at 4,1--4,1"]
2784 (new TestTokenProcessor(stack
)).process
(string
)
2787 fun test_token_location3
is test
do
2788 var string
= """**Hello**
2793 "TokenStrongStar at 1,1--1,1",
2794 "TokenStrongStar at 1,8--1,8",
2795 "TokenCodeSingle at 2,1--2,1",
2796 "TokenCodeSingle at 2,7--2,7",
2797 "TokenEmStar at 3,1--3,1",
2798 "TokenEmStar at 3,9--3,9",
2799 "TokenLink at 4,1--4,1"]
2800 (new TestTokenProcessor(stack
)).process
(string
)
2803 fun test_token_location4
is test
do
2804 var string
= "**Hello**\n\n`World`"
2806 "TokenStrongStar at 1,1--1,1",
2807 "TokenStrongStar at 1,8--1,8",
2808 "TokenCodeSingle at 3,1--3,1",
2809 "TokenCodeSingle at 3,7--3,7"]
2810 (new TestTokenProcessor(stack
)).process
(string
)
2813 fun test_token_location5
is test
do
2814 var string
= "# *Title1*\n\n# *Title2*"
2816 "TokenEmStar at 1,3--1,3",
2817 "TokenEmStar at 1,10--1,10",
2818 "TokenEmStar at 3,3--3,3",
2819 "TokenEmStar at 3,10--3,10"]
2820 (new TestTokenProcessor(stack
)).process
(string
)
2824 class TestTokenProcessor
2825 super MarkdownProcessor
2827 var test_stack
: Array[String]
2829 redef fun token_at
(input
, pos
) do
2831 if token
isa TokenNone then return token
2832 var res
= "{token.class_name} at {token.location or else "?"}"
2833 var exp
= test_stack
.shift
2842 class TestBlockLocation
2845 var proc
= new MarkdownProcessor
2847 fun test_block_location1
is test
do
2849 "BlockHeadline: 1,1--1,8",
2850 "BlockListItem: 2,1--2,6",
2851 "BlockListItem: 3,1--3,5"
2854 "# Title\n* li1\n* li2"
2855 proc
.decorator
= new TestBlockDecorator(stack
)
2856 proc
.process
(string
)
2859 fun test_block_location2
is test
do
2861 "BlockHeadline: 1,1--1,11",
2862 "BlockFence: 3,1--5,4",
2863 "BlockListItem: 7,1--7,7",
2864 "BlockListItem: 8,1--8,6"]
2865 var string
="""#### Title
2873 proc
.decorator
= new TestBlockDecorator(stack
)
2874 proc
.process
(string
)
2877 fun test_block_location3
is test
do
2879 "BlockHeadline: 1,1--1,8",
2880 "BlockHeadline: 3,1--3,10"]
2881 var string
="""# Title\n\n## Title 2"""
2882 proc
.decorator
= new TestBlockDecorator(stack
)
2883 proc
.process
(string
)
2887 class TestBlockDecorator
2890 var stack
: Array[String]
2892 redef fun add_headline
(v
, block
) do
2897 redef fun add_listitem
(v
, block
) do
2902 redef fun add_blockquote
(v
, block
) do
2907 redef fun add_code
(v
, block
) do
2912 fun check_res
(block
: Block) do
2913 var res
= "{block.class_name}: {block.block.location}"
2914 var exp
= stack
.shift