diff --git a/Project.toml b/Project.toml index 12686fe..8d26959 100644 --- a/Project.toml +++ b/Project.toml @@ -27,10 +27,11 @@ julia = "1" [extras] Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Plots", "Gadfly", "Cairo", "Conda", "IJulia"] +test = ["Cairo", "Conda", "DataFrames", "Gadfly", "IJulia", "Plots", "Test"] diff --git a/src/display_methods.jl b/src/display_methods.jl index 4d0da9e..339fb16 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -83,7 +83,7 @@ Base.display(report::Report, m::MIME"image/svg+xml", data) = add_figure(report, Base.display(report::Report, m::MIME"application/pdf", data) = add_figure(report, data, m, ".pdf") -#Text is written to stdout, called from "term" mode chunks +# Text is written to stdout, called from "term" mode chunks function Base.display(report::Report, m::MIME"text/plain", data) io = PipeBuffer() show(IOContext(io, :limit => true), m, data) @@ -107,13 +107,14 @@ function Base.show(io, m::MIME"text/html", data::Exception) println(io, "") end -#Catch "rich_output" +# Catch "rich_output" function Base.display(report::Report, m::MIME"text/html", data) - s = repr(m, data) - report.rich_output *= "\n" * s + io = IOBuffer() + show(IOContext(io, :limit => true), m, data) + report.rich_output *= "\n" * String(take!(io)) end -#Catch "rich_output" +# Catch "rich_output" function Base.display(report::Report, m::MIME"text/markdown", data) s = repr(m, data) # Convert to "richer" type of possible diff --git a/test/formatter_test.jl b/test/formatter_test.jl index 42d4566..c799363 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -108,13 +108,13 @@ str = """ """ let - doc = run_doc(mock_doc(str), doctype = "md2tex") + doc = mock_doc(str; doctype = "md2tex") @test occursin(Weave.uc2tex("α"), Weave.format(doc)) @test !occursin("α", Weave.format(doc)) end let - doc = run_doc(mock_doc(str), doctype = "md2tex",latex_keep_unicode = true) + doc = mock_doc(str; doctype = "md2tex", latex_keep_unicode = true) @test occursin("α", Weave.format(doc)) @test !occursin(Weave.uc2tex("α"), Weave.format(doc)) end diff --git a/test/runtests.jl b/test/runtests.jl index 8ad1a4d..a449244 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,12 +5,14 @@ using Weave: WeaveDoc, run_doc # TODO: add test for header processsing # TODO: add test for `include_weave` -# constructs `WeaveDoc` from `String` -function mock_doc(str, format = "markdown") +# constructs `WeaveDoc` from `String` and run it +function mock_doc(str; informat = "markdown", run = true, doctype = "md2html", kwargs...) f = tempname() write(f, str) - return WeaveDoc(f, format) + doc = WeaveDoc(f, informat) + return run ? run_doc(doc; doctype = doctype, kwargs...) : doc end +macro jmd_str(s) mock_doc(s) end @testset "Weave" begin @@ -30,10 +32,14 @@ end include("test_error_rendering.jl") end - @testset "convertions" begin + @testset "conversions" begin include("test_converter.jl") end + @testset "display" begin + include("test_display.jl") + end + @testset "Formatters" begin include("formatter_test.jl") include("markdown_test.jl") diff --git a/test/test_display.jl b/test/test_display.jl new file mode 100644 index 0000000..653bf9e --- /dev/null +++ b/test/test_display.jl @@ -0,0 +1,28 @@ +@testset "limit HMTL output" begin + +@static VERSION ≥ v"1.4" && let + +# no limit +doc = jmd""" +```julia +using DataFrames +DataFrame(rand(10,3)) +``` +""" +@test isdefined(doc.chunks[1], :rich_output) +@test count("", doc.chunks[1].rich_output) == 12 # additonal 2 for name and type row + +# limit +n = 100000 +doc = jmd""" +```julia +using DataFrames +DataFrame(rand(n,3)) +``` +""" +@test isdefined(doc.chunks[1], :rich_output) +@test count("", doc.chunks[1].rich_output) < n + +end + +end diff --git a/test/test_error_rendering.jl b/test/test_error_rendering.jl index 816aeed..aade8df 100644 --- a/test/test_error_rendering.jl +++ b/test/test_error_rendering.jl @@ -35,7 +35,7 @@ err_str3_1 = get_err_str("plot(x)") err_str3_2 = get_err_str("f(y") -let doc = run_doc(mock_doc(str), doctype = "pandoc") +let doc = mock_doc(str; doctype = "github") get_output(i) = doc.chunks[i].output @test occursin(err_str1, get_output(1)) @@ -44,6 +44,6 @@ let doc = run_doc(mock_doc(str), doctype = "pandoc") @test occursin(err_str3_2, get_output(3)) end -@test_throws ArgumentError run_doc(mock_doc(str), doctype = "pandoc", throw_errors = true) +@test_throws ArgumentError mock_doc(str; doctype = "github", throw_errors = true) # TODO: test error rendering in `rich_output` diff --git a/test/test_header.jl b/test/test_header.jl index f6b3cfa..83bf02d 100644 --- a/test/test_header.jl +++ b/test/test_header.jl @@ -47,7 +47,6 @@ let title: No. `j 1` --- """) - run_doc(d) @test d.header["title"] == "No. 1" end @@ -60,8 +59,7 @@ let --- title: No. `j n` --- - """) - run_doc(d; mod = m) + """; mod = m) @test d.header["title"] == "No. 1" # strip quotes by default @@ -70,8 +68,7 @@ let --- title: No. `j s` --- - """) - run_doc(d; mod = m) + """; mod = m) @test d.header["title"] == "No. 1" # otherwise `"No. "1""` end diff --git a/test/test_module_evaluation.jl b/test/test_module_evaluation.jl index b078d05..3e1fc38 100644 --- a/test/test_module_evaluation.jl +++ b/test/test_module_evaluation.jl @@ -1,6 +1,6 @@ @testset "evaluation module" begin function mock_output(str, mod = nothing) - result_doc = run_doc(mock_doc(str), mod = mod) + result_doc = mock_doc(str; mod = mod) return result_doc.chunks[1].output end