Weave.jl/test/test_converter.jl

32 lines
1.1 KiB
Julia
Raw Permalink Normal View History

2020-05-15 17:38:18 +02:00
# TODO: refactor
2016-12-12 18:54:02 +01:00
2018-01-03 08:13:58 +01:00
function convert_test(outfile, infile="documents/chunk_options.noweb")
2016-12-12 18:54:02 +01:00
outfile = joinpath("documents/convert", outfile)
convert_doc(infile, outfile)
result = read(outfile, String)
ref = read(outfile * ".ref", String)
2016-12-12 18:54:02 +01:00
@test result == ref
rm(outfile)
2016-12-12 18:54:02 +01:00
end
convert_test("chunk_options.jmd")
convert_test("chunk_options.jl")
convert_test("chunk_options.mdw")
2018-01-03 08:13:58 +01:00
convert_test("chunk_options_nb.mdw", "documents/chunk_options.ipynb")
2016-12-19 12:13:47 +01:00
# Separate test for notebook (output depends on julia version)
2020-05-15 17:38:18 +02:00
contents(chunk::Weave.DocChunk) = join([strip(c.content) for c in chunk.content], "")
contents(chunk::Weave.CodeChunk) = chunk.content
contents(doc::Weave.WeaveDoc) = join([contents(chunk) for chunk in doc.chunks], "")
2018-01-03 08:13:58 +01:00
outfile = "documents/convert/chunk_options.ipynb"
infile = "documents/chunk_options.noweb"
convert_doc(infile, outfile)
input = contents(Weave.WeaveDoc(infile))
output = contents(Weave.WeaveDoc(outfile))
2018-01-03 08:13:58 +01:00
@test input == output
2018-01-03 08:37:05 +01:00
rm(outfile)
2018-01-03 08:13:58 +01:00
2018-01-03 08:37:05 +01:00
# Test script reader
@test contents(Weave.WeaveDoc("documents/chunk_options.noweb")) == contents(Weave.WeaveDoc("documents/chunk_options.jl"))