# 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 htmlress or implied. # See the License for the specific language governing permissions and # limitations under the License. # Tests for markdown inline constructs module test_markdown_inlines is test import test_markdown class TestMarkdownInlines super TestMarkdownHtml test fun test_inlines_emph1 is test do var md = """ *single asterisks* _single underscores_ **double asterisks** __double underscores__ """ var html = """

single asterisks

single underscores

double asterisks

double underscores

""" assert md_to_html(md) == html end fun test_inlines_emph2 is test do var md = "un*frigging*believable" var html = "

unfriggingbelievable

\n" assert md_to_html(md) == html end fun test_inlines_emph3 is test do var md = "Con _cat_ this" var html = "

Con cat this

\n" assert md_to_html(md) == html end fun test_inlines_emph_ext is test do var md = "Con_cat_this" var html = "

Con_cat_this

\n" assert md_to_html(md) == html end fun test_inlines_xml1 is test do var md = """ This is a regular paragraph.
Foo
This is another regular paragraph. """ var html = """

This is a regular paragraph.

Foo

This is another regular paragraph.

""" assert md_to_html(md) == html end fun test_inlines_xml2 is test do var md = """ This is an image baz in a regular paragraph. """ var html = """

This is an image baz in a regular paragraph.

""" assert md_to_html(md) == html end fun test_inlines_xml3 is test do var md = """
""" var html = """
""" assert md_to_html(md) == html end fun test_inlines_xml4 is test do var md = """

This is an example of a block element that should be escaped.

Idem for the second paragraph.

""" assert md_to_html(md) == md end fun test_inlines_xml5 is test do var md = """ # 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 html = """

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!

""" assert md_to_html(md) == html end fun test_escape_bad_html is test do var md = "-1 if < , +1 if > and 0 otherwise" var html = "

-1 if < , +1 if > and 0 otherwise

\n" assert md_to_html(md) == html end fun test_inlines_span_code1 is test do var md = "Use the `printf()` function." var html = "

Use the printf() function.

\n" assert md_to_html(md) == html end fun test_inlines_span_code2 is test do var md = "``There is a literal backtick (`) here.``" var html = "

There is a literal backtick (`) here.

\n" assert md_to_html(md) == html end fun test_inlines_span_code3 is test do var md = """ A single backtick in a code span: `` ` `` A backtick-delimited string in a code span: `` `foo` `` """ var html = """

A single backtick in a code span: `

A backtick-delimited string in a code span: `foo`

""" assert md_to_html(md) == html end fun test_inlines_span_code4 is test do var md = "Please don't use any `` tags." var html = "

Please don't use any <blink> tags.

\n" assert md_to_html(md) == html end fun test_inlines_span_code5 is test do var md = "`—` is the decimal-encoded equivalent of `—`." var html = "

&#8212; is the decimal-encoded equivalent of &mdash;.

\n" assert md_to_html(md) == html end fun test_inlines_escape1 is test do var md = "\\*this text is surrounded by literal asterisks\\*" var html = "

*this text is surrounded by literal asterisks*

\n" assert md_to_html(md) == html end fun test_inlines_escape2 is test do var md = "1986\\. What a great season." var html = "

1986. What a great season.

\n" assert md_to_html(md) == html end fun test_inlines_escape3 is test do var md = "Ben & Lux" var html = "

Ben & Lux

\n" assert md_to_html(md) == html end fun test_inlines_link1 is test do var md = """ This is [an example](http://example.com/ "Title") inline link. [This link](http://example.net/) has no title attribute. """ var html = """

This is an example inline link.

This link has no title attribute.

""" assert md_to_html(md) == html end fun test_inlines_link2 is test do var md = "See my [About](/about/) page for details." var html = "

See my About page for details.

\n" assert md_to_html(md) == html end fun test_inlines_link3 is test do var md = """ This is [an example][id] reference-style link. Some lorem ipsum [id]: http://example.com/ "Optional Title Here" Some other lipsum """ var html = """

This is an example reference-style link.

Some lorem ipsum

Some other lipsum

""" assert md_to_html(md) == html end fun test_inlines_link4 is test do var md = """ This is multiple examples: [foo][1], [bar][2], [baz][3]. [1]: http://example.com/ "Optional Title Here" [2]: http://example.com/ 'Optional Title Here' [3]: http://example.com/ (Optional Title Here) """ var html = """

This is multiple examples: foo, bar, baz.

""" assert md_to_html(md) == html end fun test_inlines_link5 is test do var md = """ This is multiple examples: [foo][a], [bar][A], [a]. [a]: http://example.com/ "Optional Title Here" """ var html = """

This is multiple examples: foo, bar, a.

""" assert md_to_html(md) == html end fun test_inlines_link6 is test do var md = """ I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [Google]: http://google.com/ "Google" [Yahoo]: http://search.yahoo.com/ "Yahoo Search" [MSN]: http://search.msn.com/ "MSN Search" """ var html = """

I get 10 times more traffic from Google than from Yahoo or MSN.

""" assert md_to_html(md) == html end fun test_inlines_link7 is test do var md = """ Visit [Daring Fireball][] for more information. [Daring Fireball]: http://daringfireball.net/ """ var html = """

Visit Daring Fireball for more information.

""" assert md_to_html(md) == html end fun test_inlines_link8 is test do var md = """ This one has a [line break]. This one has a [line break] with a line-ending space. [line break]: /foo """ var html = """

This one has a line break.

This one has a line break with a line-ending space.

""" assert md_to_html(md) == html end fun test_inlines_link9 is test do var md = """ Foo [bar][]. Foo [bar](/url/ "Title with \\"quotes\\" inside"). [bar]: /url/ "Title with \\"quotes\\" inside" """ var html = """

Foo bar.

Foo bar.

""" assert md_to_html(md) == html end fun test_inlines_img1 is test do var md = """ ![Alt text](/path/to/img.jpg) ![Alt text](/path/to/img.jpg "Optional title") """ var html = """

Alt text

Alt text

""" assert md_to_html(md) == html end fun test_inlines_img2 is test do var md = """ ![Alt text][id] [id]: url/to/image "Optional title attribute" """ var html = """

Alt text

""" assert md_to_html(md) == html end end