From 05b0c04b6d2b57a7d4c960a72a70e780914c4401 Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Thu, 15 Dec 2016 16:13:24 +0200 Subject: [PATCH] Update format tests --- test/formatter_test.jl | 52 +++++++++++++++++++++++++++++++++++++++++ test/templates/mini.tpl | 2 ++ 2 files changed, 54 insertions(+) create mode 100644 test/templates/mini.tpl diff --git a/test/formatter_test.jl b/test/formatter_test.jl index 8575cfa..620337f 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -19,13 +19,65 @@ f_check = "

Test chunk

Test rendering \$\alpha\$

f = Weave.format_chunk(dchunk, docformat.formatdict, docformat) @test f_check == f +# Test with actual doc + parsed = Weave.read_doc("documents/chunk_options.noweb") doc = Weave.run(parsed, doctype = "md2html") c_check = "
\nx = [12, 10]\nprintln(y)\n
\n" +doc.format.formatdict[:theme] = doc.highlight_theme c = Weave.format_code(doc.chunks[4].content, doc.format) @test c_check == c o_check = "\nx = [12, 10]\nprintln(y)\n" o = Weave.format_output(doc.chunks[4].content, doc.format) @test o_check == o + +doc.template = "templates/mini.tpl" +rendered = Weave.render_doc("Hello", doc, doc.format) +@test rendered == "\nHello\n" + +# Tex format +parsed = Weave.read_doc("documents/chunk_options.noweb") +doc = Weave.run(parsed, doctype = "md2tex") + +c_check = "\\begin{lstlisting}\n(*@\\HLJLn{x}@*) (*@\\HLJLoB{=}@*) (*@\\HLJLp{[}@*)(*@\\HLJLni{12}@*)(*@\\HLJLp{,}@*) (*@\\HLJLni{10}@*)(*@\\HLJLp{]}@*)\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{y}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n" +doc.format.formatdict[:theme] = doc.highlight_theme +c = Weave.format_code(doc.chunks[4].content, doc.format) +@test c_check == c + +o_check = "\nx = [12, 10]\nprintln(y)\n" +o = Weave.format_output(doc.chunks[4].content, doc.format) +@test o_check == o + +doc.template = "templates/mini.tpl" +rendered = Weave.render_doc("Hello", doc, doc.format) +@test rendered == "\nHello\n" + + +# Test header parsing and stripping +header = """ +--- +title : Test block +author : Matti Pastell +--- + +# Actual header + +and some text + +""" + +dchunk = Weave.DocChunk(header, 1, 1) +h = Weave.parse_header(dchunk) +h_ref = Dict("author" => "Matti Pastell", "title" => "Test block") +@test h_ref == h + +htext = Weave.strip_header(dchunk) +h_ref = """ +# Actual header + +and some text + +""" +@test htext.content == h_ref diff --git a/test/templates/mini.tpl b/test/templates/mini.tpl new file mode 100644 index 0000000..6279a0f --- /dev/null +++ b/test/templates/mini.tpl @@ -0,0 +1,2 @@ + +{{{ :body }}}