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_suite
19 intrude import markdown
21 class TestMarkdownProcessor
24 fun test_process_empty
do
27 var res
= test
.md_to_html
.write_to_string
31 fun test_process_tabs
do
35 var exp
= """<pre><code>some code
38 var res
= test
.md_to_html
.write_to_string
43 fun test_process_par1
do
45 var exp
= "<p>test</p>\n"
46 var res
= test
.md_to_html
.write_to_string
50 fun test_process_par2
do
64 var res
= test
.md_to_html
.write_to_string
68 fun test_process_par3
do
70 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
71 Aliquam hendrerit mi posuere lectus.
72 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
74 Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
75 id sem consectetuer libero luctus adipiscing.
78 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
79 Aliquam hendrerit mi posuere lectus.
80 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
81 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
82 id sem consectetuer libero luctus adipiscing.</p>
84 var res
= test
.md_to_html
.write_to_string
88 fun test_process_headings_1
do
97 <h1 id="This_is_a_H1">This is a H1</h1>
98 <h2 id="This_is_a_H2">This is a H2</h2>
100 var res
= test
.md_to_html
.write_to_string
104 fun test_process_headings_2
do
112 <h1 id="This_is_a_H1">This is a H1</h1>
113 <h2 id="This_is_a_H2">This is a H2</h2>
114 <h6 id="This_is_a_H6">This is a H6</h6>
116 var res
= test
.md_to_html
.write_to_string
120 fun test_process_headings_3
do
126 ### This is a H3 ######
129 <h1 id="This_is_a_H1">This is a H1</h1>
130 <h2 id="This_is_a_H2">This is a H2</h2>
131 <h3 id="This_is_a_H3">This is a H3</h3>
133 var res
= test
.md_to_html
.write_to_string
137 fun test_process_hr
do
147 ---------------------------------------
149 var exp
= "<hr/>\n<hr/>\n<hr/>\n<hr/>\n<hr/>\n"
150 var res
= test
.md_to_html
.write_to_string
154 fun test_process_bquote1
do
156 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
157 > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
158 > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
160 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
161 > id sem consectetuer libero luctus adipiscing.
163 var exp
= """<blockquote>
164 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
165 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
166 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
167 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
168 id sem consectetuer libero luctus adipiscing.</p>
171 var res
= test
.md_to_html
.write_to_string
175 fun test_process_bquote2
do
177 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
178 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
179 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
181 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
182 id sem consectetuer libero luctus adipiscing.
184 var exp
= """<blockquote>
185 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
186 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
187 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
188 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
189 id sem consectetuer libero luctus adipiscing.</p>
192 var res
= test
.md_to_html
.write_to_string
196 fun test_process_bquote3
do
198 > This is the first level of quoting.
200 > > This is nested blockquote.
202 > Back to the first level.
204 var exp
= """<blockquote>
205 <p>This is the first level of quoting.</p>
207 <p>This is nested blockquote.</p>
209 <p>Back to the first level.</p>
212 var res
= test
.md_to_html
.write_to_string
216 fun test_process_list1
do
228 var res
= test
.md_to_html
.write_to_string
232 fun test_process_list2
do
244 var res
= test
.md_to_html
.write_to_string
248 fun test_process_list3
do
260 var res
= test
.md_to_html
.write_to_string
264 fun test_process_list4
do
276 var res
= test
.md_to_html
.write_to_string
280 fun test_process_list5
do
292 var res
= test
.md_to_html
.write_to_string
296 fun test_process_list6
do
298 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
299 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
300 viverra nec, fringilla in, laoreet vitae, risus.
301 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
302 Suspendisse id sem consectetuer libero luctus adipiscing.
306 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
307 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
308 viverra nec, fringilla in, laoreet vitae, risus.</li>
309 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
310 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
313 var res
= test
.md_to_html
.write_to_string
317 fun test_process_list7
do
319 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
320 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
321 viverra nec, fringilla in, laoreet vitae, risus.
322 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
323 Suspendisse id sem consectetuer libero luctus adipiscing.
327 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
328 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
329 viverra nec, fringilla in, laoreet vitae, risus.</li>
330 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
331 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
334 var res
= test
.md_to_html
.write_to_string
338 fun test_process_list8
do
352 var res
= test
.md_to_html
.write_to_string
356 fun test_process_list9
do
358 1. This is a list item with two paragraphs. Lorem ipsum dolor
359 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
362 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
363 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
366 2. Suspendisse id sem consectetuer libero luctus adipiscing.
370 <li><p>This is a list item with two paragraphs. Lorem ipsum dolor
371 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
372 mi posuere lectus.</p>
373 <p>Vestibulum enim wisi, viverra nec, fringilla in, laoreet
374 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
377 <li><p>Suspendisse id sem consectetuer libero luctus adipiscing.</p>
381 var res
= test
.md_to_html
.write_to_string
385 fun test_process_list10
do
387 * This is a list item with two paragraphs.
389 This is the second paragraph in the list item. You're
390 only required to indent the first line. Lorem ipsum dolor
391 sit amet, consectetuer adipiscing elit.
393 * Another item in the same list.
397 <li><p>This is a list item with two paragraphs.</p>
398 <p>This is the second paragraph in the list item. You're
399 only required to indent the first line. Lorem ipsum dolor
400 sit amet, consectetuer adipiscing elit.</p>
402 <li><p>Another item in the same list.</p>
406 var res
= test
.md_to_html
.write_to_string
410 fun test_process_list11
do
413 * and this is not a list
416 <p>This is a paragraph
417 * and this is not a list</p>
419 var proc
= new MarkdownProcessor
420 proc
.ext_mode
= false
421 var res
= proc
.process
(test
).write_to_string
425 fun test_process_list_ext
do
428 * and this is not a list
431 <p>This is a paragraph</p>
433 <li>and this is not a list</li>
436 var res
= test
.md_to_html
.write_to_string
440 fun test_process_code1
do
442 This is a normal paragraph:
444 This is a code block.
446 var exp
= """<p>This is a normal paragraph:</p>
447 <pre><code>This is a code block.
450 var res
= test
.md_to_html
.write_to_string
454 fun test_process_code2
do
456 Here is an example of AppleScript:
458 tell application "Foo"
463 © 2004 Foo Corporation
467 <p>Here is an example of AppleScript:</p>
468 <pre><code>tell application "Foo"
472 <div class="footer">
473 &copy; 2004 Foo Corporation
477 var res
= test
.md_to_html
.write_to_string
481 fun test_process_code_ext1
do
483 Here is an example of AppleScript:
485 tell application "Foo"
490 © 2004 Foo Corporation
495 <p>Here is an example of AppleScript:</p>
496 <pre><code>tell application "Foo"
500 <div class="footer">
501 &copy; 2004 Foo Corporation
505 var res
= test
.md_to_html
.write_to_string
509 fun test_process_code_ext2
do
511 Here is an example of AppleScript:
513 tell application "Foo"
518 © 2004 Foo Corporation
523 <p>Here is an example of AppleScript:</p>
524 <pre><code>tell application "Foo"
528 <div class="footer">
529 &copy; 2004 Foo Corporation
533 var res
= test
.md_to_html
.write_to_string
537 fun test_process_code_ext3
do
538 var proc
= new MarkdownProcessor
539 proc
.ext_mode
= false
542 Here is an example of AppleScript:
546 <p>Here is an example of AppleScript:
549 var res
= proc
.process
(test
).write_to_string
553 fun test_process_code_ext4
do
555 Here is an example of AppleScript:
559 <p>Here is an example of AppleScript:</p>
563 var res
= test
.md_to_html
.write_to_string
567 fun test_process_code_ext5
do
574 <pre class="nit"><code>print "Hello World!"
577 var res
= test
.md_to_html
.write_to_string
581 fun test_process_code_ext6
do
591 <pre><code>print "Hello"
593 <pre><code>print "World"
596 var res
= test
.md_to_html
.write_to_string
600 fun test_process_code_ext7
do
610 <pre><code>print "Hello"
612 <pre><code>print "World"
615 var res
= test
.md_to_html
.write_to_string
619 fun test_process_nesting1
do
621 > ## This is a header.
623 > 1. This is the first list item.
624 > 2. This is the second list item.
626 > Here's some example code:
628 > return shell_exec("echo $input | $markdown_script");
632 <h2 id="This_is_a_header.">This is a header.</h2>
634 <li>This is the first list item.</li>
635 <li>This is the second list item.</li>
637 <p>Here's some example code:</p>
638 <pre><code>return shell_exec("echo $input | $markdown_script");
642 var res
= test
.md_to_html
.write_to_string
646 fun test_process_nesting2
do
648 * A list item with a blockquote:
650 > This is a blockquote
651 > inside a list item.
655 <li><p>A list item with a blockquote:</p>
657 <p>This is a blockquote
658 inside a list item.</p>
663 var res
= test
.md_to_html
.write_to_string
667 fun test_process_nesting3
do
669 * A list item with a code block:
675 <li><p>A list item with a code block:</p>
676 <pre><code><code goes here>
681 var res
= test
.md_to_html
.write_to_string
685 fun test_process_nesting4
do
702 var res
= test
.md_to_html
.write_to_string
707 # fun test_process_nesting5 do
725 # var res = test.md_to_html.write_to_string
729 fun test_process_emph1
do
737 __double underscores__
739 var exp
= """<p><em>single asterisks</em></p>
740 <p><em>single underscores</em></p>
741 <p><strong>double asterisks</strong></p>
742 <p><strong>double underscores</strong></p>
744 var res
= test
.md_to_html
.write_to_string
748 fun test_process_emph2
do
749 var test
= "un*frigging*believable"
750 var exp
= "<p>un<em>frigging</em>believable</p>\n"
751 var res
= test
.md_to_html
.write_to_string
755 fun test_process_emph3
do
756 var proc
= new MarkdownProcessor
757 proc
.ext_mode
= false
758 var test
= "Con_cat_this"
759 var exp
= "<p>Con<em>cat</em>this</p>\n"
760 var res
= proc
.process
(test
).write_to_string
764 fun test_process_emph_ext
do
765 var test
= "Con_cat_this"
766 var exp
= "<p>Con_cat_this</p>\n"
767 var res
= test
.md_to_html
.write_to_string
771 fun test_process_xml1
do
773 This is a regular paragraph.
781 This is another regular paragraph.
784 <p>This is a regular paragraph.</p>
790 <p>This is another regular paragraph.</p>
792 var res
= test
.md_to_html
.write_to_string
796 fun test_process_xml2
do
798 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
800 var exp
= """<p>This is an image <img src="foo/bar" alt="baz" /> in a regular paragraph.</p>
802 var res
= test
.md_to_html
.write_to_string
806 fun test_process_xml3
do
813 var res
= test
.md_to_html
.write_to_string
817 fun test_process_xml4
do
819 <p>This is an example of a block element that should be escaped.</p>
820 <p>Idem for the second paragraph.</p>
823 var res
= test
.md_to_html
.write_to_string
827 fun test_process_xml5
do
829 # Some more XML tests
831 <p>This is an example of a block element that should be escaped.</p>
832 <p>Idem for the second paragraph.</p>
834 With a *md paragraph*!
837 <h1 id="Some_more_XML_tests">Some more XML tests</h1>
838 <p>This is an example of a block element that should be escaped.</p>
839 <p>Idem for the second paragraph.</p>
840 <p>With a <em>md paragraph</em>!</p>
842 var res
= test
.md_to_html
.write_to_string
847 fun test_process_span_code1
do
848 var test
= "Use the `printf()` function."
849 var exp
= "<p>Use the <code>printf()</code> function.</p>\n"
850 var res
= test
.md_to_html
.write_to_string
854 fun test_process_span_code2
do
855 var test
= "``There is a literal backtick (`) here.``"
856 var exp
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
857 var res
= test
.md_to_html
.write_to_string
861 fun test_process_span_code3
do
863 A single backtick in a code span: `` ` ``
865 A backtick-delimited string in a code span: `` `foo` ``
868 <p>A single backtick in a code span: <code>`</code></p>
869 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
871 var res
= test
.md_to_html
.write_to_string
875 fun test_process_span_code4
do
876 var test
= "Please don't use any `<blink>` tags."
877 var exp
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
878 var res
= test
.md_to_html
.write_to_string
882 fun test_process_span_code5
do
883 var test
= "`—` is the decimal-encoded equivalent of `—`."
884 var exp
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
885 var res
= test
.md_to_html
.write_to_string
889 fun test_process_escape1
do
890 var test
= "\\*this text is surrounded by literal asterisks\\*"
891 var exp
= "<p>*this text is surrounded by literal asterisks*</p>\n"
892 var res
= test
.md_to_html
.write_to_string
896 fun test_process_escape2
do
897 var test
= "1986\\. What a great season."
898 var exp
= "<p>1986. What a great season.</p>\n"
899 var res
= test
.md_to_html
.write_to_string
903 fun test_process_escape3
do
904 var test
= "Ben & Lux"
905 var exp
= "<p>Ben & Lux</p>\n"
906 var res
= test
.md_to_html
.write_to_string
910 fun test_process_link1
do
912 This is [an example](http://example.com/ "Title") inline link.
914 [This link](http://example.net/) has no title attribute.
916 var exp
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
917 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
919 var res
= test
.md_to_html
.write_to_string
923 fun test_process_link2
do
924 var test
= "See my [About](/about/) page for details."
925 var exp
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
926 var res
= test
.md_to_html
.write_to_string
930 fun test_process_link3
do
932 This is [an example][id] reference-style link.
934 This is [an example] [id] reference-style link.
938 [id]: http://example.com/ "Optional Title Here"
943 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
944 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
945 <p>Some lorem ipsum</p>
946 <p>Some other lipsum</p>
948 var res
= test
.md_to_html
.write_to_string
952 fun test_process_link4
do
954 This is multiple examples: [foo][1], [bar][2], [baz][3].
956 [1]: http://example.com/ "Optional Title Here"
957 [2]: http://example.com/ 'Optional Title Here'
958 [3]: http://example.com/ (Optional Title Here)
961 <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>
963 var res
= test
.md_to_html
.write_to_string
967 fun test_process_link5
do
969 This is multiple examples: [foo][a], [bar][A], [a].
971 [a]: http://example.com/ "Optional Title Here"
973 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>
975 var res
= test
.md_to_html
.write_to_string
979 fun test_process_link6
do
981 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
983 [Google]: http://google.com/ "Google"
984 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
985 [MSN]: http://search.msn.com/ "MSN Search"
987 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>
989 var res
= test
.md_to_html
.write_to_string
993 fun test_process_link7
do
995 Visit [Daring Fireball][] for more information.
997 [Daring Fireball]: http://daringfireball.net/
999 var exp
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
1001 var res
= test
.md_to_html
.write_to_string
1005 fun test_process_link8
do
1007 This one has a [line
1010 This one has a [line
1011 break] with a line-ending space.
1016 <p>This one has a <a href="/foo">line
1018 <p>This one has a <a href="/foo">line
1019 break</a> with a line-ending space.</p>
1021 var res
= test
.md_to_html
.write_to_string
1025 # FIXME unignore test once escape strings fixed
1026 # fun test_process_link9 do
1030 # Foo [bar](/url/ "Title with \"quotes\" inside").
1033 # [bar]: /url/ "Title with \"quotes\" inside"
1036 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1037 # <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
1039 # var res = test.md_to_html.write_to_string
1043 fun test_process_img1
do
1045 ![Alt text](/path/to/img.jpg)
1047 ![Alt text](/path/to/img.jpg "Optional title")
1049 var exp
= """<p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1050 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1052 var res
= test
.md_to_html
.write_to_string
1056 fun test_process_img2
do
1060 [id]: url/to/image "Optional title attribute"
1062 var exp
= """<p><img src="url/to/image" alt="Alt text" title="Optional title attribute"/></p>
1064 var res
= test
.md_to_html
.write_to_string
1068 fun test_process_strike
do
1069 var proc
= new MarkdownProcessor
1070 proc
.ext_mode
= false
1071 var test
= "This is how you ~~strike text~~"
1072 var exp
= "<p>This is how you ~~strike text~~</p>\n"
1073 var res
= proc
.process
(test
).write_to_string
1077 fun test_process_strike_ext
do
1078 var test
= "This is how you ~~strike text~~"
1079 var exp
= "<p>This is how you <del>strike text</del></p>\n"
1080 var res
= test
.md_to_html
.write_to_string
1084 fun test_escape_bad_html
do
1085 var test
= "-1 if < , +1 if > and 0 otherwise"
1086 var exp
= "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
1087 var res
= test
.md_to_html
.write_to_string
1091 fun test_daring_encoding
do
1093 AT&T has an ampersand in their name.
1095 AT&T is another way to write it.
1103 Here's a [link] [1] with an ampersand in the URL.
1105 Here's a link with an amersand in the link text: [AT&T] [2].
1107 Here's an inline [link](/script?foo=1&bar=2).
1109 Here's an inline [link](</script?foo=1&bar=2>).
1112 [1]: http://example.com/?foo=1&bar=2
1113 [2]: http://att.com/ "AT&T"
1117 <p>AT&T has an ampersand in their name.</p>
1118 <p>AT&T is another way to write it.</p>
1119 <p>This & that.</p>
1122 <p>Here's a <a href="http://example.com/?foo=1&bar=2">link</a> with an ampersand in the URL.</p>
1123 <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&T">AT&T</a>.</p>
1124 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1125 <p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
1127 var res
= test
.md_to_html
.write_to_string
1132 fun test_daring_autolinks
do
1134 Link: <http://example.com/>.
1136 With an ampersand: <http://example.com/?foo=1&bar=2>
1139 * <http://example.com/>
1142 > Blockquoted: <http://example.com/>
1144 Auto-links should not occur here: `<http://example.com/>`
1146 or here: <http://example.com/>
1150 <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
1151 <p>With an ampersand: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a></p>
1154 <li><a href="http://example.com/">http://example.com/</a></li>
1158 <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
1160 <p>Auto-links should not occur here: <code><http://example.com/></code></p>
1161 <pre><code>or here: <http://example.com/>
1164 var res
= test
.md_to_html
.write_to_string
1168 fun test_daring_escape
do
1170 These should all get escaped:
1205 These should not, because they occur within a code block:
1239 Nor should these, which occur in code spans:
1273 These should get escaped, even though they're matching pairs for
1274 other Markdown constructs:
1282 This is a code span with a literal backslash-backtick sequence: `` \` ``
1284 This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.
1286 This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.
1289 <p>These should all get escaped:</p>
1290 <p>Backslash: \\</p>
1293 <p>Underscore: \_</p>
1294 <p>Left brace: \{</p>
1295 <p>Right brace: \}</p>
1296 <p>Left bracket: \[</p>
1297 <p>Right bracket: \]</p>
1298 <p>Left paren: \(</p>
1299 <p>Right paren: \)</p>
1300 <p>Greater-than: \></p>
1306 <p>These should not, because they occur within a code block:</p>
1307 <pre><code>Backslash: \\
1339 <p>Nor should these, which occur in code spans:</p>
1340 <p>Backslash: <code>\\</code></p>
1341 <p>Backtick: <code>\`</code></p>
1342 <p>Asterisk: <code>\*</code></p>
1343 <p>Underscore: <code>\_</code></p>
1344 <p>Left brace: <code>\{</code></p>
1345 <p>Right brace: <code>\}</code></p>
1346 <p>Left bracket: <code>\[</code></p>
1347 <p>Right bracket: <code>\]</code></p>
1348 <p>Left paren: <code>\(</code></p>
1349 <p>Right paren: <code>\)</code></p>
1350 <p>Greater-than: <code>\></code></p>
1351 <p>Hash: <code>\#</code></p>
1352 <p>Period: <code>\.</code></p>
1353 <p>Bang: <code>\!</code></p>
1354 <p>Plus: <code>\+</code></p>
1355 <p>Minus: <code>\-</code></p>
1356 <p>These should get escaped, even though they're matching pairs for
1357 other Markdown constructs:</p>
1359 <p>_underscores_</p>
1361 <p>This is a code span with a literal backslash-backtick sequence: <code>\`</code></p>
1362 <p>This is a tag with unescaped backticks <span attr='`ticks`'>bar</span>.</p>
1363 <p>This is a tag with backslashes <span attr='\\\\backslashes\\\\'>bar</span>.</p>
1366 var res
= test
.md_to_html
.write_to_string
1370 fun test_daring_blockquotes
do
1388 <pre><code>sub status {
1393 <pre><code>sub status {
1399 var res
= test
.md_to_html
.write_to_string
1403 fun test_daring_code_blocks
do
1405 code block on the first line
1409 code block indented by spaces
1413 the lines in this block
1414 all contain trailing spaces
1418 code block on the last line
1422 <pre><code>code block on the first line
1424 <p>Regular text.</p>
1425 <pre><code>code block indented by spaces
1427 <p>Regular text.</p>
1428 <pre><code>the lines in this block
1429 all contain trailing spaces
1431 <p>Regular Text.</p>
1432 <pre><code>code block on the last line
1435 var res
= test
.md_to_html
.write_to_string
1439 fun test_daring_code_spans
do
1441 `<test a="` content of attribute `">`
1443 Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
1445 Here's how you put `` `backticks` `` in a code span.
1449 <p><code><test a="</code> content of attribute <code>"></code></p>
1450 <p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
1451 <p>Here's how you put <code>`backticks`</code> in a code span.</p>
1453 var res
= test
.md_to_html
.write_to_string
1457 fun test_daring_pars
do
1458 var proc
= new MarkdownProcessor
1459 proc
.ext_mode
= false
1462 In Markdown 1.0.0 and earlier. Version
1463 8. This line turns into a list item.
1464 Because a hard-wrapped line in the
1465 middle of a paragraph looked like a
1468 Here's one with a bullet.
1473 <p>In Markdown 1.0.0 and earlier. Version
1474 8. This line turns into a list item.
1475 Because a hard-wrapped line in the
1476 middle of a paragraph looked like a
1478 <p>Here's one with a bullet.
1481 var res
= proc
.process
(test
).write_to_string
1485 fun test_daring_rules
do
1597 var res
= test
.md_to_html
.write_to_string
1601 fun test_daring_images
do
1603 ![Alt text](/path/to/img.jpg)
1605 ![Alt text](/path/to/img.jpg "Optional title")
1607 Inline within a paragraph: [alt text](/url/).
1609 ![alt text](/url/ "title preceded by two spaces")
1611 ![alt text](/url/ "title has spaces afterward" )
1613 ![alt text](</url/>)
1615 ![alt text](</url/> "with a title").
1619 ![this is a stupid URL](http://example.com/(parens).jpg)
1628 [bar]: /url/ "Title here"
1632 <p><img src="/path/to/img.jpg" alt="Alt text"/></p>
1633 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title"/></p>
1634 <p>Inline within a paragraph: <a href="/url/">alt text</a>.</p>
1635 <p><img src="/url/" alt="alt text" title="title preceded by two spaces"/></p>
1636 <p><img src="/url/" alt="alt text" title="title has spaces afterward"/></p>
1637 <p><img src="/url/" alt="alt text"/></p>
1638 <p><img src="/url/" alt="alt text" title="with a title"/>.</p>
1639 <p><img src="" alt="Empty"/></p>
1640 <p><img src="http://example.com/(parens).jpg" alt="this is a stupid URL"/></p>
1641 <p><img src="/url/" alt="alt text"/></p>
1642 <p><img src="/url/" alt="alt text" title="Title here"/></p>
1644 var res
= test
.md_to_html
.write_to_string
1648 fun test_daring_inline_html1
do
1650 Here's a simple block:
1656 This should be a code block, though:
1676 This should just be an HTML comment:
1691 Just plain comment, with trailing spaces on the line:
1713 <hr class="foo" id="bar" />
1715 <hr class="foo" id="bar"/>
1717 <hr class="foo" id="bar" >
1721 <p>Here's a simple block:</p>
1725 <p>This should be a code block, though:</p>
1726 <pre><code><div>
1730 <p>As should this:</p>
1731 <pre><code><div>foo</div>
1741 <p>This should just be an HTML comment:</p>
1749 <pre><code><!-- Comment -->
1751 <p>Just plain comment, with trailing spaces on the line:</p>
1754 <pre><code><hr />
1763 <hr class="foo" id="bar" />
1764 <hr class="foo" id="bar"/>
1765 <hr class="foo" id="bar" >
1767 var res
= test
.md_to_html
.write_to_string
1771 fun test_daring_inline_html2
do
1773 Simple block on one line:
1777 And nested without indentation:
1789 And with attributes:
1796 This was broken in 1.0.2b7:
1798 <div class="inlinepage">
1799 <div class="toggleableend">
1806 <p>Simple block on one line:</p>
1808 <p>And nested without indentation:</p>
1818 <p>And with attributes:</p>
1823 <p>This was broken in 1.0.2b7:</p>
1824 <div class="inlinepage">
1825 <div class="toggleableend">
1830 var res
= test
.md_to_html
.write_to_string
1834 fun test_daring_inline_html3
do
1838 <!-- This is a simple comment -->
1841 This is another comment.
1846 <!-- one comment block -- -- with two comments -->
1852 <p>Paragraph one.</p>
1853 <!-- This is a simple comment -->
1855 This is another comment.
1857 <p>Paragraph two.</p>
1858 <!-- one comment block -- -- with two comments -->
1861 var res
= test
.md_to_html
.write_to_string
1865 fun test_daring_links1
do
1867 Just a [URL](/url/).
1869 [URL and title](/url/ "title").
1871 [URL and title](/url/ "title preceded by two spaces").
1873 [URL and title](/url/ "title preceded by a tab").
1875 [URL and title](/url/ "title has spaces afterward" ).
1877 [URL wrapped in angle brackets](</url/>).
1879 [URL w/ angle brackets + title](</url/> "Here's the title").
1883 [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing))
1885 (With outer parens and [parens in url](/foo(bar)))
1888 [With parens in the URL](/foo(bar) "and a title")
1890 (With outer parens and [parens in url](/foo(bar) "and a title"))
1894 <p>Just a <a href="/url/">URL</a>.</p>
1895 <p><a href="/url/" title="title">URL and title</a>.</p>
1896 <p><a href="/url/" title="title preceded by two spaces">URL and title</a>.</p>
1897 <p><a href="/url/" title="title preceded by a tab">URL and title</a>.</p>
1898 <p><a href="/url/" title="title has spaces afterward">URL and title</a>.</p>
1899 <p><a href="/url/">URL wrapped in angle brackets</a>.</p>
1900 <p><a href="/url/" title="Here's the title">URL w/ angle brackets + title</a>.</p>
1901 <p><a href="">Empty</a>.</p>
1902 <p><a href="http://en.wikipedia.org/wiki/WIMP_(computing)">With parens in the URL</a></p>
1903 <p>(With outer parens and <a href="/foo(bar)">parens in url</a>)</p>
1904 <p><a href="/foo(bar)" title="and a title">With parens in the URL</a></p>
1905 <p>(With outer parens and <a href="/foo(bar)" title="and a title">parens in url</a>)</p>
1907 var res
= test
.md_to_html
.write_to_string
1911 fun test_daring_links2
do
1923 With [embedded [brackets]] [b].
1930 Indented [thrice][].
1932 Indented [four][] times.
1947 [this] [this] should work
1949 So should [this][this].
1963 [Something in brackets like [this][] should work]
1967 In this case, [this](/somethingelse/) points to something else.
1969 Backslashing should suppress \\\[this] and [this\\\].
1976 Here's one where the [link
1977 breaks] across lines.
1979 Here's another where the [link
1980 breaks] across lines, but with a line-ending space.
1983 [link breaks]: /url/
1987 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1988 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1989 <p>Foo <a href="/url/" title="Title">bar</a>.</p>
1990 <p>With <a href="/url/">embedded [brackets]</a>.</p>
1991 <p>Indented <a href="/url">once</a>.</p>
1992 <p>Indented <a href="/url">twice</a>.</p>
1993 <p>Indented <a href="/url">thrice</a>.</p>
1994 <p>Indented [four][] times.</p>
1995 <pre><code>[four]: /url
1998 <p><a href="foo">this</a> should work</p>
1999 <p>So should <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>And <a href="foo">this</a>.</p>
2003 <p>But not [that] [].</p>
2004 <p>Nor [that][].</p>
2006 <p>[Something in brackets like <a href="foo">this</a> should work]</p>
2007 <p>[Same with <a href="foo">this</a>.]</p>
2008 <p>In this case, <a href="/somethingelse/">this</a> points to something else.</p>
2009 <p>Backslashing should suppress [this] and [this].</p>
2011 <p>Here's one where the <a href="/url/">link
2012 breaks</a> across lines.</p>
2013 <p>Here's another where the <a href="/url/">link
2014 breaks</a> across lines, but with a line-ending space.</p>
2016 var res
= test
.md_to_html
.write_to_string
2020 fun test_daring_links3
do
2022 This is the [simple case].
2024 [simple case]: /simple
2028 This one has a [line
2031 This one has a [line
2032 break] with a line-ending space.
2037 [this] [that] and the [other]
2045 <p>This is the <a href="/simple">simple case</a>.</p>
2046 <p>This one has a <a href="/foo">line
2048 <p>This one has a <a href="/foo">line
2049 break</a> with a line-ending space.</p>
2050 <p><a href="/that">this</a> and the <a href="/other">other</a></p>
2052 var res
= test
.md_to_html
.write_to_string
2056 fun test_daring_nested
do
2074 var res
= test
.md_to_html
.write_to_string
2078 fun test_daring_list
do
2164 Multiple paragraphs:
2166 1. Item 1, graf one.
2168 Item 2. graf two. The quick brown fox jumped over the lazy dog's
2192 Same thing but with paragraphs:
2205 <h2 id="Unordered">Unordered</h2>
2206 <p>Asterisks tight:</p>
2212 <p>Asterisks loose:</p>
2214 <li><p>asterisk 1</p>
2216 <li><p>asterisk 2</p>
2218 <li><p>asterisk 3</p>
2222 <p>Pluses tight:</p>
2228 <p>Pluses loose:</p>
2238 <p>Minuses tight:</p>
2244 <p>Minuses loose:</p>
2253 <h2 id="Ordered">Ordered</h2>
2266 <p>Loose using tabs:</p>
2275 <p>and using spaces:</p>
2284 <p>Multiple paragraphs:</p>
2286 <li><p>Item 1, graf one.</p>
2287 <p>Item 2. graf two. The quick brown fox jumped over the lazy dog's
2295 <h2 id="Nested">Nested</h2>
2305 <p>Here's another:</p>
2316 <p>Same thing but with paragraphs:</p>
2331 var res
= test
.md_to_html
.write_to_string
2335 fun test_daring_strong_em
do
2337 ***This is strong and em.***
2339 So is ***this*** word.
2341 ___This is strong and em.___
2343 So is ___this___ word.
2347 <p><strong><em>This is strong and em.</em></strong></p>
2348 <p>So is <strong><em>this</em></strong> word.</p>
2349 <p><strong><em>This is strong and em.</em></strong></p>
2350 <p>So is <strong><em>this</em></strong> word.</p>
2352 var res
= test
.md_to_html
.write_to_string
2356 fun test_daring_tabs
do
2358 + this is a list item
2361 + this is a list item
2362 indented with spaces
2366 this code block is indented by one tab
2370 this code block is indented by two tabs
2374 + this is an example list item
2377 + this is an example list item
2378 indented with spaces
2383 <li><p>this is a list item
2384 indented with tabs</p>
2386 <li><p>this is a list item
2387 indented with spaces</p>
2391 <pre><code>this code block is indented by one tab
2394 <pre><code> this code block is indented by two tabs
2397 <pre><code>+ this is an example list item
2400 + this is an example list item
2401 indented with spaces
2404 var res
= test
.md_to_html
.write_to_string
2408 fun test_daring_tidyness
do
2410 > A list within a blockquote:
2419 <p>A list within a blockquote:</p>
2427 var res
= test
.md_to_html
.write_to_string
2437 # A dummy location for testing purposes.
2438 var loc
= new MDLocation(0, 0, 0, 0)
2440 fun test_has_blocks
do
2441 var subject
= new MDBlock(loc
)
2442 assert not subject
.has_blocks
2443 subject
.first_block
= new MDBlock(loc
)
2444 assert subject
.has_blocks
2447 fun test_count_blocks
do
2448 var subject
= new MDBlock(loc
)
2449 assert subject
.count_blocks
== 0
2450 subject
.first_block
= new MDBlock(loc
)
2451 assert subject
.count_blocks
== 1
2452 subject
.first_block
.next
= new MDBlock(loc
)
2453 assert subject
.count_blocks
== 2
2456 fun test_has_lines
do
2457 var subject
= new MDBlock(loc
)
2458 assert not subject
.has_lines
2459 subject
.first_line
= new MDLine(loc
, "")
2460 assert subject
.has_lines
2463 fun test_count_lines
do
2464 var subject
= new MDBlock(loc
)
2465 assert subject
.count_lines
== 0
2466 subject
.first_line
= new MDLine(loc
, "")
2467 assert subject
.count_lines
== 1
2468 subject
.first_line
.next
= new MDLine(loc
, "")
2469 assert subject
.count_lines
== 2
2473 var line1
= new MDLine(loc
, "line1")
2474 var line2
= new MDLine(loc
, "line2")
2475 var line3
= new MDLine(loc
, "line3")
2476 var subject
= new MDBlock(loc
)
2477 subject
.add_line line1
2478 subject
.add_line line2
2479 subject
.add_line line3
2480 var block
= subject
.split
(line2
)
2481 assert subject
.count_blocks
== 1
2482 assert subject
.count_lines
== 1
2483 assert subject
.first_line
== line3
2484 assert block
.count_blocks
== 0
2485 assert block
.count_lines
== 2
2486 assert block
.first_line
== line1
2487 assert block
.last_line
== line2
2490 fun test_add_line
do
2491 var subject
= new MDBlock(loc
)
2492 assert subject
.count_lines
== 0
2493 subject
.add_line
new MDLine(loc
, "")
2494 assert subject
.count_lines
== 1
2495 subject
.add_line
new MDLine(loc
, "")
2496 assert subject
.count_lines
== 2
2499 fun test_remove_line
do
2500 var line1
= new MDLine(loc
, "line1")
2501 var line2
= new MDLine(loc
, "line2")
2502 var line3
= new MDLine(loc
, "line3")
2503 var subject
= new MDBlock(loc
)
2504 subject
.add_line line1
2505 subject
.add_line line2
2506 subject
.add_line line3
2507 subject
.remove_line
(line2
)
2508 assert subject
.count_lines
== 2
2509 subject
.remove_line
(line1
)
2510 assert subject
.count_lines
== 1
2511 assert subject
.first_line
== line3
2512 assert subject
.last_line
== line3
2515 fun test_transform_headline1
do
2516 var subject
= new MDBlock(loc
)
2517 var kind
= new BlockHeadline(subject
)
2518 subject
.add_line
new MDLine(loc
, " # Title 1 ")
2519 kind
.transform_headline
(subject
)
2520 assert kind
.depth
== 1
2521 assert subject
.first_line
.value
== "Title 1"
2524 fun test_transform_headline2
do
2525 var subject
= new MDBlock(loc
)
2526 var kind
= new BlockHeadline(subject
)
2527 subject
.add_line
new MDLine(loc
, " #####Title 5 ")
2528 kind
.transform_headline
(subject
)
2529 assert kind
.depth
== 5
2530 assert subject
.first_line
.value
== "Title 5"
2533 fun test_remove_quote_prefix
do
2534 var subject
= new MDBlock(loc
)
2535 var kind
= new BlockQuote(subject
)
2536 subject
.add_line
new MDLine(loc
, " > line 1")
2537 subject
.add_line
new MDLine(loc
, " > line 2")
2538 subject
.add_line
new MDLine(loc
, " > line 3")
2539 kind
.remove_block_quote_prefix
(subject
)
2540 assert subject
.first_line
.value
== "line 1"
2541 assert subject
.first_line
.next
.value
== "line 2"
2542 assert subject
.first_line
.next
.next
.value
== "line 3"
2545 fun test_remove_leading_empty_lines_1
do
2546 var block
= new MDBlock(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
, "")
2551 block
.add_line
new MDLine(loc
, " text")
2552 block
.add_line
new MDLine(loc
, "")
2553 assert block
.remove_leading_empty_lines
2554 assert block
.first_line
.value
== " text"
2557 fun test_remove_leading_empty_lines_2
do
2558 var block
= new MDBlock(loc
)
2559 block
.add_line
new MDLine(loc
, " text")
2560 block
.remove_leading_empty_lines
2561 assert block
.first_line
.value
== " text"
2564 fun test_remove_trailing_empty_lines_1
do
2565 var block
= new MDBlock(loc
)
2566 block
.add_line
new MDLine(loc
, "")
2567 block
.add_line
new MDLine(loc
, "text")
2568 block
.add_line
new MDLine(loc
, "")
2569 block
.add_line
new MDLine(loc
, "")
2570 block
.add_line
new MDLine(loc
, "")
2571 block
.add_line
new MDLine(loc
, "")
2572 assert block
.remove_trailing_empty_lines
2573 assert block
.last_line
.value
== "text"
2576 fun test_remove_trailing_empty_lines_2
do
2577 var block
= new MDBlock(loc
)
2578 block
.add_line
new MDLine(loc
, "text ")
2579 assert not block
.remove_trailing_empty_lines
2580 assert block
.last_line
.value
== "text "
2583 fun test_remove_surrounding_empty_lines
do
2584 var block
= new MDBlock(loc
)
2585 block
.add_line
new MDLine(loc
, "")
2586 block
.add_line
new MDLine(loc
, "text")
2587 block
.add_line
new MDLine(loc
, "")
2588 block
.add_line
new MDLine(loc
, "")
2589 block
.add_line
new MDLine(loc
, "")
2590 block
.add_line
new MDLine(loc
, "")
2591 assert block
.remove_surrounding_empty_lines
2592 assert block
.first_line
.value
== "text"
2593 assert block
.last_line
.value
== "text"
2600 # A dummy location for testing purposes.
2601 var loc
= new MDLocation(0, 0, 0, 0)
2605 fun test_is_empty
do
2606 subject
= new MDLine(loc
, "")
2607 assert subject
.is_empty
2608 subject
= new MDLine(loc
, " ")
2609 assert subject
.is_empty
2610 subject
= new MDLine(loc
, "test")
2611 assert not subject
.is_empty
2612 subject
= new MDLine(loc
, " test")
2613 assert not subject
.is_empty
2617 subject
= new MDLine(loc
, "")
2618 assert subject
.leading
== 0
2619 subject
= new MDLine(loc
, " ")
2620 assert subject
.leading
== 4
2621 subject
= new MDLine(loc
, "test")
2622 assert subject
.leading
== 0
2623 subject
= new MDLine(loc
, " test")
2624 assert subject
.leading
== 4
2627 fun test_trailing
do
2628 subject
= new MDLine(loc
, "")
2629 assert subject
.trailing
== 0
2630 subject
= new MDLine(loc
, " ")
2631 assert subject
.trailing
== 0
2632 subject
= new MDLine(loc
, "test ")
2633 assert subject
.trailing
== 3
2634 subject
= new MDLine(loc
, " test ")
2635 assert subject
.trailing
== 1
2638 fun test_line_type
do
2639 var v
= new MarkdownProcessor
2640 subject
= new MDLine(loc
, "")
2641 assert v
.line_kind
(subject
) isa LineEmpty
2642 subject
= new MDLine(loc
, " ")
2643 assert v
.line_kind
(subject
) isa LineEmpty
2644 subject
= new MDLine(loc
, "text ")
2645 assert v
.line_kind
(subject
) isa LineOther
2646 subject
= new MDLine(loc
, " # Title")
2647 assert v
.line_kind
(subject
) isa LineHeadline
2648 subject
= new MDLine(loc
, " ### Title")
2649 assert v
.line_kind
(subject
) isa LineHeadline
2650 subject
= new MDLine(loc
, " code")
2651 assert v
.line_kind
(subject
) isa LineCode
2652 subject
= new MDLine(loc
, " Title ")
2653 subject
.next
= new MDLine(loc
, "== ")
2654 assert v
.line_kind
(subject
) isa LineHeadline1
2655 subject
= new MDLine(loc
, " Title ")
2656 subject
.next
= new MDLine(loc
, "-- ")
2657 assert v
.line_kind
(subject
) isa LineHeadline2
2658 subject
= new MDLine(loc
, " * * * ")
2659 assert v
.line_kind
(subject
) isa LineHR
2660 subject
= new MDLine(loc
, " *** ")
2661 assert v
.line_kind
(subject
) isa LineHR
2662 subject
= new MDLine(loc
, "- -- ")
2663 assert v
.line_kind
(subject
) isa LineHR
2664 subject
= new MDLine(loc
, "--------- ")
2665 assert v
.line_kind
(subject
) isa LineHR
2666 subject
= new MDLine(loc
, " >")
2667 assert v
.line_kind
(subject
) isa LineBlockquote
2668 subject
= new MDLine(loc
, "<p></p>")
2669 assert v
.line_kind
(subject
) isa LineXML
2670 subject
= new MDLine(loc
, "<p>")
2671 assert v
.line_kind
(subject
) isa LineOther
2672 subject
= new MDLine(loc
, " * foo")
2673 assert v
.line_kind
(subject
) isa LineUList
2674 subject
= new MDLine(loc
, "- foo")
2675 assert v
.line_kind
(subject
) isa LineUList
2676 subject
= new MDLine(loc
, "+ foo")
2677 assert v
.line_kind
(subject
) isa LineUList
2678 subject
= new MDLine(loc
, "1. foo")
2679 assert v
.line_kind
(subject
) isa LineOList
2680 subject
= new MDLine(loc
, " 11111. foo")
2681 assert v
.line_kind
(subject
) isa LineOList
2684 fun test_line_type_ext
do
2685 var v
= new MarkdownProcessor
2686 subject
= new MDLine(loc
, " ~~~")
2687 assert v
.line_kind
(subject
) isa LineFence
2688 subject
= new MDLine(loc
, " ```")
2689 assert v
.line_kind
(subject
) isa LineFence
2690 subject
= new MDLine(loc
, "~~~raw")
2691 assert v
.line_kind
(subject
) isa LineFence
2694 fun test_count_chars
do
2695 subject
= new MDLine(loc
, "")
2696 assert subject
.count_chars
('*') == 0
2697 subject
= new MDLine(loc
, "* ")
2698 assert subject
.count_chars
('*') == 1
2699 subject
= new MDLine(loc
, " * text")
2700 assert subject
.count_chars
('*') == 0
2701 subject
= new MDLine(loc
, " * * *")
2702 assert subject
.count_chars
('*') == 3
2703 subject
= new MDLine(loc
, "text ** ")
2704 assert subject
.count_chars
('*') == 0
2707 fun test_count_chars_start
do
2708 subject
= new MDLine(loc
, "")
2709 assert subject
.count_chars_start
('*') == 0
2710 subject
= new MDLine(loc
, "* ")
2711 assert subject
.count_chars_start
('*') == 1
2712 subject
= new MDLine(loc
, " * text")
2713 assert subject
.count_chars_start
('*') == 1
2714 subject
= new MDLine(loc
, " * * * text")
2715 assert subject
.count_chars_start
('*') == 3
2716 subject
= new MDLine(loc
, "text ** ")
2717 assert subject
.count_chars_start
('*') == 0
2721 class TestHTMLDecorator
2724 fun test_headlines
do
2738 var proc
= new MarkdownProcessor
2739 var decorator
= proc
.emitter
.decorator
.as(HTMLDecorator)
2742 for id
, headline
in decorator
.headlines
do
2743 res
+= "{headline.title}:{id}\n"
2762 class TestTokenLocation
2765 fun test_token_location1
do
2766 var string
= "**Hello** `World`"
2768 "TokenStrongStar at 1,1--1,1",
2769 "TokenStrongStar at 1,8--1,8",
2770 "TokenCodeSingle at 1,11--1,11",
2771 "TokenCodeSingle at 1,17--1,17"]
2772 (new TestTokenProcessor(stack
)).process
(string
)
2775 fun test_token_location2
do
2776 var string
= "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
2778 "TokenStrongStar at 1,1--1,1",
2779 "TokenStrongStar at 1,8--1,8",
2780 "TokenCodeSingle at 2,1--2,1",
2781 "TokenCodeSingle at 2,7--2,7",
2782 "TokenEmStar at 3,1--3,1",
2783 "TokenEmStar at 3,9--3,9",
2784 "TokenLink at 4,1--4,1"]
2785 (new TestTokenProcessor(stack
)).process
(string
)
2788 fun test_token_location3
do
2789 var string
= """**Hello**
2794 "TokenStrongStar at 1,1--1,1",
2795 "TokenStrongStar at 1,8--1,8",
2796 "TokenCodeSingle at 2,1--2,1",
2797 "TokenCodeSingle at 2,7--2,7",
2798 "TokenEmStar at 3,1--3,1",
2799 "TokenEmStar at 3,9--3,9",
2800 "TokenLink at 4,1--4,1"]
2801 (new TestTokenProcessor(stack
)).process
(string
)
2804 fun test_token_location4
do
2805 var string
= "**Hello**\n\n`World`"
2807 "TokenStrongStar at 1,1--1,1",
2808 "TokenStrongStar at 1,8--1,8",
2809 "TokenCodeSingle at 3,1--3,1",
2810 "TokenCodeSingle at 3,7--3,7"]
2811 (new TestTokenProcessor(stack
)).process
(string
)
2814 fun test_token_location5
do
2815 var string
= "# *Title1*\n\n# *Title2*"
2817 "TokenEmStar at 1,3--1,3",
2818 "TokenEmStar at 1,10--1,10",
2819 "TokenEmStar at 3,3--3,3",
2820 "TokenEmStar at 3,10--3,10"]
2821 (new TestTokenProcessor(stack
)).process
(string
)
2825 class TestTokenProcessor
2826 super MarkdownProcessor
2828 var test_stack
: Array[String]
2830 redef fun token_at
(input
, pos
) do
2832 if token
isa TokenNone then return token
2833 var res
= "{token.class_name} at {token.location or else "?"}"
2834 var exp
= test_stack
.shift
2843 class TestBlockLocation
2846 var proc
= new MarkdownProcessor
2848 fun test_block_location1
do
2850 "BlockHeadline: 1,1--1,8",
2851 "BlockListItem: 2,1--2,6",
2852 "BlockListItem: 3,1--3,5"
2855 "# Title\n* li1\n* li2"
2856 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2857 proc
.process
(string
)
2860 fun test_block_location2
do
2862 "BlockHeadline: 1,1--1,11",
2863 "BlockFence: 3,1--5,4",
2864 "BlockListItem: 7,1--7,7",
2865 "BlockListItem: 8,1--8,6"]
2866 var string
="""#### Title
2874 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2875 proc
.process
(string
)
2878 fun test_block_location3
do
2880 "BlockHeadline: 1,1--1,8",
2881 "BlockHeadline: 3,1--3,10"]
2882 var string
="""# Title\n\n## Title 2"""
2883 proc
.emitter
.decorator
= new TestBlockDecorator(stack
)
2884 proc
.process
(string
)
2888 class TestBlockDecorator
2891 var stack
: Array[String]
2893 redef fun add_headline
(v
, block
) do
2898 redef fun add_listitem
(v
, block
) do
2903 redef fun add_blockquote
(v
, block
) do
2908 redef fun add_code
(v
, block
) do
2913 fun check_res
(block
: Block) do
2914 var res
= "{block.class_name}: {block.block.location}"
2915 var exp
= stack
.shift