mirror of https://github.com/mpastell/Weave.jl
add tests cases for RMarkdown styel chunk option passing
parent
b0db8b991c
commit
bb4ebb105e
|
@ -1,20 +0,0 @@
|
|||
using Weave
|
||||
using Test
|
||||
|
||||
cleanup = true
|
||||
|
||||
VER = "$(VERSION.major).$(VERSION.minor)"
|
||||
|
||||
Weave.push_preexecute_hook(identity)
|
||||
weave("documents/chunk_options.noweb")
|
||||
Weave.pop_preexecute_hook(identity)
|
||||
result = read("documents/chunk_options.md", String)
|
||||
ref = read("documents/chunk_options_ref.md", String)
|
||||
@test result == ref
|
||||
cleanup && rm("documents/chunk_options.md")
|
||||
|
||||
tangle("documents/chunk_options.noweb", out_path = "documents/tangle")
|
||||
result = read("documents/tangle/chunk_options.jl", String)
|
||||
ref = read("documents/tangle/chunk_options.jl.ref", String)
|
||||
@test ref == result
|
||||
cleanup && rm("documents/tangle/chunk_options.jl")
|
|
@ -16,3 +16,17 @@ rm(out)
|
|||
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl)
|
||||
@test read(out, String) == read(out*".ref", String)
|
||||
rm(out)
|
||||
|
||||
|
||||
@testset "chunk options" begin
|
||||
|
||||
result = read("documents/chunk_options.md", String)
|
||||
ref = read("documents/chunk_options_ref.md", String)
|
||||
@test result == ref
|
||||
|
||||
tangle("documents/chunk_options.noweb", out_path = "documents/tangle")
|
||||
result = read("documents/tangle/chunk_options.jl", String)
|
||||
ref = read("documents/tangle/chunk_options.jl.ref", String)
|
||||
@test ref == result
|
||||
|
||||
end
|
||||
|
|
|
@ -16,10 +16,6 @@ macro jmd_str(s) mock_doc(s) end
|
|||
|
||||
|
||||
@testset "Weave" begin
|
||||
@testset "Chunk options" begin
|
||||
include("chunk_options.jl")
|
||||
end
|
||||
|
||||
@testset "module evaluation" begin
|
||||
include("test_module_evaluation.jl")
|
||||
end
|
||||
|
@ -32,6 +28,10 @@ macro jmd_str(s) mock_doc(s) end
|
|||
include("test_inline.jl")
|
||||
end
|
||||
|
||||
@testset "chunk options" begin
|
||||
include("test_chunk_options.jl")
|
||||
end
|
||||
|
||||
@testset "error rendering" begin
|
||||
include("test_error_rendering.jl")
|
||||
end
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
using Weave: parse_options, parse_markdown
|
||||
|
||||
|
||||
@testset "`parse_options`" begin
|
||||
|
||||
# general
|
||||
@test isempty(parse_options(""))
|
||||
@test (:opt => nothing) in parse_options("opt = nothing")
|
||||
|
||||
# Weave style -- semicolon separated
|
||||
let opts = parse_options("opt1 = 1; opt2 = 2")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
# robust parsing
|
||||
@test let opts = parse_options("invalid; valid = nothing")
|
||||
@test (:valid => nothing) in opts
|
||||
true
|
||||
end
|
||||
|
||||
# RMarkdown style -- comma separated
|
||||
let opts = parse_options("opt1 = 1, opt2 = 2")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
# robust parsing
|
||||
@test let opts = parse_options("invalid, valid = nothing")
|
||||
@test (:valid => nothing) in opts
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@testset "`parse_markdown` Julia markdown format" begin
|
||||
|
||||
get_options(str) =
|
||||
(chunk = first(last(parse_markdown(str))); @test hasproperty(chunk, :options); chunk.options)
|
||||
|
||||
# Julia markdown
|
||||
@test get_options("```julia\n```") |> length === 1
|
||||
@test get_options("```julia \n```") |> length === 1
|
||||
@test get_options("```{julia}\n```") |> length === 1
|
||||
@test get_options("```{julia }\n```") |> length === 1
|
||||
|
||||
# Weave style -- semicolon separated
|
||||
@test get_options("```julia;\n```") |> length === 1
|
||||
@test get_options("```julia ;\n```") |> length === 1
|
||||
@test get_options("```julia; \n```") |> length === 1
|
||||
@test (:opt => nothing) in get_options("```julia; opt = nothing\n```")
|
||||
@test (:opt => nothing) in get_options("```{julia; opt = nothing}\n```")
|
||||
let opts = get_options("```julia; opt1 = 1; opt2 = 2\n```")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
let opts = get_options("```{julia; opt1 = 1; opt2 = 2}\n```")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
|
||||
# RMarkdown style -- comma separated
|
||||
@test get_options("```julia,\n```") |> length === 1
|
||||
@test get_options("```julia ,\n```") |> length === 1
|
||||
@test get_options("```julia, \n```") |> length === 1
|
||||
@test (:opt => nothing) in get_options("```julia, opt = nothing\n```")
|
||||
@test (:opt => nothing) in get_options("```{julia, opt = nothing}\n```")
|
||||
let opts = get_options("```{julia, opt1 = 1, opt2 = 2}\n```")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
let opts = get_options("```julia, opt1 = 1, opt2 = 2\n```")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@testset "`parse_markdown` pandoc format" begin
|
||||
|
||||
get_options(str) =
|
||||
(chunk = first(last(parse_markdown(str; is_pandoc = true))); @test hasproperty(chunk, :options); chunk.options)
|
||||
|
||||
@test get_options("<<>>=\n@") |> length === 1
|
||||
@test (:opt => nothing) in get_options("<<opt = nothing>>=\n@")
|
||||
let opts = get_options("<<opt1 = 1; opt2 = 2>>=\n@")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
let opts = get_options("<<opt1 = 1, opt2 = 2>>=\n@")
|
||||
@test (:opt1 => 1) in opts
|
||||
@test (:opt2 => 2) in opts
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
# TODO: tests for `"script"` format ?
|
Loading…
Reference in New Issue