mirror of https://github.com/mpastell/Weave.jl
add test for header processing
parent
17c2151d86
commit
6955ca6be2
|
@ -1,5 +1,5 @@
|
||||||
using Weave, Test
|
using Weave, Test
|
||||||
using Weave: run_doc
|
using Weave: WeaveDoc, run_doc
|
||||||
|
|
||||||
|
|
||||||
# TODO: add test for header processsing
|
# TODO: add test for header processsing
|
||||||
|
@ -9,7 +9,7 @@ using Weave: run_doc
|
||||||
function mock_doc(str, format = "markdown")
|
function mock_doc(str, format = "markdown")
|
||||||
f = tempname()
|
f = tempname()
|
||||||
write(f, str)
|
write(f, str)
|
||||||
return Weave.WeaveDoc(f, format)
|
return WeaveDoc(f, format)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,114 @@
|
||||||
using Weave.YAML
|
using Weave: separate_header_text, parse_header, specific_options!
|
||||||
|
|
||||||
# TODO:
|
# TODO: add test for header restoring (strip)
|
||||||
# - header stripping
|
|
||||||
# - header parsing from a Weave document
|
@testset "header separation" begin
|
||||||
|
|
||||||
|
header_body = """
|
||||||
|
options:
|
||||||
|
foo: bar
|
||||||
|
"""
|
||||||
|
|
||||||
|
let
|
||||||
|
header_text = "---\n$header_body---"
|
||||||
|
f, l = separate_header_text("$header_text")
|
||||||
|
@test occursin(header_body, f)
|
||||||
|
@test isempty(l)
|
||||||
|
end
|
||||||
|
|
||||||
|
let
|
||||||
|
doc_body = "hogehoge"
|
||||||
|
header_text = "---\n$header_body---\n$doc_body"
|
||||||
|
f, l = separate_header_text("$header_text")
|
||||||
|
@test occursin(header_body, f)
|
||||||
|
@test occursin(doc_body, l)
|
||||||
|
end
|
||||||
|
|
||||||
|
let
|
||||||
|
slide_body = """
|
||||||
|
---
|
||||||
|
slide comes here !
|
||||||
|
---
|
||||||
|
"""
|
||||||
|
header_text = "---\n$header_body---\n$slide_body"
|
||||||
|
f, l = separate_header_text("$header_text")
|
||||||
|
@test occursin(header_body, f)
|
||||||
|
@test occursin(slide_body, l)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
header = YAML.load("""
|
@testset "dynamic header specifications" begin
|
||||||
|
|
||||||
|
let
|
||||||
|
d = mock_doc("""
|
||||||
|
---
|
||||||
|
title: No. `j 1`
|
||||||
|
---
|
||||||
|
""")
|
||||||
|
run_doc(d)
|
||||||
|
@test d.header["title"] == "No. 1"
|
||||||
|
end
|
||||||
|
|
||||||
|
let
|
||||||
|
m = Core.eval(Main, :(module $(gensym(:WeaveTest)) end))
|
||||||
|
|
||||||
|
# run in target module
|
||||||
|
@eval m n = 1
|
||||||
|
d = mock_doc("""
|
||||||
|
---
|
||||||
|
title: No. `j n`
|
||||||
|
---
|
||||||
|
""")
|
||||||
|
run_doc(d; mod = m)
|
||||||
|
@test d.header["title"] == "No. 1"
|
||||||
|
|
||||||
|
# strip quotes by default
|
||||||
|
@eval m s = "1"
|
||||||
|
d = mock_doc("""
|
||||||
|
---
|
||||||
|
title: No. `j s`
|
||||||
|
---
|
||||||
|
""")
|
||||||
|
run_doc(d; mod = m)
|
||||||
|
@test d.header["title"] == "No. 1" # otherwise `"No. "1""`
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@testset "doctype specific header configuration" begin
|
||||||
|
|
||||||
|
header = parse_header("""
|
||||||
---
|
---
|
||||||
options:
|
options:
|
||||||
out_path: reports
|
out_path: reports # should be overwrote
|
||||||
md2html:
|
md2html:
|
||||||
out_path : html/
|
out_path : html/
|
||||||
md2pdf:
|
md2pdf:
|
||||||
out_path : pdf/
|
out_path : pdf/
|
||||||
github:
|
github:
|
||||||
out_path : md/
|
out_path : md/
|
||||||
fig_ext : .png
|
fig_ext : .png # should remain
|
||||||
---
|
---
|
||||||
""")
|
""")
|
||||||
|
|
||||||
let args = header[Weave.WEAVE_OPTION_NAME]
|
weave_options = header[Weave.WEAVE_OPTION_NAME]
|
||||||
@test Weave.combine_args(args, "md2html") == Dict("fig_ext" => ".png", "out_path" => "html/")
|
|
||||||
@test Weave.combine_args(args, "github") == Dict("fig_ext" => ".png", "out_path" => "md/")
|
let md2html_options = copy(weave_options)
|
||||||
@test Weave.combine_args(args, "pandoc") == Dict("fig_ext" => ".png", "out_path" => "reports")
|
specific_options!(md2html_options, "md2html")
|
||||||
|
@test md2html_options == Dict("fig_ext" => ".png", "out_path" => "html/")
|
||||||
|
end
|
||||||
|
|
||||||
|
let md2pdf_options = copy(weave_options)
|
||||||
|
specific_options!(md2pdf_options, "md2pdf")
|
||||||
|
@test md2pdf_options == Dict("fig_ext" => ".png", "out_path" => "pdf/")
|
||||||
|
end
|
||||||
|
|
||||||
|
let github_options = copy(weave_options)
|
||||||
|
specific_options!(github_options, "github")
|
||||||
|
@test github_options == Dict("fig_ext" => ".png", "out_path" => "md/")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue