1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either htmlress or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Tests for markdown inline constructs
16 module test_markdown_inlines
is test
20 class TestMarkdownInlines
21 super TestMarkdownHtml
24 fun test_inlines_emph1
is test
do
32 __double underscores__
34 var html
= """<p><em>single asterisks</em></p>
35 <p><em>single underscores</em></p>
36 <p><strong>double asterisks</strong></p>
37 <p><strong>double underscores</strong></p>
39 assert md_to_html
(md
) == html
42 fun test_inlines_emph2
is test
do
43 var md
= "un*frigging*believable"
44 var html
= "<p>un<em>frigging</em>believable</p>\n"
45 assert md_to_html
(md
) == html
48 fun test_inlines_emph3
is test
do
49 var md
= "Con _cat_ this"
50 var html
= "<p>Con <em>cat</em> this</p>\n"
51 assert md_to_html
(md
) == html
54 fun test_inlines_emph_ext
is test
do
55 var md
= "Con_cat_this"
56 var html
= "<p>Con_cat_this</p>\n"
57 assert md_to_html
(md
) == html
60 fun test_inlines_xml1
is test
do
62 This is a regular paragraph.
70 This is another regular paragraph.
73 <p>This is a regular paragraph.</p>
79 <p>This is another regular paragraph.</p>
81 assert md_to_html
(md
) == html
84 fun test_inlines_xml2
is test
do
86 This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.
89 <p>This is an image <img src="foo/bar" alt="baz"/> in a regular paragraph.</p>
91 assert md_to_html
(md
) == html
94 fun test_inlines_xml3
is test
do
101 assert md_to_html
(md
) == html
104 fun test_inlines_xml4
is test
do
106 <p>This is an example of a block element that should be escaped.</p>
107 <p>Idem for the second paragraph.</p>
109 assert md_to_html
(md
) == md
112 fun test_inlines_xml5
is test
do
114 # Some more XML tests
116 <p>This is an example of a block element that should be escaped.</p>
117 <p>Idem for the second paragraph.</p>
119 With a *md paragraph*!
122 <h1>Some more XML tests</h1>
123 <p>This is an example of a block element that should be escaped.</p>
124 <p>Idem for the second paragraph.</p>
125 <p>With a <em>md paragraph</em>!</p>
127 assert md_to_html
(md
) == html
130 fun test_escape_bad_html
is test
do
131 var md
= "-1 if < , +1 if > and 0 otherwise"
132 var html
= "<p>-1 if < , +1 if > and 0 otherwise</p>\n"
133 assert md_to_html
(md
) == html
136 fun test_inlines_span_code1
is test
do
137 var md
= "Use the `printf()` function."
138 var html
= "<p>Use the <code>printf()</code> function.</p>\n"
139 assert md_to_html
(md
) == html
142 fun test_inlines_span_code2
is test
do
143 var md
= "``There is a literal backtick (`) here.``"
144 var html
= "<p><code>There is a literal backtick (`) here.</code></p>\n"
145 assert md_to_html
(md
) == html
148 fun test_inlines_span_code3
is test
do
150 A single backtick in a code span: `` ` ``
152 A backtick-delimited string in a code span: `` `foo` ``
155 <p>A single backtick in a code span: <code>`</code></p>
156 <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
158 assert md_to_html
(md
) == html
161 fun test_inlines_span_code4
is test
do
162 var md
= "Please don't use any `<blink>` tags."
163 var html
= "<p>Please don't use any <code><blink></code> tags.</p>\n"
164 assert md_to_html
(md
) == html
167 fun test_inlines_span_code5
is test
do
168 var md
= "`—` is the decimal-encoded equivalent of `—`."
169 var html
= "<p><code>&#8212;</code> is the decimal-encoded equivalent of <code>&mdash;</code>.</p>\n"
170 assert md_to_html
(md
) == html
173 fun test_inlines_escape1
is test
do
174 var md
= "\\*this text is surrounded by literal asterisks\\*"
175 var html
= "<p>*this text is surrounded by literal asterisks*</p>\n"
176 assert md_to_html
(md
) == html
179 fun test_inlines_escape2
is test
do
180 var md
= "1986\\. What a great season."
181 var html
= "<p>1986. What a great season.</p>\n"
182 assert md_to_html
(md
) == html
185 fun test_inlines_escape3
is test
do
187 var html
= "<p>Ben & Lux</p>\n"
188 assert md_to_html
(md
) == html
191 fun test_inlines_link1
is test
do
193 This is [an example](http://example.com/ "Title") inline link.
195 [This link](http://example.net/) has no title attribute.
197 var html
= """<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
198 <p><a href="http://example.net/">This link</a> has no title attribute.</p>
200 assert md_to_html
(md
) == html
203 fun test_inlines_link2
is test
do
204 var md
= "See my [About](/about/) page for details."
205 var html
= "<p>See my <a href=\"/about
/\
">About</a> page for details.</p>\n"
206 assert md_to_html
(md
) == html
209 fun test_inlines_link3
is test
do
211 This is [an example][id] reference-style link.
215 [id]: http://example.com/ "Optional Title Here"
220 <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
221 <p>Some lorem ipsum</p>
222 <p>Some other lipsum</p>
224 assert md_to_html
(md
) == html
227 fun test_inlines_link4
is test
do
229 This is multiple examples: [foo][1], [bar][2], [baz][3].
231 [1]: http://example.com/ "Optional Title Here"
232 [2]: http://example.com/ 'Optional Title Here'
233 [3]: http://example.com/ (Optional Title Here)
236 <p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">baz</a>.</p>
238 assert md_to_html
(md
) == html
241 fun test_inlines_link5
is test
do
243 This is multiple examples: [foo][a], [bar][A], [a].
245 [a]: http://example.com/ "Optional Title Here"
247 var html
= """<p>This is multiple examples: <a href="http://example.com/" title="Optional Title Here">foo</a>, <a href="http://example.com/" title="Optional Title Here">bar</a>, <a href="http://example.com/" title="Optional Title Here">a</a>.</p>
249 assert md_to_html
(md
) == html
252 fun test_inlines_link6
is test
do
254 I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][].
256 [Google]: http://google.com/ "Google"
257 [Yahoo]: http://search.yahoo.com/ "Yahoo Search"
258 [MSN]: http://search.msn.com/ "MSN Search"
260 var html
= """<p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
262 assert md_to_html
(md
) == html
265 fun test_inlines_link7
is test
do
267 Visit [Daring Fireball][] for more information.
269 [Daring Fireball]: http://daringfireball.net/
271 var html
= """<p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
273 assert md_to_html
(md
) == html
276 fun test_inlines_link8
is test
do
282 break] with a line-ending space.
287 <p>This one has a <a href="/foo">line
289 <p>This one has a <a href="/foo">line
290 break</a> with a line-ending space.</p>
292 assert md_to_html
(md
) == html
295 fun test_inlines_link9
is test
do
299 Foo [bar](/url/ "Title with \\"quotes\\" inside").
302 [bar]: /url/ "Title with \\"quotes\\" inside"
305 <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
306 <p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
308 assert md_to_html
(md
) == html
311 fun test_inlines_img1
is test
do
313 ![Alt text](/path/to/img.jpg)
315 ![Alt text](/path/to/img.jpg "Optional title")
318 <p><img src="/path/to/img.jpg" alt="Alt text" /></p>
319 <p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
321 assert md_to_html
(md
) == html
324 fun test_inlines_img2
is test
do
328 [id]: url/to/image "Optional title attribute"
331 <p><img src="url/to/image" alt="Alt text" title="Optional title attribute" /></p>
333 assert md_to_html
(md
) == html