From 8fd8de5a4c7a05a651b1c9ee896fc07b9f106269 Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Sat, 6 Dec 2014 19:16:45 +0200 Subject: [PATCH] Added tests, fix to markdown parsing --- .gitignore | 4 + src/JuliaReport.jl | 1 - src/gadfly.jl | 3 +- src/readers.jl | 2 +- test/documents/chunk_options.noweb | 26 +++ test/documents/chunk_options_ref.md | 52 ++++++ test/documents/chunk_options_ref.rst | 57 +++++++ test/documents/chunk_options_ref.tex | 42 +++++ test/documents/chunk_options_ref.texminted | 42 +++++ test/documents/gadfly_markdown_test.jmd | 30 ++++ test/documents/gadfly_markdown_test_ref.md | 175 +++++++++++++++++++++ test/runtests.jl | 36 ++++- 12 files changed, 464 insertions(+), 6 deletions(-) create mode 100644 test/documents/chunk_options.noweb create mode 100644 test/documents/chunk_options_ref.md create mode 100644 test/documents/chunk_options_ref.rst create mode 100644 test/documents/chunk_options_ref.tex create mode 100644 test/documents/chunk_options_ref.texminted create mode 100644 test/documents/gadfly_markdown_test.jmd create mode 100644 test/documents/gadfly_markdown_test_ref.md diff --git a/.gitignore b/.gitignore index 37eb0ca..bf5e95e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ examples/*.pdf examples/*.html examples/*.rst examples/*.tex +test/documents/figures +test/documents/*.tex +test/documents/*.md +test/documents/*.rst tmp/ .idea diff --git a/src/JuliaReport.jl b/src/JuliaReport.jl index 5bf5254..54a291c 100644 --- a/src/JuliaReport.jl +++ b/src/JuliaReport.jl @@ -93,7 +93,6 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb", popdisplay(report) formatted = format(executed, doctype) outname = "$(report.cwd)/$(report.basename).$(formatdict[:extension])" - @show outname open(outname, "w") do io write(io, join(formatted, "\n")) end diff --git a/src/gadfly.jl b/src/gadfly.jl index a798a23..b824a2b 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -22,7 +22,7 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot) if report.term_state == :text report.cur_result *= "\n" * report.formatdict[:codeend] end - + report.cur_result *= formatfigures(chunk, docformat) report.term_state = :fig @@ -38,7 +38,6 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot) w = chunk[:fig_width]inch h = chunk[:fig_height]inch format = chunk[:fig_ext] - @show format #This is probably not the correct way to handle different formats, but it works. if format == ".png" diff --git a/src/readers.jl b/src/readers.jl index 24cf334..90069b5 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -7,7 +7,7 @@ const input_formats = @compat Dict{String, Any}( :codeend => r"^@\s*$" ), "markdown" => Dict{Symbol, Any}( - :codestart => r"(?:^`|~{3,}\s*(?:\{|\{\.|)julia(?:;|\s)(.*)\}\s*$)|(?:^`|~{3,}\s*julia\s*$)", + :codestart => r"(?:^(?:`|~){3,}\s*(?:\{|\{\.|)julia(?:;|\s)(.*)\}\s*$)|(?:^(?:`|~){3,}\s*julia\s*$)", :codeend => r"^`|~{3,}\s*$" ) ) diff --git a/test/documents/chunk_options.noweb b/test/documents/chunk_options.noweb new file mode 100644 index 0000000..4c17753 --- /dev/null +++ b/test/documents/chunk_options.noweb @@ -0,0 +1,26 @@ + +<>= +y= [2, 5, 12] +@ + +<<>>= +x = [12, 10] +println(y) +@ + + +<>= +println(x) +@ + + +<>= +y = randn(5) +println(y) +@ + + +<>= +a = "Some string" +println(a) +@ diff --git a/test/documents/chunk_options_ref.md b/test/documents/chunk_options_ref.md new file mode 100644 index 0000000..2b5c15a --- /dev/null +++ b/test/documents/chunk_options_ref.md @@ -0,0 +1,52 @@ + + +~~~~{.julia} +julia> y= [2, 5, 12] +3-element Array{Int64,1}: + 2 + 5 + 12 + +~~~~~~~~~~~~~ + + + + + +~~~~{.julia} +x = [12, 10] +println(y) +~~~~~~~~~~~~~ + + +~~~~{.julia} +[2,5,12] +~~~~~~~~~~~~~ + + + + + + +~~~~{.julia} +[12,10] +~~~~~~~~~~~~~ + + + + + + + + + +~~~~{.julia} +a = "Some string" +println(a) +~~~~~~~~~~~~~ + + + + + + diff --git a/test/documents/chunk_options_ref.rst b/test/documents/chunk_options_ref.rst new file mode 100644 index 0000000..5e83374 --- /dev/null +++ b/test/documents/chunk_options_ref.rst @@ -0,0 +1,57 @@ + + +.. code-block:: julia + + julia> y= [2, 5, 12] + 3-element Array{Int64,1}: + 2 + 5 + 12 + + + + + + + +.. code-block:: julia + + x = [12, 10] + println(y) + + + +:: + + [2,5,12] + + + + + + + +:: + + [12,10] + + + + + + + + + + +.. code-block:: julia + + a = "Some string" + println(a) + + + + + + + diff --git a/test/documents/chunk_options_ref.tex b/test/documents/chunk_options_ref.tex new file mode 100644 index 0000000..2f1b3ed --- /dev/null +++ b/test/documents/chunk_options_ref.tex @@ -0,0 +1,42 @@ + + +\begin{juliacode} +julia> y= [2, 5, 12] +3-element Array{Int64,1}: + 2 + 5 + 12 + +\end{juliacode} + + + +\begin{juliacode} +x = [12, 10] +println(y) +\end{juliacode} +\begin{juliaout} +[2,5,12] +\end{juliaout} + + + + +\begin{juliaout} +[12,10] +\end{juliaout} + + + + + + + +\begin{juliacode} +a = "Some string" +println(a) +\end{juliacode} + + + + diff --git a/test/documents/chunk_options_ref.texminted b/test/documents/chunk_options_ref.texminted new file mode 100644 index 0000000..2b45de6 --- /dev/null +++ b/test/documents/chunk_options_ref.texminted @@ -0,0 +1,42 @@ + + +\begin{minted}[fontsize=\footnotesize, xleftmargin=0.5em, mathescape]{julia} +julia> y= [2, 5, 12] +3-element Array{Int64,1}: + 2 + 5 + 12 + +\end{minted} + + + +\begin{minted}[mathescape, fontsize=\small, xleftmargin=0.5em]{julia} +x = [12, 10] +println(y) +\end{minted} +\begin{minted}[fontsize=\small, xleftmargin=0.5em, mathescape, frame = leftline]{text} +[2,5,12] +\end{minted} + + + + +\begin{minted}[fontsize=\small, xleftmargin=0.5em, mathescape, frame = leftline]{text} +[12,10] +\end{minted} + + + + + + + +\begin{minted}[mathescape, fontsize=\small, xleftmargin=0.5em]{julia} +a = "Some string" +println(a) +\end{minted} + + + + diff --git a/test/documents/gadfly_markdown_test.jmd b/test/documents/gadfly_markdown_test.jmd new file mode 100644 index 0000000..8c2ba0d --- /dev/null +++ b/test/documents/gadfly_markdown_test.jmd @@ -0,0 +1,30 @@ + +# Gadfly + +```{julia;term=true;fig_width=5} +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +``` + + +```julia +x = linspace(0, 200) +println(x) +``` + + +~~~{julia;term=true;fig_width=5} +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +~~~ + +~~~julia +x = linspace(0, 200) +println(x) +~~~ diff --git a/test/documents/gadfly_markdown_test_ref.md b/test/documents/gadfly_markdown_test_ref.md new file mode 100644 index 0000000..129a0c5 --- /dev/null +++ b/test/documents/gadfly_markdown_test_ref.md @@ -0,0 +1,175 @@ + + +# Gadfly + +````julia +julia> using Gadfly + +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +```` + +![](figures/gadfly_markdown_test_1_1.png) + + +````julia +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +```` + +![](figures/gadfly_markdown_test_1_2.png) + + + + + +````julia +x = linspace(0, 200) +println(x) +```` + + +````julia +[0.0,2.0202020202020203,4.040404040404041,6.0606060606060606,8.0808080 +80808081,10.1010101010101,12.121212121212121,14.14141414141414,16.1616 +16161616163,18.181818181818183,20.2020202020202,22.22222222222222,24.2 +42424242424242,26.262626262626267,28.28282828282828,30.303030303030305 +,32.323232323232325,34.34343434343434,36.36363636363637,38.38383838383 +838,40.4040404040404,42.42424242424242,44.44444444444444,46.4646464646 +46464,48.484848484848484,50.505050505050505,52.52525252525253,54.54545 +454545454,56.56565656565656,58.58585858585859,60.60606060606061,62.626 +26262626263,64.64646464646465,66.66666666666666,68.68686868686868,70.7 +0707070707071,72.72727272727273,74.74747474747475,76.76767676767676,78 +.78787878787878,80.8080808080808,82.82828282828282,84.84848484848484,8 +6.86868686868688,88.88888888888889,90.9090909090909,92.92929292929293, +94.94949494949495,96.96969696969697,98.98989898989899,101.010101010101 +01,103.03030303030303,105.05050505050507,107.07070707070707,109.090909 +09090908,111.11111111111111,113.13131313131312,115.15151515151516,117. +17171717171718,119.19191919191918,121.21212121212122,123.2323232323232 +2,125.25252525252526,127.27272727272727,129.2929292929293,131.31313131 +313132,133.33333333333331,135.35353535353536,137.37373737373736,139.39 +39393939394,141.41414141414143,143.43434343434342,145.45454545454547,1 +47.47474747474746,149.4949494949495,151.5151515151515,153.535353535353 +52,155.55555555555557,157.57575757575756,159.5959595959596,161.6161616 +161616,163.63636363636365,165.65656565656565,167.67676767676767,169.69 +69696969697,171.7171717171717,173.73737373737376,175.75757575757575,17 +7.77777777777777,179.7979797979798,181.8181818181818,183.8383838383838 +3,185.85858585858585,187.87878787878788,189.8989898989899,191.91919191 +919192,193.93939393939394,195.95959595959596,197.97979797979798,200.0] +```` + + + + + + +````julia +julia> using Gadfly + +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +```` + +![](figures/gadfly_markdown_test_3_1.png) + + +````julia +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +```` + +![](figures/gadfly_markdown_test_3_2.png) + + + + +````julia +x = linspace(0, 200) +println(x) +```` + + +````julia +[0.0,2.0202020202020203,4.040404040404041,6.0606060606060606,8.0808080 +80808081,10.1010101010101,12.121212121212121,14.14141414141414,16.1616 +16161616163,18.181818181818183,20.2020202020202,22.22222222222222,24.2 +42424242424242,26.262626262626267,28.28282828282828,30.303030303030305 +,32.323232323232325,34.34343434343434,36.36363636363637,38.38383838383 +838,40.4040404040404,42.42424242424242,44.44444444444444,46.4646464646 +46464,48.484848484848484,50.505050505050505,52.52525252525253,54.54545 +454545454,56.56565656565656,58.58585858585859,60.60606060606061,62.626 +26262626263,64.64646464646465,66.66666666666666,68.68686868686868,70.7 +0707070707071,72.72727272727273,74.74747474747475,76.76767676767676,78 +.78787878787878,80.8080808080808,82.82828282828282,84.84848484848484,8 +6.86868686868688,88.88888888888889,90.9090909090909,92.92929292929293, +94.94949494949495,96.96969696969697,98.98989898989899,101.010101010101 +01,103.03030303030303,105.05050505050507,107.07070707070707,109.090909 +09090908,111.11111111111111,113.13131313131312,115.15151515151516,117. +17171717171718,119.19191919191918,121.21212121212122,123.2323232323232 +2,125.25252525252526,127.27272727272727,129.2929292929293,131.31313131 +313132,133.33333333333331,135.35353535353536,137.37373737373736,139.39 +39393939394,141.41414141414143,143.43434343434342,145.45454545454547,1 +47.47474747474746,149.4949494949495,151.5151515151515,153.535353535353 +52,155.55555555555557,157.57575757575756,159.5959595959596,161.6161616 +161616,163.63636363636365,165.65656565656565,167.67676767676767,169.69 +69696969697,171.7171717171717,173.73737373737376,175.75757575757575,17 +7.77777777777777,179.7979797979798,181.8181818181818,183.8383838383838 +3,185.85858585858585,187.87878787878788,189.8989898989899,191.91919191 +919192,193.93939393939394,195.95959595959596,197.97979797979798,200.0] +```` + + + + diff --git a/test/runtests.jl b/test/runtests.jl index c1b45e7..863f229 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,37 @@ using JuliaReport using Base.Test -# write your own tests here -@test 1 == 1 + +#Test chunk options and output formats + +weave("documents/chunk_options.noweb", plotlib=nothing) +result = readall(open("documents/chunk_options.md")) +ref = readall(open("documents/chunk_options_ref.md")) + +@test result == ref + +weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing) +result = readall(open("documents/chunk_options.tex")) +ref = readall(open("documents/chunk_options_ref.tex")) + +@test result == ref + +weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing) +result = readall(open("documents/chunk_options.tex")) +ref = readall(open("documents/chunk_options_ref.texminted")) + +@test result == ref + +weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing) +result = readall(open("documents/chunk_options.rst")) +ref = readall(open("documents/chunk_options_ref.rst")) + +@test result == ref + + +#Test Gadfly and markdown reader +weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown") +result = readall(open("documents/gadfly_markdown_test.md")) +ref = readall(open("documents/gadfly_markdown_test_ref.md")) + +@test result == ref