File: test-brew.R

package info (click to toggle)
r-cran-pander 0.6.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,804 kB
  • sloc: javascript: 301; cpp: 145; lisp: 94; makefile: 21
file content (43 lines) | stat: -rw-r--r-- 2,650 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
library(testthat)
library(pander)
context('Pandoc.brew')

test_that('expected result', {
    expect_equal(capture.output(Pandoc.brew(text = '## foo')), '## foo ')
    expect_equal(capture.output(Pandoc.brew(text = '## <%=1%>')), '## _1_ ')
    expect_equal(capture.output(Pandoc.brew(text = '<%=1%>')), '_1_ ')
    expect_equal(capture.output(Pandoc.brew(text = '<%for (i in 1:3)%><%=i%>')), '_1__2__3_ ')
})

output <- '/tmp/dev.null' #nolint

test_that('correct number of list elements', {
    expect_equal(length(Pandoc.brew(text = '## foo', output = output)), 1)
    expect_equal(length(Pandoc.brew(text = '## foo <%=mtcars[1:2,]%>', output = output)), 3)
    expect_equal(length(Pandoc.brew(text = '## foo <%=mtcars[1:2,]%> bar <%=plot(1:10)%>', output = output)), 5)
    expect_equal(length(Pandoc.brew(text = '## foo <%=1%> bar <%=pi%>', output = output)), 1)
    expect_equal(length(Pandoc.brew(text = '<%for (i in 1:5){%>## foo<%}%>', output = output)), 5)
    expect_equal(length(Pandoc.brew(text = '# FOO <%=pi%> bar \n# sad', output = output)), 2)
    expect_equal(length(Pandoc.brew(text = '# FOO\n## bar<%=pi%> bar \n# sad', output = output)), 3)
    expect_equal(length(Pandoc.brew(text = '# FOO ## bar<%=pi%> barn# sad', output = output)), 1)
})

getChunkTypes <- function(x)
    sapply(x, function(x) x$type)

test_that('correct returned list element types', {
    expect_equal(getChunkTypes(Pandoc.brew(text = 'foo <%=1:10%>', output = output)), 'text')
    expect_equal(getChunkTypes(Pandoc.brew(text = '## foo <%=1:10%>', output = output)), 'heading')
    expect_equal(getChunkTypes(Pandoc.brew(text = 'foo\n<%=1:10%>', output = output)), c('text', 'block', 'text'))
    expect_equal(getChunkTypes(Pandoc.brew(text = '## foo\n<%=1:10%>', output = output)), c('heading', 'block', 'text'))
    expect_equal(getChunkTypes(Pandoc.brew(text = 'foo <%=list(1:10)%>', output = output)), c('text', 'block', 'text'))
    expect_equal(getChunkTypes(Pandoc.brew(text = '## foo <%=mtcars%>', output = output)),
                 c('heading', 'block', 'text'))
    expect_equal(getChunkTypes(Pandoc.brew(text = 'foo has <%=1%> apple and <%=3%> pears', output = output)), 'text')
    expect_equal(getChunkTypes(Pandoc.brew(text = 'foo has \nsome neat apples. Exactly <%=5%>', output = output)),
                  'text')
    expect_equal(getChunkTypes(Pandoc.brew(text = '<%=5%> apple', output = output)), 'text')
    expect_equal(getChunkTypes(Pandoc.brew(text = '## header\n<%=5%> apple', output = output)), c('heading', 'text'))
    expect_equal(getChunkTypes(Pandoc.brew(text = '<%=plot(1:10)%> ', output = output)), c('block', 'text'))

})