Merge: Basename fix
[nit.git] / lib / markdown / test_markdown.nit
index 6a49039..53c355f 100644 (file)
@@ -416,7 +416,9 @@ This is a paragraph
 <p>This is a paragraph
 * and this is not a list</p>
 """
-               var res = test.md_to_html.write_to_string
+               var proc = new MarkdownProcessor
+               proc.ext_mode = false
+               var res = proc.process(test).write_to_string
                assert res == exp
        end
 
@@ -431,9 +433,7 @@ This is a paragraph
 <li>and this is not a list</li>
 </ul>
 """
-               var proc = new MarkdownProcessor
-               proc.ext_mode = true
-               var res = proc.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
@@ -479,8 +479,6 @@ end tell
        end
 
        fun test_process_code_ext1 do
-               var processor = new MarkdownProcessor
-               processor.ext_mode = true
                var test = """
 Here is an example of AppleScript:
 ~~~
@@ -504,13 +502,11 @@ end tell
 &lt;/div&gt;
 </code></pre>
 """
-               var res = processor.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
        fun test_process_code_ext2 do
-               var processor = new MarkdownProcessor
-               processor.ext_mode = true
                var test = """
 Here is an example of AppleScript:
 ```
@@ -534,11 +530,14 @@ end tell
 &lt;/div&gt;
 </code></pre>
 """
-               var res = processor.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
        fun test_process_code_ext3 do
+               var proc = new MarkdownProcessor
+               proc.ext_mode = false
+
                var test = """
 Here is an example of AppleScript:
     beep
@@ -547,13 +546,11 @@ Here is an example of AppleScript:
 <p>Here is an example of AppleScript:
 beep</p>
 """
-               var res = test.md_to_html.write_to_string
+               var res = proc.process(test).write_to_string
                assert res == exp
        end
 
        fun test_process_code_ext4 do
-               var processor = new MarkdownProcessor
-               processor.ext_mode = true
                var test = """
 Here is an example of AppleScript:
     beep
@@ -563,13 +560,11 @@ Here is an example of AppleScript:
 <pre><code>beep
 </code></pre>
 """
-               var res = processor.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
        fun test_process_code_ext5 do
-               var processor = new MarkdownProcessor
-               processor.ext_mode = true
                var test = """
 ```nit
 print "Hello World!"
@@ -579,7 +574,45 @@ print "Hello World!"
 <pre class="nit"><code>print "Hello World!"
 </code></pre>
 """
-               var res = processor.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
+               assert res == exp
+       end
+
+       fun test_process_code_ext6 do
+               var test = """
+~~~
+print "Hello"
+~~~
+~~~
+print "World"
+~~~
+"""
+               var exp = """
+<pre><code>print "Hello"
+</code></pre>
+<pre><code>print "World"
+</code></pre>
+"""
+               var res = test.md_to_html.write_to_string
+               assert res == exp
+       end
+
+       fun test_process_code_ext7 do
+               var test = """
+~~~
+print "Hello"
+~~~
+~~~
+print "World"
+~~~
+"""
+               var exp = """
+<pre><code>print "Hello"
+</code></pre>
+<pre><code>print "World"
+</code></pre>
+"""
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
@@ -720,18 +753,18 @@ __double underscores__
        end
 
        fun test_process_emph3 do
+               var proc = new MarkdownProcessor
+               proc.ext_mode = false
                var test = "Con_cat_this"
                var exp = "<p>Con<em>cat</em>this</p>\n"
-               var res = test.md_to_html.write_to_string
+               var res = proc.process(test).write_to_string
                assert res == exp
        end
 
        fun test_process_emph_ext do
                var test = "Con_cat_this"
                var exp = "<p>Con_cat_this</p>\n"
-               var proc = new MarkdownProcessor
-               proc.ext_mode = true
-               var res = proc.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert res == exp
        end
 
@@ -781,6 +814,36 @@ This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
                assert res == exp
        end
 
+       fun test_process_xml4 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 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 do
                var test = "Use the `printf()` function."
                var exp = "<p>Use the <code>printf()</code> function.</p>\n"
@@ -1003,21 +1066,27 @@ break</a> with a line-ending space.</p>
        end
 
        fun test_process_strike do
+               var proc = new MarkdownProcessor
+               proc.ext_mode = false
                var test = "This is how you ~~strike text~~"
                var exp = "<p>This is how you ~~strike text~~</p>\n"
-               var res = test.md_to_html.write_to_string
+               var res = proc.process(test).write_to_string
                assert exp == res
        end
 
        fun test_process_strike_ext do
-               var proc = new MarkdownProcessor
-               proc.ext_mode = true
                var test = "This is how you ~~strike text~~"
                var exp = "<p>This is how you <del>strike text</del></p>\n"
-               var res = proc.process(test).write_to_string
+               var res = test.md_to_html.write_to_string
                assert exp == res
        end
 
+       fun test_escape_bad_html do
+                       var test = "-1 if < , +1 if > and 0 otherwise"
+                       var exp = "<p>-1 if &lt; , +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
                var test = """
@@ -1386,6 +1455,9 @@ Here's how you put `` `backticks` `` in a code span.
        end
 
        fun test_daring_pars do
+               var proc = new MarkdownProcessor
+               proc.ext_mode = false
+
                var test = """
 In Markdown 1.0.0 and earlier. Version
 8. This line turns into a list item.
@@ -1406,7 +1478,7 @@ list item.</p>
 <p>Here's one with a bullet.
 * criminey.</p>
 """
-               var res = test.md_to_html.write_to_string
+               var res = proc.process(test).write_to_string
                assert res == exp
        end
 
@@ -2362,43 +2434,46 @@ end
 class TestBlock
        super TestSuite
 
+       # A dummy location for testing purposes.
+       var loc = new MDLocation(0, 0, 0, 0)
+
        fun test_has_blocks do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                assert not subject.has_blocks
-               subject.first_block = new MDBlock
+               subject.first_block = new MDBlock(loc)
                assert subject.has_blocks
        end
 
        fun test_count_blocks do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                assert subject.count_blocks == 0
-               subject.first_block = new MDBlock
+               subject.first_block = new MDBlock(loc)
                assert subject.count_blocks == 1
-               subject.first_block.next = new MDBlock
+               subject.first_block.next = new MDBlock(loc)
                assert subject.count_blocks == 2
        end
 
        fun test_has_lines do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                assert not subject.has_lines
-               subject.first_line = new MDLine("")
+               subject.first_line = new MDLine(loc, "")
                assert subject.has_lines
        end
 
        fun test_count_lines do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                assert subject.count_lines == 0
-               subject.first_line = new MDLine("")
+               subject.first_line = new MDLine(loc, "")
                assert subject.count_lines == 1
-               subject.first_line.next = new MDLine("")
+               subject.first_line.next = new MDLine(loc, "")
                assert subject.count_lines == 2
        end
 
        fun test_split do
-               var line1 = new MDLine("line1")
-               var line2 = new MDLine("line2")
-               var line3 = new MDLine("line3")
-               var subject = new MDBlock
+               var line1 = new MDLine(loc, "line1")
+               var line2 = new MDLine(loc, "line2")
+               var line3 = new MDLine(loc, "line3")
+               var subject = new MDBlock(loc)
                subject.add_line line1
                subject.add_line line2
                subject.add_line line3
@@ -2413,19 +2488,19 @@ class TestBlock
        end
 
        fun test_add_line do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                assert subject.count_lines == 0
-               subject.add_line new MDLine("")
+               subject.add_line new MDLine(loc, "")
                assert subject.count_lines == 1
-               subject.add_line new MDLine("")
+               subject.add_line new MDLine(loc, "")
                assert subject.count_lines == 2
        end
 
        fun test_remove_line do
-               var line1 = new MDLine("line1")
-               var line2 = new MDLine("line2")
-               var line3 = new MDLine("line3")
-               var subject = new MDBlock
+               var line1 = new MDLine(loc, "line1")
+               var line2 = new MDLine(loc, "line2")
+               var line3 = new MDLine(loc, "line3")
+               var subject = new MDBlock(loc)
                subject.add_line line1
                subject.add_line line2
                subject.add_line line3
@@ -2438,29 +2513,29 @@ class TestBlock
        end
 
        fun test_transform_headline1 do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                var kind = new BlockHeadline(subject)
-               subject.add_line new MDLine(" #   Title 1   ")
+               subject.add_line new MDLine(loc, " #   Title 1   ")
                kind.transform_headline(subject)
                assert kind.depth == 1
                assert subject.first_line.value == "Title 1"
        end
 
        fun test_transform_headline2 do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                var kind = new BlockHeadline(subject)
-               subject.add_line new MDLine(" #####Title 5   ")
+               subject.add_line new MDLine(loc, " #####Title 5   ")
                kind.transform_headline(subject)
                assert kind.depth == 5
                assert subject.first_line.value == "Title 5"
        end
 
        fun test_remove_quote_prefix do
-               var subject = new MDBlock
+               var subject = new MDBlock(loc)
                var kind = new BlockQuote(subject)
-               subject.add_line new MDLine(" > line 1")
-               subject.add_line new MDLine(" > line 2")
-               subject.add_line new MDLine(" > line 3")
+               subject.add_line new MDLine(loc, " > line 1")
+               subject.add_line new MDLine(loc, " > line 2")
+               subject.add_line new MDLine(loc, " > line 3")
                kind.remove_block_quote_prefix(subject)
                assert subject.first_line.value == "line 1"
                assert subject.first_line.next.value == "line 2"
@@ -2468,51 +2543,51 @@ class TestBlock
        end
 
        fun test_remove_leading_empty_lines_1 do
-               var block = new MDBlock
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("   text")
-               block.add_line new MDLine("")
+               var block = new MDBlock(loc)
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "   text")
+               block.add_line new MDLine(loc, "")
                assert block.remove_leading_empty_lines
                assert block.first_line.value == "   text"
        end
 
        fun test_remove_leading_empty_lines_2 do
-               var block = new MDBlock
-               block.add_line new MDLine("   text")
+               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
-               var block = new MDBlock
-               block.add_line new MDLine("")
-               block.add_line new MDLine("text")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
+               var block = new MDBlock(loc)
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "text")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
                assert block.remove_trailing_empty_lines
                assert block.last_line.value == "text"
        end
 
        fun test_remove_trailing_empty_lines_2 do
-               var block = new MDBlock
-               block.add_line new MDLine("text  ")
+               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
-               var block = new MDBlock
-               block.add_line new MDLine("")
-               block.add_line new MDLine("text")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
-               block.add_line new MDLine("")
+               var block = new MDBlock(loc)
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "text")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
+               block.add_line new MDLine(loc, "")
                assert block.remove_surrounding_empty_lines
                assert block.first_line.value == "text"
                assert block.last_line.value == "text"
@@ -2522,121 +2597,123 @@ end
 class TestLine
        super TestSuite
 
-       var subject: MDLine
+       # A dummy location for testing purposes.
+       var loc = new MDLocation(0, 0, 0, 0)
 
-       init do end
+       var subject: MDLine
 
        fun test_is_empty do
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert subject.is_empty
-               subject = new MDLine("    ")
+               subject = new MDLine(loc, "    ")
                assert subject.is_empty
-               subject = new MDLine("test")
+               subject = new MDLine(loc, "test")
                assert not subject.is_empty
-               subject = new MDLine("    test")
+               subject = new MDLine(loc, "    test")
                assert not subject.is_empty
        end
 
        fun test_leading do
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert subject.leading == 0
-               subject = new MDLine("    ")
+               subject = new MDLine(loc, "    ")
                assert subject.leading == 4
-               subject = new MDLine("test")
+               subject = new MDLine(loc, "test")
                assert subject.leading == 0
-               subject = new MDLine("    test")
+               subject = new MDLine(loc, "    test")
                assert subject.leading == 4
        end
 
        fun test_trailing do
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert subject.trailing == 0
-               subject = new MDLine("    ")
+               subject = new MDLine(loc, "    ")
                assert subject.trailing == 0
-               subject = new MDLine("test   ")
+               subject = new MDLine(loc, "test   ")
                assert subject.trailing == 3
-               subject = new MDLine("    test ")
+               subject = new MDLine(loc, "    test ")
                assert subject.trailing == 1
        end
 
        fun test_line_type do
                var v = new MarkdownProcessor
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert v.line_kind(subject) isa LineEmpty
-               subject = new MDLine("    ")
+               subject = new MDLine(loc, "    ")
                assert v.line_kind(subject) isa LineEmpty
-               subject = new MDLine("text   ")
+               subject = new MDLine(loc, "text   ")
                assert v.line_kind(subject) isa LineOther
-               subject = new MDLine("  # Title")
+               subject = new MDLine(loc, "  # Title")
                assert v.line_kind(subject) isa LineHeadline
-               subject = new MDLine("  ### Title")
+               subject = new MDLine(loc, "  ### Title")
                assert v.line_kind(subject) isa LineHeadline
-               subject = new MDLine("    code")
+               subject = new MDLine(loc, "    code")
                assert v.line_kind(subject) isa LineCode
-               subject = new MDLine("   Title  ")
-               subject.next = new MDLine("== ")
+               subject = new MDLine(loc, "   Title  ")
+               subject.next = new MDLine(loc, "== ")
                assert v.line_kind(subject) isa LineHeadline1
-               subject = new MDLine("   Title  ")
-               subject.next = new MDLine("-- ")
+               subject = new MDLine(loc, "   Title  ")
+               subject.next = new MDLine(loc, "-- ")
                assert v.line_kind(subject) isa LineHeadline2
-               subject = new MDLine("  *    *   * ")
+               subject = new MDLine(loc, "  *    *   * ")
                assert v.line_kind(subject) isa LineHR
-               subject = new MDLine("  *** ")
+               subject = new MDLine(loc, "  *** ")
                assert v.line_kind(subject) isa LineHR
-               subject = new MDLine("- -- ")
+               subject = new MDLine(loc, "- -- ")
                assert v.line_kind(subject) isa LineHR
-               subject = new MDLine("--------- ")
+               subject = new MDLine(loc, "--------- ")
                assert v.line_kind(subject) isa LineHR
-               subject = new MDLine(" >")
+               subject = new MDLine(loc, " >")
                assert v.line_kind(subject) isa LineBlockquote
-               subject = new MDLine("<p></p>")
+               subject = new MDLine(loc, "<p></p>")
                assert v.line_kind(subject) isa LineXML
-               subject = new MDLine("<p>")
+               subject = new MDLine(loc, "<p>")
                assert v.line_kind(subject) isa LineOther
-               subject = new MDLine("  * foo")
+               subject = new MDLine(loc, "  * foo")
                assert v.line_kind(subject) isa LineUList
-               subject = new MDLine("- foo")
+               subject = new MDLine(loc, "- foo")
                assert v.line_kind(subject) isa LineUList
-               subject = new MDLine("+ foo")
+               subject = new MDLine(loc, "+ foo")
                assert v.line_kind(subject) isa LineUList
-               subject = new MDLine("1. foo")
+               subject = new MDLine(loc, "1. foo")
                assert v.line_kind(subject) isa LineOList
-               subject = new MDLine("   11111. foo")
+               subject = new MDLine(loc, "   11111. foo")
                assert v.line_kind(subject) isa LineOList
        end
 
        fun test_line_type_ext do
                var v = new MarkdownProcessor
-               v.ext_mode = true
-               subject = new MDLine("  ~~~")
+               subject = new MDLine(loc, "  ~~~")
                assert v.line_kind(subject) isa LineFence
-               subject = new MDLine("  ```")
+               subject = new MDLine(loc, "  ```")
+               assert v.line_kind(subject) isa LineFence
+               subject = new MDLine(loc, "~~~raw")
                assert v.line_kind(subject) isa LineFence
        end
 
        fun test_count_chars do
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert subject.count_chars('*') == 0
-               subject = new MDLine("* ")
+               subject = new MDLine(loc, "* ")
                assert subject.count_chars('*') == 1
-               subject = new MDLine(" * text")
+               subject = new MDLine(loc, " * text")
                assert subject.count_chars('*') == 0
-               subject = new MDLine(" *    *    *")
+               subject = new MDLine(loc, " *    *    *")
                assert subject.count_chars('*') == 3
-               subject = new MDLine("text ** ")
+               subject = new MDLine(loc, "text ** ")
                assert subject.count_chars('*') == 0
        end
 
        fun test_count_chars_start do
-               subject = new MDLine("")
+               subject = new MDLine(loc, "")
                assert subject.count_chars_start('*') == 0
-               subject = new MDLine("* ")
+               subject = new MDLine(loc, "* ")
                assert subject.count_chars_start('*') == 1
-               subject = new MDLine(" * text")
+               subject = new MDLine(loc, " * text")
                assert subject.count_chars_start('*') == 1
-               subject = new MDLine(" *    *    * text")
+               subject = new MDLine(loc, " *    *    * text")
                assert subject.count_chars_start('*') == 3
-               subject = new MDLine("text ** ")
+               subject = new MDLine(loc, "text ** ")
                assert subject.count_chars_start('*') == 0
        end
 end
@@ -2681,3 +2758,161 @@ c:c
                assert res == exp
        end
 end
+
+class TestTokenLocation
+       super TestSuite
+
+       fun test_token_location1 do
+               var string = "**Hello** `World`"
+               var stack =  [
+                       "TokenStrongStar at 1,1--1,1",
+                       "TokenStrongStar at 1,8--1,8",
+                       "TokenCodeSingle at 1,11--1,11",
+                       "TokenCodeSingle at 1,17--1,17"]
+               (new TestTokenProcessor(stack)).process(string)
+       end
+
+       fun test_token_location2 do
+               var string = "**Hello**\n`World`\n*Bonjour*\n[le monde]()"
+               var stack =  [
+                       "TokenStrongStar at 1,1--1,1",
+                       "TokenStrongStar at 1,8--1,8",
+                       "TokenCodeSingle at 2,1--2,1",
+                       "TokenCodeSingle at 2,7--2,7",
+                       "TokenEmStar at 3,1--3,1",
+                       "TokenEmStar at 3,9--3,9",
+                       "TokenLink at 4,1--4,1"]
+               (new TestTokenProcessor(stack)).process(string)
+       end
+
+       fun test_token_location3 do
+               var string = """**Hello**
+               `World`
+               *Bonjour*
+               [le monde]()"""
+               var stack =  [
+                       "TokenStrongStar at 1,1--1,1",
+                       "TokenStrongStar at 1,8--1,8",
+                       "TokenCodeSingle at 2,1--2,1",
+                       "TokenCodeSingle at 2,7--2,7",
+                       "TokenEmStar at 3,1--3,1",
+                       "TokenEmStar at 3,9--3,9",
+                       "TokenLink at 4,1--4,1"]
+               (new TestTokenProcessor(stack)).process(string)
+       end
+
+       fun test_token_location4 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 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
+       super MarkdownProcessor
+
+       var test_stack: Array[String]
+
+       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}"
+               var exp = test_stack.shift
+               print ""
+               print "EXP {exp}"
+               print "RES {res}"
+               assert exp == res
+               return token
+       end
+end
+
+class TestBlockLocation
+       super TestSuite
+
+       var proc = new MarkdownProcessor
+
+       fun test_block_location1 do
+               var stack = [
+                       "BlockHeadline: 1,1--1,8",
+                       "BlockListItem: 2,1--2,6",
+                       "BlockListItem: 3,1--3,5"
+               ]
+               var string =
+               "# Title\n* li1\n* li2"
+               proc.emitter.decorator = new TestBlockDecorator(stack)
+               proc.process(string)
+       end
+
+       fun test_block_location2 do
+               var stack = [
+                       "BlockHeadline: 1,1--1,11",
+                       "BlockFence: 3,1--5,4",
+                       "BlockListItem: 7,1--7,7",
+                       "BlockListItem: 8,1--8,6"]
+               var string ="""#### Title
+
+~~~fence
+some code
+~~~
+
+1. li1
+1. li2"""
+               proc.emitter.decorator = new TestBlockDecorator(stack)
+               proc.process(string)
+       end
+
+       fun test_block_location3 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
+       super HTMLDecorator
+
+       var stack: Array[String]
+
+       redef fun add_headline(v, block) do
+               super
+               check_res(block)
+       end
+
+       redef fun add_listitem(v, block) do
+               super
+               check_res(block)
+       end
+
+       redef fun add_blockquote(v, block) do
+               super
+               check_res(block)
+       end
+
+       redef fun add_code(v, block) do
+               super
+               check_res(block)
+       end
+
+       fun check_res(block: Block) do
+               var res = "{block.class_name}: {block.block.location}"
+               var exp = stack.shift
+               assert res == exp
+       end
+end