File: test-templates.R

package info (click to toggle)
r-cran-knitr 1.50%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,864 kB
  • sloc: makefile: 16; sh: 10; javascript: 8
file content (35 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download
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
library(testit)

template = 'The value of a is {{a}}, so a + 1 is {{a + 1}}'
exp = knit_expand(text = template, a = 10)
act = 'The value of a is 10, so a + 1 is 11'
assert('templates use data specified', {
  (exp %==% act)
})

template = 'The value of a is <% a %>, so a + 1 is <% a + 1 %>'
exp = knit_expand(text = template, a = 10, delim = c("<%", "%>"))
act = 'The value of a is 10, so a + 1 is 11'
assert('templates respect custom delimiter pairs', {
  (exp %==% act)
})

template = 'hello $(LETTERS[24]) and $(pi)!'
exp = knit_expand(text = template, delim = c("$(", ")"))
act = "hello X and 3.14159265358979!"
assert('templates respect pypi delimiters', {
  (exp %==% act)
})

template = 'The value of a is <% a %>, so a + 1 is <% a + 1 %>'
assert('error is thrown when delimiter is not a pair', {
  (has_error(knit_expand(text = template, a = 10, delim = '<%')))
})

template = 'The value of a is {{a}}, and b + 1 is {{b + 1}}'
b = -1.21
exp = knit_expand(text = template, a = 10)
act = "The value of a is 10, and b + 1 is -0.21"
assert('templates use data from parent frame', {
  (exp %==% act)
})