# This file is part of NIT ( http://www.nitlanguage.org ). # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Test suites for module `markdown` module test_markdown is test intrude import markdown class TestMarkdownProcessor test fun test_process_empty is test do var test = "" var exp = "" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_tabs is test do var test = """ some code """ var exp = """
some code
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_par1 is test do
var test = "test"
var exp = "test
\n" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_par2 is test do var test = """ line1 line2 line3 line4 line5""" var exp = """line1 line2
line3 line4
line5
""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_par3 is test do var test = """ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. """ var exp = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_headings_1 is test do var test = """ This is a H1 ============= This is a H2 ------------- """ var exp = """""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_bquote2 is test do var test = """ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. """ var exp = """This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_bquote3 is test do var test = """ > This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level. """ var exp = """This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.
""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_list1 is test do var test = """ * Red * Green * Blue """ var exp = """This is the first level of quoting.
This is nested blockquote.
Back to the first level.
Bird
Magic
This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
This is a list item with two paragraphs.
This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Another item in the same list.
This is a paragraph * and this is not a list
""" var proc = new MarkdownProcessor proc.ext_mode = false var res = proc.process(test).write_to_string assert res == exp end fun test_process_list_ext is test do var test = """ This is a paragraph * and this is not a list """ var exp = """This is a paragraph
This is a normal paragraph:
This is a code block.
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code2 is test do
var test = """
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
"""
var exp = """
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
<div class="footer">
© 2004 Foo Corporation
</div>
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext1 is test do
var test = """
Here is an example of AppleScript:
~~~
tell application "Foo"
beep
end tell
~~~
"""
var exp = """
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
<div class="footer">
© 2004 Foo Corporation
</div>
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext2 is test do
var test = """
Here is an example of AppleScript:
```
tell application "Foo"
beep
end tell
```
"""
var exp = """
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
<div class="footer">
© 2004 Foo Corporation
</div>
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = """
Here is an example of AppleScript:
beep
"""
var exp = """
Here is an example of AppleScript: beep
""" var res = proc.process(test).write_to_string assert res == exp end fun test_process_code_ext4 is test do var test = """ Here is an example of AppleScript: beep """ var exp = """Here is an example of AppleScript:
beep
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext5 is test do
var test = """
```nit
print "Hello World!"
```
"""
var exp = """
print "Hello World!"
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext6 is test do
var test = """
~~~
print "Hello"
~~~
~~~
print "World"
~~~
"""
var exp = """
print "Hello"
print "World"
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_code_ext7 is test do
var test = """
~~~
print "Hello"
~~~
~~~
print "World"
~~~
"""
var exp = """
print "Hello"
print "World"
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_nesting1 is test do
var test = """
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
"""
var exp = """
""" var res = test.md_to_html.write_to_string assert res == exp end fun test_process_nesting2 is test do var test = """ * A list item with a blockquote: > This is a blockquote > inside a list item. """ var exp = """This is a header.
- This is the first list item.
- This is the second list item.
Here's some example code:
return shell_exec("echo $input | $markdown_script");
A list item with a blockquote:
This is a blockquote inside a list item.
"""
var exp = """
A list item with a code block:
<code goes here>
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_nesting4 is test do
var test = """
* Tab
* Tab
* Tab
"""
var exp = """
- Tab
- Tab
- Tab
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
# TODO
# fun test_process_nesting5 is test do
# var test = """
# * this
#
# * sub
#
# that
# """
# var exp = """
#
# this
#
# - sub
#
# that
#
#
# """
# var res = test.md_to_html.write_to_string
# assert res == exp
# end
fun test_process_emph1 is test do
var test = """
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
"""
var exp = """single asterisks
single underscores
double asterisks
double underscores
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_emph2 is test do
var test = "un*frigging*believable"
var exp = "unfriggingbelievable
\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_emph3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = "Con_cat_this"
var exp = "Concatthis
\n"
var res = proc.process(test).write_to_string
assert res == exp
end
fun test_process_emph_ext is test do
var test = "Con_cat_this"
var exp = "Con_cat_this
\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_xml1 is test do
var test = """
This is a regular paragraph.
Foo
This is another regular paragraph.
"""
var exp = """
This is a regular paragraph.
Foo
This is another regular paragraph.
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_xml2 is test do
var test = """
This is an image in a regular paragraph.
"""
var exp = """This is an image in a regular paragraph.
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_xml3 is test do
var test = """
"""
var exp = """
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_xml4 is test do
var test = """
This is an example of a block element that should be escaped.
Idem for the second paragraph.
"""
var exp = test
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_xml5 is test do
var test = """
# Some more XML tests
This is an example of a block element that should be escaped.
Idem for the second paragraph.
With a *md paragraph*!
"""
var exp = """
Some more XML tests
This is an example of a block element that should be escaped.
Idem for the second paragraph.
With a md paragraph!
"""
var res = test.md_to_html.write_to_string
print res
assert res == exp
end
fun test_process_span_code1 is test do
var test = "Use the `printf()` function."
var exp = "Use the printf()
function.
\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_span_code2 is test do
var test = "``There is a literal backtick (`) here.``"
var exp = "There is a literal backtick (`) here.
\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_span_code3 is test do
var test = """
A single backtick in a code span: `` ` ``
A backtick-delimited string in a code span: `` `foo` ``
"""
var exp = """
A single backtick in a code span: `
A backtick-delimited string in a code span: `foo`
"""
var res = test.md_to_html.write_to_string
assert res == exp
end
fun test_process_span_code4 is test do
var test = "Please don't use any `