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 express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Tests for markdown Wikilinks mode
16 module test_markdown_wikilinks
is test
19 import test_markdown_location
20 import test_markdown_md
21 import test_markdown_man
22 import test_markdown_latex
24 redef class TestMarkdown
25 redef var md_parser
do
27 parser
.wikilinks_mode
= true
32 class TestWikilinksLocation
33 super TestMarkdownLocation
36 fun test_wikilinks1
is test
do
38 A [[wiki link]] and text.
42 MdParagraph: 1,1--1,25
48 assert md_to_loc
(md
) == loc
51 fun test_wikilinks2
is test
do
53 A [[wiki: link | with: more, args: end]] and text.
57 MdParagraph: 1,1--1,50
63 assert md_to_loc
(md
) == loc
68 class TestWikilinksHtml
69 super TestMarkdownHtml
72 fun test_wikilinks1
is test
do
73 var md
= """[[foo]]\n"""
74 var html
= """<p><wiki link="foo">foo</wiki></p>\n"""
75 assert md_to_html
(md
) == html
78 fun test_wikilinks2
is test
do
79 var md
= """[[foo | bar baz]]\n"""
80 var html
= """<p><wiki link="bar%20baz">foo</wiki></p>\n"""
81 assert md_to_html
(md
) == html
84 fun test_wikilinks3
is test
do
85 var md
= """This is a [[link]] and this is another [[one]].\n"""
86 var html
= """<p>This is a <wiki link="link">link</wiki> and this is another <wiki link="one">one</wiki>.</p>\n"""
87 assert md_to_html
(md
) == html
90 fun test_wikilinks4
is test
do
91 var md
= """[[very: complex | link: with, more: options]]\n"""
92 var html
= """<p><wiki link="link:%20with,%20more:%20options">very: complex</wiki></p>\n"""
93 assert md_to_html
(md
) == html
96 fun test_wikilink_bad1
is test
do
97 var md
= """Not a [wikilink]].\n"""
98 var html
= """<p>Not a [wikilink]].</p>\n"""
99 assert md_to_html
(md
) == html
102 fun test_wikilink_bad2
is test
do
103 var md
= """Not a [[wikilink].\n"""
104 var html
= """<p>Not a [[wikilink].</p>\n"""
105 assert md_to_html
(md
) == html
108 fun test_wikilink_bad3
is test
do
109 var md
= """Not a ![[wikilink]].\n"""
110 var html
= """<p>Not a ![[wikilink]].</p>\n"""
111 assert md_to_html
(md
) == html
114 fun test_wikilink_bad4
is test
do
115 var md
= """Not a [wikilink].\n"""
116 var html
= """<p>Not a [wikilink].</p>\n"""
117 assert md_to_html
(md
) == html
120 fun test_link
is test
do
121 var md
= """A standard [link](url).\n"""
122 var html
= """<p>A standard <a href="url">link</a>.</p>\n"""
123 assert md_to_html
(md
) == html
126 fun test_image
is test
do
127 var md
= """A standard ![image](url).\n"""
128 var html
= """<p>A standard <img src="url" alt="image" />.</p>\n"""
129 assert md_to_html
(md
) == html
132 fun test_link_ref1
is test
do
133 var md
= """A standard [link definition].\n\n[link definition]: url\n"""
134 var html
= """<p>A standard <a href="url">link definition</a>.</p>\n"""
135 assert md_to_html
(md
) == html
138 fun test_link_ref2
is test
do
139 var md
= """[[wikilinks]] are not \n\n[[link definition]]: url\n"""
140 var html
= """<p><wiki link="wikilinks">wikilinks</wiki> are not</p>\n<p><wiki link="link%20definition">link definition</wiki>: url</p>\n"""
141 assert md_to_html
(md
) == html
145 class TestWikilinksMd
149 fun test_wikilinks_md1
is test
do
150 var md
= """[[foo]]\n"""
151 assert md_to_md
(md
) == md
154 fun test_wikilinks_md2
is test
do
155 var md
= """[[foo: bar | baz: b, c: d]]\n"""
156 assert md_to_md
(md
) == md
160 class TestWikilinksMan
161 super TestMarkdownMan
164 fun test_wikilinks_man
is test
do
165 var md
= """[[foo]]\n"""
166 var man
= """\n(foo)\n"""
167 assert md_to_man
(md
) == man
171 class TestWikilinksLatex
172 super TestMarkdownLatex
175 fun test_wikilinks_latex
is test
do
176 var md
= """[[foo]]\n"""
177 var tex
= """\\texttt{foo}\n"""
178 assert md_to_tex
(md
) == tex