# 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. # Markdown tests from DaringFireball # # See . module test_markdown_daring is test import test_markdown class TestMarkdownDaring super TestMarkdownHtml test fun test_daring_encoding is test do var md = """ AT&T has an ampersand in their name. AT&T is another way to write it. This & that. 4 < 5. 6 > 5. Here's a [link][1] with an ampersand in the URL. Here's a link with an ampersand in the link text: [AT&T][2]. Here's an inline [link](/script?foo=1&bar=2). Here's an inline [link](). [1]: http://example.com/?foo=1&bar=2 [2]: http://att.com/ "AT&T" """ var html = """

AT&T has an ampersand in their name.

AT&T is another way to write it.

This & that.

4 < 5.

6 > 5.

Here's a link with an ampersand in the URL.

Here's a link with an ampersand in the link text: AT&T.

Here's an inline link.

Here's an inline link.

""" assert md_to_html(md) == html end fun test_daring_autolinks is test do var md = """ Link: . With an ampersand: * In a list? * * It should. > Blockquoted: Auto-links should not occur here: `` or here: """ var html = """

Link: http://example.com/.

With an ampersand: http://example.com/?foo=1&bar=2

Blockquoted: http://example.com/

Auto-links should not occur here: <http://example.com/>

or here: <http://example.com/>
""" assert md_to_html(md) == html end fun test_daring_escape is test do var md = """ These should all get escaped: Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: \{ Right brace: \} Left bracket: \[ Right bracket: \] Left paren: \( Right paren: \) Greater-than: \> Hash: \# Period: \. Bang: \! Plus: \+ Minus: \- These should not, because they occur within a code block: Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: \{ Right brace: \} Left bracket: \[ Right bracket: \] Left paren: \( Right paren: \) Greater-than: \> Hash: \# Period: \. Bang: \! Plus: \+ Minus: \- Nor should these, which occur in code spans: Backslash: `\\` Backtick: `` \` `` Asterisk: `\*` Underscore: `\_` Left brace: `\{` Right brace: `\}` Left bracket: `\[` Right bracket: `\]` Left paren: `\(` Right paren: `\)` Greater-than: `\>` Hash: `\#` Period: `\.` Bang: `\!` Plus: `\+` Minus: `\-` These should get escaped, even though they're matching pairs for other Markdown constructs: \\\*asterisks\\\* \\\_underscores\\\_ \\\`backticks\\\` This is a code span with a literal backslash-backtick sequence: `` \` `` This is a tag with unescaped backticks bar. This is a tag with backslashes bar. """ var html = """

These should all get escaped:

Backslash: \\

Backtick: \`

Asterisk: \*

Underscore: \_

Left brace: \{

Right brace: \}

Left bracket: \[

Right bracket: \]

Left paren: \(

Right paren: \)

Greater-than: >

Hash: \#

Period: \.

Bang: \!

Plus: \+

Minus: \-

These should not, because they occur within a code block:

Backslash: \\

Backtick: \`

Asterisk: \*

Underscore: \_

Left brace: \{

Right brace: \}

Left bracket: \[

Right bracket: \]

Left paren: \(

Right paren: \)

Greater-than: \>

Hash: \#

Period: \.

Bang: \!

Plus: \+

Minus: \-

Nor should these, which occur in code spans:

Backslash: \\

Backtick: \`

Asterisk: \*

Underscore: \_

Left brace: \{

Right brace: \}

Left bracket: \[

Right bracket: \]

Left paren: \(

Right paren: \)

Greater-than: \>

Hash: \#

Period: \.

Bang: \!

Plus: \+

Minus: \-

These should get escaped, even though they're matching pairs for other Markdown constructs:

*asterisks*

_underscores_

`backticks`

This is a code span with a literal backslash-backtick sequence: \`

This is a tag with unescaped backticks bar.

This is a tag with backslashes bar.

""" assert md_to_html(md) == html end fun test_daring_blockquotes is test do var md = """ > Example: > > sub status { > print "working"; > } > > Or: > > sub status { > return "working"; > } """ var html = """

Example:

sub status {
    print "working";
}

Or:

sub status {
    return "working";
}
""" assert md_to_html(md) == html end fun test_daring_code_blocks is test do var md = """ code block on the first line Regular text. code block indented by spaces Regular text. the lines in this block all contain trailing spaces Regular Text. code block on the last line """ var html = """
code block on the first line

Regular text.

code block indented by spaces

Regular text.

the lines in this block
all contain trailing spaces

Regular Text.

code block on the last line
""" assert md_to_html(md) == html end fun test_daring_rules is test do var md = """ Dashes: --- --- --- --- --- - - - - - - - - - - - - - - - Asterisks: *** *** *** *** *** * * * * * * * * * * * * * * * Underscores: ___ ___ ___ ___ ___ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ """ var html = """

Dashes:





---




- - -

Asterisks:





***




* * *

Underscores:





___




_ _ _
""" assert md_to_html(md) == html end fun test_daring_code_spans is test do var md = """ `` Fix for backticks within HTML tag: like this Here's how you put `` `backticks` `` in a code span. """ var html = """

<test a=" content of attribute ">

Fix for backticks within HTML tag: like this

Here's how you put `backticks` in a code span.

""" assert md_to_html(md) == html end fun test_daring_images is test do var md = """ ![Alt text](/path/to/img.jpg) ![Alt text](/path/to/img.jpg "Optional title") Inline within a paragraph: [alt text](/url/). ![alt text](/url/ "title preceded by two spaces") ![alt text](/url/ "title has spaces afterward" ) ![alt text]() ![alt text]( "with a title"). ![Empty]() ![this is a stupid URL](http://example.com/(parens).jpg) ![alt text][foo] [foo]: /url/ ![alt text][bar] [bar]: /url/ "Title here" """ var html = """

Alt text

Alt text

Inline within a paragraph: alt text.

alt text

alt text

alt text

alt text.

Empty

this is a stupid URL

alt text

alt text

""" assert md_to_html(md) == html end fun test_daring_links1 is test do var md = """ Just a [URL](/url/). [URL and title](/url/ "title"). [URL and title](/url/ "title preceded by two spaces"). [URL and title](/url/ "title preceded by a tab"). [URL and title](/url/ "title has spaces afterward" ). [URL wrapped in angle brackets](). [URL w/ angle brackets + title]( "Here's the title"). [Empty](). [With parens in the URL](http://en.wikipedia.org/wiki/WIMP_(computing)) (With outer parens and [parens in url](/foo(bar))) [With parens in the URL](/foo(bar) "and a title") (With outer parens and [parens in url](/foo(bar) "and a title")) """ var html = """

Just a URL.

URL and title.

URL and title.

URL and title.

URL and title.

URL wrapped in angle brackets.

URL w/ angle brackets + title.

Empty.

With parens in the URL

(With outer parens and parens in url)

With parens in the URL

(With outer parens and parens in url)

""" assert md_to_html(md) == html end fun test_daring_links2 is test do var md = """ Foo [bar][1]. Foo [bar][1]. Foo [bar][1]. [1]: /url/ "Title" With [embedded [brackets]][b]. Indented [once][]. Indented [twice][]. Indented [thrice][]. Indented [four][] times. [once]: /url [twice]: /url [thrice]: /url [four]: /url [b]: /url/ * * * [this][this] should work So should [this][this]. And [this][]. And [this][]. And [this]. But not [that][]. Nor [that][]. Nor [that]. [Something in brackets like [this][] should work] [Same with [this].] In this case, [this](/somethingelse/) points to something else. Backslashing should suppress \\\[this] and [this\\\]. [this]: foo * * * Here's one where the [link breaks] across lines. Here's another where the [link breaks] across lines, but with a line-ending space. [link breaks]: /url/ """ var html = """

Foo bar.

Foo bar.

Foo bar.

With embedded [brackets].

Indented once.

Indented twice.

Indented thrice.

Indented [four][] times.
[four]: /url

this should work

So should this.

And this.

And this.

And this.

But not [that][].

Nor [that][].

Nor [that].

[Something in brackets like this should work]

[Same with this.]

In this case, this points to something else.

Backslashing should suppress [this] and [this].


Here's one where the link breaks across lines.

Here's another where the link breaks across lines, but with a line-ending space.

""" assert md_to_html(md) == html end fun test_daring_links3 is test do var md = """ This is the [simple case]. [simple case]: /simple This one has a [line break]. This one has a [line break] with a line-ending space. [line break]: /foo [this][that] and the [other] [this]: /this [that]: /that [other]: /other """ var html = """

This is the simple case.

This one has a line break.

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

this and the other

""" assert md_to_html(md) == html end fun test_daring_nested is test do var md = """ > foo > > > bar > > foo """ var html = """

foo

bar

foo

""" assert md_to_html(md) == html end fun test_daring_tidyness is test do var md = """ > A list within a blockquote: > > * asterisk 1 > * asterisk 2 > * asterisk 3 """ var html = """

A list within a blockquote:

  • asterisk 1
  • asterisk 2
  • asterisk 3
""" assert md_to_html(md) == html end fun test_daring_list is test do var md = """ ## Unordered Asterisks tight: * asterisk 1 * asterisk 2 * asterisk 3 Asterisks loose: * asterisk 1 * asterisk 2 * asterisk 3 * * * Pluses tight: + Plus 1 + Plus 2 + Plus 3 Pluses loose: + Plus 1 + Plus 2 + Plus 3 * * * Minuses tight: - Minus 1 - Minus 2 - Minus 3 Minuses loose: - Minus 1 - Minus 2 - Minus 3 ## Ordered Tight: 1. First 2. Second 3. Third and: 1. One 2. Two 3. Three Loose using tabs: 1. First 2. Second 3. Third and using spaces: 1. One 2. Two 3. Three Multiple paragraphs: 1. Item 1, graf one. Item 2. graf two. The quick brown fox jumped over the lazy dog's back. 2. Item 2. 3. Item 3. ## Nested * Tab * Tab * Tab Here's another: 1. First 2. Second: * Fee * Fie * Foe 3. Third Same thing but with paragraphs: 1. First 2. Second: * Fee * Fie * Foe 3. Third """ var html = """

Unordered

Asterisks tight:

  • asterisk 1
  • asterisk 2
  • asterisk 3

Asterisks loose:

  • asterisk 1

  • asterisk 2

  • asterisk 3


Pluses tight:

  • Plus 1
  • Plus 2
  • Plus 3

Pluses loose:

  • Plus 1

  • Plus 2

  • Plus 3


Minuses tight:

  • Minus 1
  • Minus 2
  • Minus 3

Minuses loose:

  • Minus 1

  • Minus 2

  • Minus 3

Ordered

Tight:

  1. First
  2. Second
  3. Third

and:

  1. One
  2. Two
  3. Three

Loose using tabs:

  1. First

  2. Second

  3. Third

and using spaces:

  1. One

  2. Two

  3. Three

Multiple paragraphs:

  1. Item 1, graf one.

    Item 2. graf two. The quick brown fox jumped over the lazy dog's back.

  2. Item 2.

  3. Item 3.

Nested

  • Tab
    • Tab
      • Tab

Here's another:

  1. First
  2. Second:
    • Fee
    • Fie
    • Foe
  3. Third

Same thing but with paragraphs:

  1. First

  2. Second:

    • Fee
    • Fie
    • Foe
  3. Third

""" assert md_to_html(md) == html end fun test_daring_strong_em is test do var md = """ ***This is strong and em.*** So is ***this*** word. ___This is strong and em.___ So is ___this___ word. """ var html = """

This is strong and em.

So is this word.

This is strong and em.

So is this word.

""" assert md_to_html(md) == html end fun test_daring_tabs is test do var md = """ + this is a list item indented with tabs + this is a list item indented with spaces Code: this code block is indented by one tab And: this code block is indented by two tabs And: + this is an example list item indented with tabs + this is an example list item indented with spaces """ var html = """
  • this is a list item indented with tabs

  • this is a list item indented with spaces

Code:

this code block is indented by one tab

And:

	this code block is indented by two tabs

And:

+	this is an example list item
	indented with tabs

+   this is an example list item
    indented with spaces
""" assert md_to_html(md) == html end fun test_daring_inline_html1 is test do var md = """ Here's a simple block:
foo
This should be a code block, though:
foo
As should this:
foo
Now, nested:
foo
This should just be an HTML comment: Multiline: Code block: Just plain comment, with trailing spaces on the line: Code:
Hr's:








""" var html = """

Here's a simple block:

foo

This should be a code block, though:

<div>
	foo
</div>

As should this:

<div>foo</div>

Now, nested:

foo

This should just be an HTML comment:

Multiline:

Code block:

<!-- Comment -->

Just plain comment, with trailing spaces on the line:

Code:

<hr />

Hr's:










""" assert md_to_html(md) == html end fun test_daring_inline_html2 is test do var md = """ Simple block on one line:
foo
And nested without indentation:
foo
bar
And with attributes:
This was broken in 1.0.2b7:
foo
""" var html = """

Simple block on one line:

foo

And nested without indentation:

foo
bar

And with attributes:

This was broken in 1.0.2b7:

foo
""" assert md_to_html(md) == html end fun test_daring_inline_html3 is test do var md = """ Paragraph one. Paragraph two. The end. """ var html = """

Paragraph one.

Paragraph two.

The end.

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