# limitations under the License.
# Test suites for module `markdown`
-module test_markdown is test_suite
+module test_markdown is test
-import test_suite
intrude import markdown
class TestMarkdownProcessor
- super TestSuite
+ test
- fun test_process_empty do
+ 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 do
+ fun test_process_tabs is test do
var test = """
some code
"""
end
- fun test_process_par1 do
+ fun test_process_par1 is test do
var test = "test"
var exp = "<p>test</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_par2 do
+ fun test_process_par2 is test do
var test = """
line1
line2
assert res == exp
end
- fun test_process_par3 do
+ fun test_process_par3 is test do
var test = """
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus.
assert res == exp
end
- fun test_process_headings_1 do
+ fun test_process_headings_1 is test do
var test = """
This is a H1
=============
assert res == exp
end
- fun test_process_headings_2 do
+ fun test_process_headings_2 is test do
var test = """
# This is a H1
assert res == exp
end
- fun test_process_headings_3 do
+ fun test_process_headings_3 is test do
var test = """
# This is a H1 #
assert res == exp
end
- fun test_process_hr do
+ fun test_process_hr is test do
var test = """
* * *
assert res == exp
end
- fun test_process_bquote1 do
+ fun test_process_bquote1 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.
assert res == exp
end
- fun test_process_bquote2 do
+ 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.
assert res == exp
end
- fun test_process_bquote3 do
+ fun test_process_bquote3 is test do
var test = """
> This is the first level of quoting.
>
assert res == exp
end
- fun test_process_list1 do
+ fun test_process_list1 is test do
var test = """
* Red
* Green
assert res == exp
end
- fun test_process_list2 do
+ fun test_process_list2 is test do
var test = """
+ Red
+ Green
assert res == exp
end
- fun test_process_list3 do
+ fun test_process_list3 is test do
var test = """
- Red
- Green
assert res == exp
end
- fun test_process_list4 do
+ fun test_process_list4 is test do
var test = """
1. Bird
2. McHale
assert res == exp
end
- fun test_process_list5 do
+ fun test_process_list5 is test do
var test = """
3. Bird
1. McHale
assert res == exp
end
- fun test_process_list6 do
+ fun test_process_list6 is test do
var test = """
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
assert res == exp
end
- fun test_process_list7 do
+ fun test_process_list7 is test do
var test = """
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
assert res == exp
end
- fun test_process_list8 do
+ fun test_process_list8 is test do
var test = """
* Bird
assert res == exp
end
- fun test_process_list9 do
+ fun test_process_list9 is test do
var test = """
1. This is a list item with two paragraphs. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. Aliquam hendrerit
assert res == exp
end
- fun test_process_list10 do
+ fun test_process_list10 is test do
var test = """
* This is a list item with two paragraphs.
assert res == exp
end
- fun test_process_list11 do
+ fun test_process_list11 is test do
var test = """
This is a paragraph
* and this is not a list
assert res == exp
end
- fun test_process_list_ext do
+ fun test_process_list_ext is test do
var test = """
This is a paragraph
* and this is not a list
assert res == exp
end
- fun test_process_code1 do
+ fun test_process_code1 is test do
var test = """
This is a normal paragraph:
assert res == exp
end
- fun test_process_code2 do
+ fun test_process_code2 is test do
var test = """
Here is an example of AppleScript:
assert res == exp
end
- fun test_process_code_ext1 do
+ fun test_process_code_ext1 is test do
var test = """
Here is an example of AppleScript:
~~~
assert res == exp
end
- fun test_process_code_ext2 do
+ fun test_process_code_ext2 is test do
var test = """
Here is an example of AppleScript:
```
assert res == exp
end
- fun test_process_code_ext3 do
+ fun test_process_code_ext3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
assert res == exp
end
- fun test_process_code_ext4 do
+ fun test_process_code_ext4 is test do
var test = """
Here is an example of AppleScript:
beep
assert res == exp
end
- fun test_process_code_ext5 do
+ fun test_process_code_ext5 is test do
var test = """
```nit
print "Hello World!"
assert res == exp
end
- fun test_process_code_ext6 do
+ fun test_process_code_ext6 is test do
var test = """
~~~
print "Hello"
assert res == exp
end
- fun test_process_code_ext7 do
+ fun test_process_code_ext7 is test do
var test = """
~~~
print "Hello"
assert res == exp
end
- fun test_process_nesting1 do
+ fun test_process_nesting1 is test do
var test = """
> ## This is a header.
>
assert res == exp
end
- fun test_process_nesting2 do
+ fun test_process_nesting2 is test do
var test = """
* A list item with a blockquote:
assert res == exp
end
- fun test_process_nesting3 do
+ fun test_process_nesting3 is test do
var test = """
* A list item with a code block:
assert res == exp
end
- fun test_process_nesting4 do
+ fun test_process_nesting4 is test do
var test = """
* Tab
* Tab
end
# TODO
- # fun test_process_nesting5 do
+ # fun test_process_nesting5 is test do
# var test = """
# * this
#
# assert res == exp
# end
- fun test_process_emph1 do
+ fun test_process_emph1 is test do
var test = """
*single asterisks*
assert res == exp
end
- fun test_process_emph2 do
+ fun test_process_emph2 is test do
var test = "un*frigging*believable"
var exp = "<p>un<em>frigging</em>believable</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_emph3 do
+ fun test_process_emph3 is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = "Con_cat_this"
assert res == exp
end
- fun test_process_emph_ext do
+ fun test_process_emph_ext is test do
var test = "Con_cat_this"
var exp = "<p>Con_cat_this</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_xml1 do
+ fun test_process_xml1 is test do
var test = """
This is a regular paragraph.
assert res == exp
end
- fun test_process_xml2 do
+ fun test_process_xml2 is test do
var test = """
This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
"""
assert res == exp
end
- fun test_process_xml3 do
+ fun test_process_xml3 is test do
var test = """
<div style=">"/>
"""
assert res == exp
end
- fun test_process_span_code1 do
+ fun test_process_xml4 is test do
+ var test = """
+<p>This is an example of a block element that should be escaped.</p>
+<p>Idem for the second paragraph.</p>
+"""
+ 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
+
+<p>This is an example of a block element that should be escaped.</p>
+<p>Idem for the second paragraph.</p>
+
+With a *md paragraph*!
+"""
+ var exp = """
+<h1 id="Some_more_XML_tests">Some more XML tests</h1>
+<p>This is an example of a block element that should be escaped.</p>
+<p>Idem for the second paragraph.</p>
+<p>With a <em>md paragraph</em>!</p>
+"""
+ 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 = "<p>Use the <code>printf()</code> function.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code2 do
+ fun test_process_span_code2 is test do
var test = "``There is a literal backtick (`) here.``"
var exp = "<p><code>There is a literal backtick (`) here.</code></p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code3 do
+ fun test_process_span_code3 is test do
var test = """
A single backtick in a code span: `` ` ``
assert res == exp
end
- fun test_process_span_code4 do
+ fun test_process_span_code4 is test do
var test = "Please don't use any `<blink>` tags."
var exp = "<p>Please don't use any <code><blink></code> tags.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_span_code5 do
+ fun test_process_span_code5 is test do
var test = "`—` is the decimal-encoded equivalent of `—`."
var exp = "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape1 do
+ fun test_process_escape1 is test do
var test = "\\*this text is surrounded by literal asterisks\\*"
var exp = "<p>*this text is surrounded by literal asterisks*</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape2 do
+ fun test_process_escape2 is test do
var test = "1986\\. What a great season."
var exp = "<p>1986. What a great season.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_escape3 do
+ fun test_process_escape3 is test do
var test = "Ben & Lux"
var exp = "<p>Ben & Lux</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_link1 do
+ fun test_process_link1 is test do
var test = """
This is [an example](http://example.com/ "Title") inline link.
assert res == exp
end
- fun test_process_link2 do
+ fun test_process_link2 is test do
var test = "See my [About](/about/) page for details."
var exp = "<p>See my <a href=\"/about/\">About</a> page for details.</p>\n"
var res = test.md_to_html.write_to_string
assert res == exp
end
- fun test_process_link3 do
+ fun test_process_link3 is test do
var test = """
This is [an example][id] reference-style link.
assert res == exp
end
- fun test_process_link4 do
+ fun test_process_link4 is test do
var test = """
This is multiple examples: [foo][1], [bar][2], [baz][3].
assert res == exp
end
- fun test_process_link5 do
+ fun test_process_link5 is test do
var test = """
This is multiple examples: [foo][a], [bar][A], [a].
assert res == exp
end
- fun test_process_link6 do
+ fun test_process_link6 is test do
var test = """
I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
assert res == exp
end
- fun test_process_link7 do
+ fun test_process_link7 is test do
var test = """
Visit [Daring Fireball][] for more information.
assert res == exp
end
- fun test_process_link8 do
+ fun test_process_link8 is test do
var test = """
This one has a [line
break].
end
# FIXME unignore test once escape strings fixed
- # fun test_process_link9 do
+ # fun test_process_link9 is test do
# var test = """
# Foo [bar][].
#
# assert res == exp
# end
- fun test_process_img1 do
+ fun test_process_img1 is test do
var test = """
![Alt text](/path/to/img.jpg)
assert res == exp
end
- fun test_process_img2 do
+ fun test_process_img2 is test do
var test = """
![Alt text][id]
assert res == exp
end
- fun test_process_strike do
+ fun test_process_strike is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
var test = "This is how you ~~strike text~~"
assert exp == res
end
- fun test_process_strike_ext do
+ fun test_process_strike_ext is test do
var test = "This is how you ~~strike text~~"
var exp = "<p>This is how you <del>strike text</del></p>\n"
var res = test.md_to_html.write_to_string
assert exp == res
end
- fun test_escape_bad_html do
+ fun test_escape_bad_html is test do
var test = "-1 if < , +1 if > and 0 otherwise"
var exp = "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
var res = test.md_to_html.write_to_string
assert exp == res
end
- fun test_daring_encoding do
+ fun test_daring_encoding is test do
var test = """
AT&T has an ampersand in their name.
end
- fun test_daring_autolinks do
+ fun test_daring_autolinks is test do
var test = """
Link: <http://example.com/>.
assert res == exp
end
- fun test_daring_escape do
+ fun test_daring_escape is test do
var test = """
These should all get escaped:
assert res == exp
end
- fun test_daring_blockquotes do
+ fun test_daring_blockquotes is test do
var test = """
> Example:
>
assert res == exp
end
- fun test_daring_code_blocks do
+ fun test_daring_code_blocks is test do
var test = """
code block on the first line
assert res == exp
end
- fun test_daring_code_spans do
+ fun test_daring_code_spans is test do
var test = """
`<test a="` content of attribute `">`
assert res == exp
end
- fun test_daring_pars do
+ fun test_daring_pars is test do
var proc = new MarkdownProcessor
proc.ext_mode = false
assert res == exp
end
- fun test_daring_rules do
+ fun test_daring_rules is test do
var test = """
Dashes:
assert res == exp
end
- fun test_daring_images do
+ fun test_daring_images is test do
var test = """
![Alt text](/path/to/img.jpg)
assert res == exp
end
- fun test_daring_inline_html1 do
+ fun test_daring_inline_html1 is test do
var test = """
Here's a simple block:
assert res == exp
end
- fun test_daring_inline_html2 do
+ fun test_daring_inline_html2 is test do
var test = """
Simple block on one line:
assert res == exp
end
- fun test_daring_inline_html3 do
+ fun test_daring_inline_html3 is test do
var test = """
Paragraph one.
assert res == exp
end
- fun test_daring_links1 do
+ fun test_daring_links1 is test do
var test = """
Just a [URL](/url/).
assert res == exp
end
- fun test_daring_links2 do
+ fun test_daring_links2 is test do
var test = """
Foo [bar] [1].
assert res == exp
end
- fun test_daring_links3 do
+ fun test_daring_links3 is test do
var test = """
This is the [simple case].
assert res == exp
end
- fun test_daring_nested do
+ fun test_daring_nested is test do
var test = """
> foo
>
assert res == exp
end
- fun test_daring_list do
+ fun test_daring_list is test do
var test = """
## Unordered
assert res == exp
end
- fun test_daring_strong_em do
+ fun test_daring_strong_em is test do
var test = """
***This is strong and em.***
assert res == exp
end
- fun test_daring_tabs do
+ fun test_daring_tabs is test do
var test = """
+ this is a list item
indented with tabs
assert res == exp
end
- fun test_daring_tidyness do
+ fun test_daring_tidyness is test do
var test = """
> A list within a blockquote:
>
end
class TestBlock
- super TestSuite
+ test
# A dummy location for testing purposes.
var loc = new MDLocation(0, 0, 0, 0)
- fun test_has_blocks do
+ fun test_has_blocks is test do
var subject = new MDBlock(loc)
assert not subject.has_blocks
subject.first_block = new MDBlock(loc)
assert subject.has_blocks
end
- fun test_count_blocks do
+ fun test_count_blocks is test do
var subject = new MDBlock(loc)
assert subject.count_blocks == 0
subject.first_block = new MDBlock(loc)
assert subject.count_blocks == 2
end
- fun test_has_lines do
+ fun test_has_lines is test do
var subject = new MDBlock(loc)
assert not subject.has_lines
subject.first_line = new MDLine(loc, "")
assert subject.has_lines
end
- fun test_count_lines do
+ fun test_count_lines is test do
var subject = new MDBlock(loc)
assert subject.count_lines == 0
subject.first_line = new MDLine(loc, "")
assert subject.count_lines == 2
end
- fun test_split do
+ fun test_split is test do
var line1 = new MDLine(loc, "line1")
var line2 = new MDLine(loc, "line2")
var line3 = new MDLine(loc, "line3")
assert block.last_line == line2
end
- fun test_add_line do
+ fun test_add_line is test do
var subject = new MDBlock(loc)
assert subject.count_lines == 0
subject.add_line new MDLine(loc, "")
assert subject.count_lines == 2
end
- fun test_remove_line do
+ fun test_remove_line is test do
var line1 = new MDLine(loc, "line1")
var line2 = new MDLine(loc, "line2")
var line3 = new MDLine(loc, "line3")
assert subject.last_line == line3
end
- fun test_transform_headline1 do
+ fun test_transform_headline1 is test do
var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
subject.add_line new MDLine(loc, " # Title 1 ")
assert subject.first_line.value == "Title 1"
end
- fun test_transform_headline2 do
+ fun test_transform_headline2 is test do
var subject = new MDBlock(loc)
var kind = new BlockHeadline(subject)
subject.add_line new MDLine(loc, " #####Title 5 ")
assert subject.first_line.value == "Title 5"
end
- fun test_remove_quote_prefix do
+ fun test_remove_quote_prefix is test do
var subject = new MDBlock(loc)
var kind = new BlockQuote(subject)
subject.add_line new MDLine(loc, " > line 1")
assert subject.first_line.next.next.value == "line 3"
end
- fun test_remove_leading_empty_lines_1 do
+ fun test_remove_leading_empty_lines_1 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "")
assert block.first_line.value == " text"
end
- fun test_remove_leading_empty_lines_2 do
+ fun test_remove_leading_empty_lines_2 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, " text")
block.remove_leading_empty_lines
assert block.first_line.value == " text"
end
- fun test_remove_trailing_empty_lines_1 do
+ fun test_remove_trailing_empty_lines_1 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "text")
assert block.last_line.value == "text"
end
- fun test_remove_trailing_empty_lines_2 do
+ fun test_remove_trailing_empty_lines_2 is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "text ")
assert not block.remove_trailing_empty_lines
assert block.last_line.value == "text "
end
- fun test_remove_surrounding_empty_lines do
+ fun test_remove_surrounding_empty_lines is test do
var block = new MDBlock(loc)
block.add_line new MDLine(loc, "")
block.add_line new MDLine(loc, "text")
end
class TestLine
- super TestSuite
+ test
# A dummy location for testing purposes.
var loc = new MDLocation(0, 0, 0, 0)
var subject: MDLine
- fun test_is_empty do
+ fun test_is_empty is test do
subject = new MDLine(loc, "")
assert subject.is_empty
subject = new MDLine(loc, " ")
assert not subject.is_empty
end
- fun test_leading do
+ fun test_leading is test do
subject = new MDLine(loc, "")
assert subject.leading == 0
subject = new MDLine(loc, " ")
assert subject.leading == 4
end
- fun test_trailing do
+ fun test_trailing is test do
subject = new MDLine(loc, "")
assert subject.trailing == 0
subject = new MDLine(loc, " ")
assert subject.trailing == 1
end
- fun test_line_type do
+ fun test_line_type is test do
var v = new MarkdownProcessor
subject = new MDLine(loc, "")
assert v.line_kind(subject) isa LineEmpty
assert v.line_kind(subject) isa LineOList
end
- fun test_line_type_ext do
+ fun test_line_type_ext is test do
var v = new MarkdownProcessor
subject = new MDLine(loc, " ~~~")
assert v.line_kind(subject) isa LineFence
assert v.line_kind(subject) isa LineFence
end
- fun test_count_chars do
+ fun test_count_chars is test do
subject = new MDLine(loc, "")
assert subject.count_chars('*') == 0
subject = new MDLine(loc, "* ")
assert subject.count_chars('*') == 0
end
- fun test_count_chars_start do
+ fun test_count_chars_start is test do
subject = new MDLine(loc, "")
assert subject.count_chars_start('*') == 0
subject = new MDLine(loc, "* ")
end
class TestHTMLDecorator
- super TestSuite
+ test
- fun test_headlines do
+ fun test_headlines is test do
var test = """
# **a**
## a.a
end
class TestTokenLocation
- super TestSuite
+ test
- fun test_token_location1 do
+ fun test_token_location1 is test do
var string = "**Hello** `World`"
var stack = [
"TokenStrongStar at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location2 do
+ fun test_token_location2 is test do
var string = "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
var stack = [
"TokenStrongStar at 1,1--1,1",
(new TestTokenProcessor(stack)).process(string)
end
- fun test_token_location3 do
+ fun test_token_location3 is test do
var string = """**Hello**
`World`
*Bonjour*
"TokenLink at 4,1--4,1"]
(new TestTokenProcessor(stack)).process(string)
end
+
+ fun test_token_location4 is test do
+ var string = "**Hello**\n\n`World`"
+ var stack = [
+ "TokenStrongStar at 1,1--1,1",
+ "TokenStrongStar at 1,8--1,8",
+ "TokenCodeSingle at 3,1--3,1",
+ "TokenCodeSingle at 3,7--3,7"]
+ (new TestTokenProcessor(stack)).process(string)
+ end
+
+ fun test_token_location5 is test do
+ var string = "# *Title1*\n\n# *Title2*"
+ var stack = [
+ "TokenEmStar at 1,3--1,3",
+ "TokenEmStar at 1,10--1,10",
+ "TokenEmStar at 3,3--3,3",
+ "TokenEmStar at 3,10--3,10"]
+ (new TestTokenProcessor(stack)).process(string)
+ end
end
class TestTokenProcessor
redef fun token_at(input, pos) do
var token = super
if token isa TokenNone then return token
- var res = "{token.class_name} at {token.location}"
- print res
+ var res = "{token.class_name} at {token.location or else "?"}"
var exp = test_stack.shift
+ print ""
+ print "EXP {exp}"
+ print "RES {res}"
assert exp == res
return token
end
end
class TestBlockLocation
- super TestSuite
+ test
var proc = new MarkdownProcessor
- fun test_block_location1 do
+ fun test_block_location1 is test do
var stack = [
"BlockHeadline: 1,1--1,8",
"BlockListItem: 2,1--2,6",
proc.process(string)
end
- fun test_block_location2 do
+ fun test_block_location2 is test do
var stack = [
"BlockHeadline: 1,1--1,11",
"BlockFence: 3,1--5,4",
proc.emitter.decorator = new TestBlockDecorator(stack)
proc.process(string)
end
+
+ fun test_block_location3 is test do
+ var stack = [
+ "BlockHeadline: 1,1--1,8",
+ "BlockHeadline: 3,1--3,10"]
+ var string ="""# Title\n\n## Title 2"""
+ proc.emitter.decorator = new TestBlockDecorator(stack)
+ proc.process(string)
+ end
end
class TestBlockDecorator