1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either htmlress or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Test for markdown blocks parsing
16 module test_markdown_blocks
is test
20 class TestMarkdownBlocks
21 super TestMarkdownHtml
24 fun test_blocks_empty
is test
do
27 assert md_to_html
(md
) == html
30 fun test_blocks_tabs
is test
do
31 var md
= """\tsome code\n"""
32 var html
= """<pre><code>some code\n</code></pre>\n"""
33 assert md_to_html
(md
) == html
36 fun test_blocks_pagraph1
is test
do
38 var html
= "<p>test</p>\n"
39 assert md_to_html
(md
) == html
42 fun test_blocks_pagraph2
is test
do
43 var md
= """line1\nline2\n\nline3 line4\n\nline5\n"""
44 var html
= """<p>line1\nline2</p>\n<p>line3 line4</p>\n<p>line5</p>\n"""
45 assert md_to_html
(md
) == html
48 fun test_blocks_pagraph3
is test
do
50 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
51 Aliquam hendrerit mi posuere lectus.
52 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
54 Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
55 id sem consectetuer libero luctus adipiscing.
58 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
59 Aliquam hendrerit mi posuere lectus.
60 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
61 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
62 id sem consectetuer libero luctus adipiscing.</p>
64 assert md_to_html
(md
) == html
67 fun test_blocks_headings_1
is test
do
79 assert md_to_html
(md
) == html
82 fun test_blocks_headings_2
is test
do
94 assert md_to_html
(md
) == html
97 fun test_blocks_headings_3
is test
do
103 ### This is a H3 ######
106 <h1>This is a H1</h1>
107 <h2>This is a H2</h2>
108 <h3>This is a H3</h3>
110 assert md_to_html
(md
) == html
113 fun test_blocks_hr1
is test
do
123 ---------------------------------------
125 var html
= "<hr />\n<hr />\n<hr />\n<hr />\n<hr />\n"
126 assert md_to_html
(md
) == html
129 fun test_blocks_bquote1
is test
do
131 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
132 > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
133 > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
135 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
136 > id sem consectetuer libero luctus adipiscing.
138 var html
= """<blockquote>
139 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
140 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
141 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
142 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
143 id sem consectetuer libero luctus adipiscing.</p>
146 assert md_to_html
(md
) == html
149 fun test_blocks_bquote2
is test
do
151 > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
152 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
153 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
155 > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
156 id sem consectetuer libero luctus adipiscing.
158 var html
= """<blockquote>
159 <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
160 consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
161 Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
164 <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
165 id sem consectetuer libero luctus adipiscing.</p>
168 assert md_to_html
(md
) == html
171 fun test_blocks_bquote3
is test
do
173 > This is the first level of quoting.
175 > > This is nested blockquote.
177 > Back to the first level.
179 var html
= """<blockquote>
180 <p>This is the first level of quoting.</p>
182 <p>This is nested blockquote.</p>
184 <p>Back to the first level.</p>
187 assert md_to_html
(md
) == html
190 fun test_blocks_list1
is test
do
202 assert md_to_html
(md
) == html
205 fun test_blocks_list2
is test
do
217 assert md_to_html
(md
) == html
220 fun test_blocks_list3
is test
do
232 assert md_to_html
(md
) == html
235 fun test_blocks_list4
is test
do
247 assert md_to_html
(md
) == html
250 fun test_blocks_list5
is test
do
256 var html
= """<ol start=\"3\">
262 assert md_to_html
(md
) == html
265 fun test_blocks_list6
is test
do
267 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
268 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
269 viverra nec, fringilla in, laoreet vitae, risus.
270 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
271 Suspendisse id sem consectetuer libero luctus adipiscing.
275 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
276 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
277 viverra nec, fringilla in, laoreet vitae, risus.</li>
278 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
279 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
282 assert md_to_html
(md
) == html
285 fun test_blocks_list7
is test
do
287 * Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
288 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
289 viverra nec, fringilla in, laoreet vitae, risus.
290 * Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
291 Suspendisse id sem consectetuer libero luctus adipiscing.
295 <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
296 Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
297 viverra nec, fringilla in, laoreet vitae, risus.</li>
298 <li>Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
299 Suspendisse id sem consectetuer libero luctus adipiscing.</li>
302 assert md_to_html
(md
) == html
305 fun test_blocks_list8
is test
do
321 assert md_to_html
(md
) == html
324 fun test_blocks_list9
is test
do
326 1. This is a list item with two paragraphs. Lorem ipsum dolor
327 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
330 Vestibulum enim wisi, viverra nec, fringilla in, laoreet
331 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
334 2. Suspendisse id sem consectetuer libero luctus adipiscing.
339 <p>This is a list item with two paragraphs. Lorem ipsum dolor
340 sit amet, consectetuer adipiscing elit. Aliquam hendrerit
341 mi posuere lectus.</p>
342 <p>Vestibulum enim wisi, viverra nec, fringilla in, laoreet
343 vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
347 <p>Suspendisse id sem consectetuer libero luctus adipiscing.</p>
351 assert md_to_html
(md
) == html
354 fun test_blocks_list10
is test
do
356 * This is a list item with two paragraphs.
358 This is the second paragraph in the list item. You're
359 only required to indent the first line. Lorem ipsum dolor
360 sit amet, consectetuer adipiscing elit.
362 * Another item in the same list.
367 <p>This is a list item with two paragraphs.</p>
368 <p>This is the second paragraph in the list item. You're
369 only required to indent the first line. Lorem ipsum dolor
370 sit amet, consectetuer adipiscing elit.</p>
373 <p>Another item in the same list.</p>
377 assert md_to_html
(md
) == html
380 fun test_blocks_list_ext
is test
do
386 <p>This is a paragraph</p>
388 <li>and this is a list</li>
391 assert md_to_html
(md
) == html
394 fun test_blocks_indented_code1
is test
do
396 This is a normal paragraph:
398 This is a code block.
400 var html
= """<p>This is a normal paragraph:</p>
401 <pre><code>This is a code block.
404 assert md_to_html
(md
) == html
407 fun test_blocks_indented_code2
is test
do
409 Here is an example of AppleScript:
411 tell application "Foo"
416 © 2004 Foo Corporation
420 <p>Here is an example of AppleScript:</p>
421 <pre><code>tell application "Foo"
425 <div class="footer">
426 &copy; 2004 Foo Corporation
430 assert md_to_html
(md
) == html
433 fun test_blocks_indented_code3
is test
do
435 Here is an example of AppleScript:
440 <p>Here is an example of AppleScript:</p>
444 assert md_to_html
(md
) == html
447 fun test_blocks_fenced_code1
is test
do
449 Here is an example of AppleScript:
451 tell application "Foo"
456 © 2004 Foo Corporation
461 <p>Here is an example of AppleScript:</p>
462 <pre><code>tell application "Foo"
466 <div class="footer">
467 &copy; 2004 Foo Corporation
471 assert md_to_html
(md
) == html
474 fun test_blocks_fenced_code2
is test
do
476 Here is an example of AppleScript:
478 tell application "Foo"
483 © 2004 Foo Corporation
488 <p>Here is an example of AppleScript:</p>
489 <pre><code>tell application "Foo"
493 <div class="footer">
494 &copy; 2004 Foo Corporation
498 assert md_to_html
(md
) == html
501 fun test_blocks_fenced_code3
is test
do
508 <pre><code class="language-nit">print "Hello World!"
511 assert md_to_html
(md
) == html
514 fun test_blocks_fenced_code4
is test
do
524 <pre><code>print "Hello"
526 <pre><code>print "World"
529 assert md_to_html
(md
) == html
532 fun test_blocks_fenced_code5
is test
do
542 <pre><code>print "Hello"
544 <pre><code>print "World"
547 assert md_to_html
(md
) == html
550 fun test_blocks_nesting1
is test
do
552 > ## This is a header.
554 > 1. This is the first list item.
555 > 2. This is the second list item.
557 > Here's some example code:
559 > return shell_exec("echo $input | $markdown_script");
563 <h2>This is a header.</h2>
565 <li>This is the first list item.</li>
566 <li>This is the second list item.</li>
568 <p>Here's some example code:</p>
569 <pre><code>return shell_exec("echo $input | $markdown_script");
573 assert md_to_html
(md
) == html
576 fun test_blocks_nesting2
is test
do
578 * A list item with a blockquote:
580 > This is a blockquote
581 > inside a list item.
586 <p>A list item with a blockquote:</p>
588 <p>This is a blockquote
589 inside a list item.</p>
594 assert md_to_html
(md
) == html
597 fun test_blocks_nesting3
is test
do
599 * A list item with a code block:
606 <p>A list item with a code block:</p>
607 <pre><code><code goes here>
612 assert md_to_html
(md
) == html
615 fun test_blocks_nesting4
is test
do
634 assert md_to_html
(md
) == html
637 fun test_blocks_nesting5
is test
do
658 assert md_to_html
(md
) == html