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 rendering to LaTeX
16 module test_markdown_latex
is test
19 import markdown_latex_rendering
21 # Abstract test class that defines the test methods for LaTeX rendering
22 abstract class TestMarkdownLatex
25 # LaTeX renderer used in tests
26 var tex_renderer
= new LatexRenderer
28 # Render the `md` string as LaTeX format
29 fun md_to_tex
(md
: String): String do
30 var node
= parse_md
(md
)
31 return tex_renderer
.render
(node
)
35 class TestLatexRendering
36 super TestMarkdownLatex
39 fun after_test
is after
do
40 tex_renderer
.wrap_document
= false
41 tex_renderer
.use_listings
= false
44 fun test_document_wrapper
is test
do
46 This example needs a document wrapper.
50 \\documentclass[letter,10pt]{article}
52 \\usepackage[utf8]{inputenc}
53 \\usepackage{hyperref}
54 \\usepackage{graphicx}
59 This example needs a document wrapper.
63 tex_renderer
.wrap_document
= true
64 assert md_to_tex
(md
) == tex
67 fun test_atx_headings
is test
do
81 \\subsubsection{Title 3}
85 \\subparagraph{Title 5}
89 assert md_to_tex
(md
) == tex
92 fun test_blockquotes
is test
do
103 assert md_to_tex
(md
) == tex
106 fun test_thematic_breaks
is test
do
111 \\begin{center}\\rule{3in}{0.4pt}\\end{center}
113 assert md_to_tex
(md
) == tex
116 fun test_paragraphs
is test
do
129 assert md_to_tex
(md
) == tex
132 fun test_html_block
is test
do
135 <a href="url">foo</a>
141 <a href="url">foo</a>
145 assert md_to_tex
(md
) == tex
148 fun test_indented_code
is test
do
159 assert md_to_tex
(md
) == tex
162 fun test_indented_code_with_listings
is test
do
173 tex_renderer
.use_listings
= true
174 assert md_to_tex
(md
) == tex
177 fun test_fenced_code
is test
do
190 assert md_to_tex
(md
) == tex
193 fun test_fenced_code_with_listings
is test
do
206 tex_renderer
.use_listings
= true
207 assert md_to_tex
(md
) == tex
210 fun test_fenced_code_with_listings_and_language
is test
do
218 \\begin{lstlisting}[language=c]
223 tex_renderer
.use_listings
= true
224 assert md_to_tex
(md
) == tex
227 fun test_list_ordered
is test
do
240 assert md_to_tex
(md
) == tex
243 fun test_list_ordered_with_starting_number
is test
do
250 \\setcounter{enumi}{4}
257 assert md_to_tex
(md
) == tex
260 fun test_list_unordered
is test
do
273 assert md_to_tex
(md
) == tex
276 fun test_list_nested
is test
do
297 assert md_to_tex
(md
) == tex
300 fun test_ordered_list_nested
is test
do
316 \\setcounter{enumi}{4}
322 \\setcounter{enumii}{4}
328 \\setcounter{enumiii}{4}
334 \\setcounter{enumiv}{4}
344 assert md_to_tex
(md
) == tex
347 fun test_list_and_blockquote
is test
do
366 assert md_to_tex
(md
) == tex
369 fun test_blockquote_and_list
is test
do
388 assert md_to_tex
(md
) == tex
391 fun test_code
is test
do
396 An \\texttt{inline code}.
398 assert md_to_tex
(md
) == tex
401 fun test_emphasis
is test
do
403 An *emphasis* and a **strong emphasis**.
406 An \\textit{emphasis} and a \\textbf{strong emphasis}.
408 assert md_to_tex
(md
) == tex
411 fun test_autolink
is test
do
418 assert md_to_tex
(md
) == tex
421 fun test_link
is test
do
426 A \\href{url/}{link}.
428 assert md_to_tex
(md
) == tex
431 fun test_link_with_title
is test
do
433 A [link](url/ "with a title").
436 A \\href{url/}{link (with a title)}.
438 assert md_to_tex
(md
) == tex
441 fun test_image
is test
do
446 \\includegraphics{url/}.
448 assert md_to_tex
(md
) == tex
451 fun test_softbreak
is test
do
460 assert md_to_tex
(md
) == tex
463 fun test_hardbreak
is test
do
472 assert md_to_tex
(md
) == tex
475 fun test_escaped
is test
do
482 assert md_to_tex
(md
) == tex
485 fun test_forbidden_chars
is test
do
490 \\%\\$\\{\\_\\textgreater\\textless\\#\\&\\}\\textbackslash
492 assert md_to_tex
(md
) == tex
495 fun test_full_document
is test
do
520 \\subsection{Another title}
540 assert md_to_tex
(md
) == tex