Debian Codegraph @

tests/testit/test-block.R

raw
1 library(testit)
2
3 # see http://stackoverflow.com/q/18992260/559676 for the bug
4 assert('inline_exec only accept character result', {
5 block = list(code = "function() 1", input = "inline `r function() 1`")
6 res = xfun::try_silent(inline_exec(block, new.env()))
7 (inherits(res, 'try-error'))
8 block = list(code = "(function() 1)()", input = "inline `r (function() 1)()`")
9 block$location = matrix(c(8,27), ncol = 2, byrow = TRUE)
10 res = inline_exec(block, new.env())
11 (res %==% "inline 1")
12 block = list(code = character(0), input = "no inline")
13 res = inline_exec(block, new.env())
14 (res %==% "no inline")
15 })
16
17 assert('label_code correct adds comment on code for yaml block or parsed param', {
18 oldW = getOption('width')
19 options(width = 20)
20 (label_code("1+1", list(params.src = "test, eval=TRUE")) %==% "## ----test, eval=TRUE----\n1+1\n")
21 options(width = oldW)
22 (label_code("1+1", list(params.chunk = c("#| label: test", "#| eval: true"))) %==%
23 "## --------\n#| label: test\n#| eval: true\n1+1\n")
24 })