/
test-hooks.R
34 lines (28 loc) · 1.09 KB
/
test-hooks.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(testit)
render_jekyll('prettify')
options(prompt = '> ', continue = '+ ')
# see http://stackoverflow.com/q/18992260/559676 for the bug
assert(
'the source hook pastes source code into one character string',
identical(
knit_hooks$get('source')(c('1+1', '2-2'), opts_chunk$get()),
"\n\n<pre><code class=\"prettyprint \">1+1\n2-2</code></pre>\n\n"
),
identical(
knit_hooks$get('source')(c('1+1+\n1', '2-2'), opts_chunk$merge(list(prompt = TRUE))),
"\n\n<pre><code class=\"prettyprint \">> 1+1+\n+ 1\n> 2-2</code></pre>\n\n"
)
)
render_markdown()
img_output = function(path, opts = list()) {
opts = opts_chunk$merge(opts)
wrap(knit_print(include_graphics(path)), opts)
}
assert(
'include_graphics() includes custom images correctly',
identical(img_output('a.png'), '![](a.png) '),
identical(img_output(c('a.png', 'b.png')), '![](a.png) ![](b.png) '),
identical(img_output('a.png', list(fig.cap = 'foo bar')), '![foo bar](a.png) '),
identical(img_output('a.png', list(out.width = '50%')), '<img src="a.png" title="" alt="" width="50%" />')
)
knit_hooks$restore()