| 1 |
library(testthat) |
| 2 |
library(pander) |
| 3 |
context('Pandoc.brew') |
| 4 |
|
| 5 |
test_that('expected result', { |
| 6 |
expect_equal(capture.output(Pandoc.brew(text = '## foo')), '## foo ') |
| 7 |
expect_equal(capture.output(Pandoc.brew(text = '## <%=1%>')), '## _1_ ') |
| 8 |
expect_equal(capture.output(Pandoc.brew(text = '<%=1%>')), '_1_ ') |
| 9 |
expect_equal(capture.output(Pandoc.brew(text = '<%for (i in 1:3)%><%=i%>')), '_1__2__3_ ') |
| 10 |
}) |
| 11 |
|
| 12 |
output <- '/tmp/dev.null' #nolint |
| 13 |
|
| 14 |
test_that('correct number of list elements', { |
| 15 |
expect_equal(length(Pandoc.brew(text = '## foo', output = output)), 1) |
| 16 |
expect_equal(length(Pandoc.brew(text = '## foo <%=mtcars[1:2,]%>', output = output)), 3) |
| 17 |
expect_equal(length(Pandoc.brew(text = '## foo <%=mtcars[1:2,]%> bar <%=plot(1:10)%>', output = output)), 5) |
| 18 |
expect_equal(length(Pandoc.brew(text = '## foo <%=1%> bar <%=pi%>', output = output)), 1) |
| 19 |
expect_equal(length(Pandoc.brew(text = '<%for (i in 1:5){%>## foo<%}%>', output = output)), 5) |
| 20 |
expect_equal(length(Pandoc.brew(text = '# FOO <%=pi%> bar \n# sad', output = output)), 2) |
| 21 |
expect_equal(length(Pandoc.brew(text = '# FOO\n## bar<%=pi%> bar \n# sad', output = output)), 3) |
| 22 |
expect_equal(length(Pandoc.brew(text = '# FOO ## bar<%=pi%> barn# sad', output = output)), 1) |
| 23 |
}) |
| 24 |
|
| 25 |
getChunkTypes <- function(x) |
| 26 |
sapply(x, function(x) x$type) |
| 27 |
|
| 28 |
test_that('correct returned list element types', { |
| 29 |
expect_equal(getChunkTypes(Pandoc.brew(text = 'foo <%=1:10%>', output = output)), 'text') |
| 30 |
expect_equal(getChunkTypes(Pandoc.brew(text = '## foo <%=1:10%>', output = output)), 'heading') |
| 31 |
expect_equal(getChunkTypes(Pandoc.brew(text = 'foo\n<%=1:10%>', output = output)), c('text', 'block', 'text')) |
| 32 |
expect_equal(getChunkTypes(Pandoc.brew(text = '## foo\n<%=1:10%>', output = output)), c('heading', 'block', 'text')) |
| 33 |
expect_equal(getChunkTypes(Pandoc.brew(text = 'foo <%=list(1:10)%>', output = output)), c('text', 'block', 'text')) |
| 34 |
expect_equal(getChunkTypes(Pandoc.brew(text = '## foo <%=mtcars%>', output = output)), |
| 35 |
c('heading', 'block', 'text')) |
| 36 |
expect_equal(getChunkTypes(Pandoc.brew(text = 'foo has <%=1%> apple and <%=3%> pears', output = output)), 'text') |
| 37 |
expect_equal(getChunkTypes(Pandoc.brew(text = 'foo has \nsome neat apples. Exactly <%=5%>', output = output)), |
| 38 |
'text') |
| 39 |
expect_equal(getChunkTypes(Pandoc.brew(text = '<%=5%> apple', output = output)), 'text') |
| 40 |
expect_equal(getChunkTypes(Pandoc.brew(text = '## header\n<%=5%> apple', output = output)), c('heading', 'text')) |
| 41 |
expect_equal(getChunkTypes(Pandoc.brew(text = '<%=plot(1:10)%> ', output = output)), c('block', 'text')) |
| 42 |
|
| 43 |
}) |