# 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. # Tests for markdown rendering to markdown module test_markdown_md is test import test_markdown import markdown_md_rendering abstract class TestMarkdownMd super TestMarkdown var md_renderer = new MarkdownRenderer fun md_to_md(md: String): String do var doc = md_parser.parse(md) doc.debug return md_renderer.render(doc) end end class TestMdHeadings super TestMarkdownMd test fun test_no_trailings is test do var md = """# foo\n## foo\n### foo\n#### foo\n##### foo\n###### foo\n""" var exp = """# foo\n\n## foo\n\n### foo\n\n#### foo\n\n##### foo\n\n###### foo\n""" assert md_to_md(md) == exp end fun test_trailings is test do var md = """# foo #\n## foo ##\n### foo ###\n#### foo ####\n##### foo #####\n""" var exp = """# foo #\n\n## foo ##\n\n### foo ###\n\n#### foo ####\n\n##### foo #####\n""" assert md_to_md(md) == exp end fun test_setext is test do var md = """Foo *bar*\n=========\nFoo *bar*\n---------\n""" var exp = """Foo *bar*\n=========\n\nFoo *bar*\n---------\n""" assert md_to_md(md) == exp end end class TestMdBlockQuotes super TestMarkdownMd test fun test191 is test do var md = """> # Foo\n> bar\n> baz\n""" assert md_to_md(md) == md end fun test197 is test do var md = """> foo\n---\n""" var exp = """> foo\n\n---\n""" assert md_to_md(md) == exp end fun test198 is test do var md = """> - foo\n- bar\n""" var exp = """> - foo\n\n- bar\n""" assert md_to_md(md) == exp end fun test206 is test do var md = """> foo\n> bar\n""" assert md_to_md(md) == md end fun test213 is test do var md = """> > > foo\n> bar\n""" var exp = """> > > foo\n> > > bar\n""" assert md_to_md(md) == exp end end class TestMdLists super TestMarkdownMd test fun test264 is test do var md = """- foo\n- bar\n+ baz\n""" var exp = """- foo\n- bar\n\n+ baz\n""" assert md_to_md(md) == exp end fun test265 is test do var md = """1. foo\n2. bar\n3) baz\n""" var exp = """1. foo\n2. bar\n\n3) baz\n""" assert md_to_md(md) == exp end fun test270 is test do var md = """- foo\n - bar\n - baz\n\n bim\n""" assert md_to_md(md) == md end fun test273 is test do var md = """- a\n - b\n - c\n - d\n - e\n - f\n- g\n""" var exp = """- a\n- b\n- c\n- d\n- e\n- f\n- g\n""" assert md_to_md(md) == exp end fun test274 is test do var md = """1. a\n\n 2. b\n\n 3. c\n""" var exp = """1. a\n\n2. b\n\n3. c\n""" assert md_to_md(md) == exp end fun test289 is test do var md = """- a\n - b\n - c\n\n- d\n - e\n - f\n""" var exp = """- a\n\n - b\n - c\n\n- d\n\n - e\n - f\n""" assert md_to_md(md) == exp end end class TestMdkListItems super TestMarkdownMd test fun test217 is test do var md = """1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote.\n""" var exp = """1. A paragraph\n with two lines.\n\n indented code\n\n > A block quote.\n""" assert md_to_md(md) == exp end fun test219 is test do var md = """- one\n\n two\n""" assert md_to_md(md) == md end fun test221 is test do var md = """ - one\n\n two\n""" var exp = """- one\n\n two\n""" assert md_to_md(md) == exp end # FIXME # fun test223 is test do # var md = """>>- one\n>>\n > > two\n""" # var exp = """> > - one\n> >\n> > two\n""" # assert md_to_md(md) == exp # end fun test225 is test do var md = """- foo\n\n bar\n""" assert md_to_md(md) == md end fun test228 is test do var md = """123456789. ok\n""" assert md_to_md(md) == md end fun test230 is test do var md = """0. ok\n""" assert md_to_md(md) == md end fun test246 is test do var md = """1. foo\n2.\n3. bar\n""" assert md_to_md(md) == md end fun test254 is test do var md = """ 1. A paragraph\n with two lines.\n""" var exp = """1. A paragraph\n with two lines.\n""" assert md_to_md(md) == exp end # FIXME # fun test255 is test do # var md = """> 1. > Blockquote\n> continued here.\n""" # var exp = """> 1. > Blockquote\n > continued here.\n""" # assert md_to_md(md) == exp # end end class TestMdFencedCodeBlocks super TestMarkdownMd test fun test88 is test do var md = """```\nfoo\n```\n""" assert md_to_md(md) == md end fun test92 is test do var md = """~~~\nfoo\n~~~\n""" assert md_to_md(md) == md end fun test111 is test do var md = """```ruby\ndef foo(x)\n return 3\nend\n```\n""" assert md_to_md(md) == md end fun test112 is test do var md = """~~~~~~\nSome markdown:\n~~~\n**hello**\n~~~\n~~~~~~\n""" assert md_to_md(md) == md end end class TestMdIndentedCodeBlocks super TestMarkdownMd test fun test75 is test do var md = """ a code block\n""" assert md_to_md(md) == md end fun test76 is test do var md = """ a simple\n indented code block\n""" assert md_to_md(md) == md end fun test80 is test do var md = """ chunk1\n\n chunk2\n \n \n \n chunk3\n""" assert md_to_md(md) == """ chunk1\n\n chunk2\n\n\n\n chunk3\n""" end fun test85 is test do var md = """ foo\n bar\n""" assert md_to_md(md) == md end fun test87 is test do var md = """\t\tfoo \n""" assert md_to_md(md) == md end end class TestMdThematicBreaks super TestMarkdownMd test fun test13 is test do var md = """***\n---\n___\n""" var exp = """***\n\n---\n\n___\n""" assert md_to_md(md) == exp end fun test17 is test do var md = """ ***\n ***\n ***\n""" var exp = """***\n\n***\n\n***\n""" assert md_to_md(md) == exp end fun test20 is test do var md = """_____________________________________\n""" assert md_to_md(md) == md end fun test21 is test do var md = """ - - -\n""" var exp = """- - -\n""" assert md_to_md(md) == exp end fun test22 is test do var md = """ ** * ** * ** * **\n""" var exp = """** * ** * ** * **\n""" assert md_to_md(md) == exp end fun test23 is test do var md = """- - - -\n""" assert md_to_md(md) == md end end class TestMdParagraphs super TestMarkdownMd test fun test182 is test do var md = """aaa\n\nbbb\n""" assert md_to_md(md) == md end fun test183 is test do var md = """aaa\nbbb\n\nccc\nddd\n""" assert md_to_md(md) == md end fun test186 is test do var md = """aaa\n bbb\n ccc\n""" var exp = """aaa\nbbb\nccc\n""" assert md_to_md(md) == exp end fun test187 is test do var md = """ aaa\nbbb\n""" var exp = """aaa\nbbb\n""" assert md_to_md(md) == exp end end class TestMdHTMLBlocks super TestMarkdownMd test fun test116 is test do var md = """
\n\n*Hello*,\n\n_world_.\n\n\n |
\nimport Text.HTML.TagSoup\n\nmain :: IO ()\nmain = print $ parseTags tags\n
\n"""
assert md_to_md(md) == md
end
fun test138 is test do
var md = """\n"""
assert md_to_md(md) == md
end
fun test139 is test do
var md = """\n"""
assert md_to_md(md) == md
end
fun test149 is test do
var md = """\n"""
assert md_to_md(md) == md
end
fun test150 is test do
var md = """ \n\n \n"""
assert md_to_md(md) == md
end
end
# Inlines
class TestMdLinks
super TestMarkdownMd
test
fun test_autolink is test do
var md = """