Skip to content

Commit

Permalink
Added tests for rich text, added display methods for markdown and latex
Browse files Browse the repository at this point in the history
  • Loading branch information
mpastell committed Apr 27, 2016
1 parent 2681f19 commit daa645a
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ test/documents/figures
test/documents/cache
test/documents/output/figures
test/documents/output/gadfly_formats_test.txt
test/documents/*.tex
test/documents/*.md
test/documents/*.rst
test/documents/*.html
test/documents/*.pdf
test/documents/chunk_options.jl
!test/documents/*ref.*
test/**/*.tex
test/**/*.md
test/**/*.rst
test/**/*.html
test/**/*.pdf
test/**/chunk_options.jl
!test/**/*ref.*

doc/build
doc/site
Expand Down
12 changes: 12 additions & 0 deletions src/display_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ function Base.display(report::Report, m::MIME"text/html", data)
report.rich_output *= "\n" * s
end

#Catch "rich_output"
function Base.display(report::Report, m::MIME"text/markdown", data)
s = reprmime(m, data)
report.rich_output *= "\n" * s
end

function Base.display(report::Report, m::MIME"text/latex", data)
s = reprmime(m, data)
report.rich_output *= "\n" * s
end


"""Add saved figure name to results and return the name"""
function add_figure(report::Report, ext)
chunk = report.cur_chunk
Expand Down
131 changes: 131 additions & 0 deletions test/documents/multimedia/rich_output.md.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@


~~~~{.julia}
using DataFrames
df = DataFrame(letters = 'a':'z', numbers = 1:26)

df

~~~~~~~~~~~~~


~~~~
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
~~~~



~~~~{.julia}
z = 51
display(df)
~~~~~~~~~~~~~


~~~~
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
~~~~





~~~~{.julia}
head(df)
~~~~~~~~~~~~~


~~~~
6x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
~~~~





~~~~{.julia}
julia> df
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
~~~~~~~~~~~~~






~~~~{.julia}
m = Base.Markdown.parse("**Some Markdown**")
m
~~~~~~~~~~~~~



**Some Markdown**

115 changes: 115 additions & 0 deletions test/documents/multimedia/rich_output.tex.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@


\begin{juliacode}
using DataFrames
df = DataFrame(letters = 'a':'z', numbers = 1:26)

df

\end{juliacode}
\begin{juliaout}
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
\end{juliaout}

\begin{juliacode}
z = 51
display(df)
\end{juliacode}
\begin{juliaout}
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
\end{juliaout}



\begin{juliacode}
head(df)
\end{juliacode}
\begin{juliaout}
6x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
\end{juliaout}



\begin{juliaterm}
julia> df
26x2 DataFrames.DataFrame
│ Row │ letters │ numbers │
┝━━━━━┿━━━━━━━━━┿━━━━━━━━━┥
│ 1 │ 'a' │ 1 │
│ 2 │ 'b' │ 2 │
│ 3 │ 'c' │ 3 │
│ 4 │ 'd' │ 4 │
│ 5 │ 'e' │ 5 │
│ 6 │ 'f' │ 6 │
│ 7 │ 'g' │ 7 │
│ 8 │ 'h' │ 8 │
│ 18 │ 'r' │ 18 │
│ 19 │ 's' │ 19 │
│ 20 │ 't' │ 20 │
│ 21 │ 'u' │ 21 │
│ 22 │ 'v' │ 22 │
│ 23 │ 'w' │ 23 │
│ 24 │ 'x' │ 24 │
│ 25 │ 'y' │ 25 │
│ 26 │ 'z' │ 26 │
\end{juliaterm}




\begin{juliacode}
m = Base.Markdown.parse("**Some Markdown**")
m
\end{juliacode}

\textbf{Some Markdown}

6 changes: 6 additions & 0 deletions test/documents/rich_output.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ head(df)
```julia; term=true
df
```


```julia
m = Base.Markdown.parse("**Some Markdown**")
m
```
12 changes: 12 additions & 0 deletions test/rich_output.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Weave, Compat
using Base.Test

function mmtest(source, resfile, doctype)
weave("documents/$source", out_path = "documents/multimedia/$resfile", doctype=doctype, plotlib=nothing)
result = @compat readstring(open("documents/multimedia/$resfile"))
ref = @compat readstring(open("documents/multimedia/$resfile.ref"))
@test result == ref
end

mmtest("rich_output.jmd", "rich_output.md", "pandoc")
mmtest("rich_output.jmd", "rich_output.tex", "tex")
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ include("chunk_options.jl")
info("Test: Caching")
include("cache_test.jl")

info("Testing rich output")
include("rich_output.jl")

if VERSION < v"0.5-dev"
info("Test: Chunk options with Gadfly")
include("chunk_opts_gadfly.jl")
Expand Down

0 comments on commit daa645a

Please sign in to comment.