| 1 |
library(testit) |
| 2 |
|
| 3 |
template = 'The value of a is {{a}}, so a + 1 is {{a + 1}}' |
| 4 |
exp = knit_expand(text = template, a = 10) |
| 5 |
act = 'The value of a is 10, so a + 1 is 11' |
| 6 |
assert('templates use data specified', { |
| 7 |
(exp %==% act) |
| 8 |
}) |
| 9 |
|
| 10 |
template = 'The value of a is <% a %>, so a + 1 is <% a + 1 %>' |
| 11 |
exp = knit_expand(text = template, a = 10, delim = c("<%", "%>")) |
| 12 |
act = 'The value of a is 10, so a + 1 is 11' |
| 13 |
assert('templates respect custom delimiter pairs', { |
| 14 |
(exp %==% act) |
| 15 |
}) |
| 16 |
|
| 17 |
template = 'hello $(LETTERS[24]) and $(pi)!' |
| 18 |
exp = knit_expand(text = template, delim = c("$(", ")")) |
| 19 |
act = "hello X and 3.14159265358979!" |
| 20 |
assert('templates respect pypi delimiters', { |
| 21 |
(exp %==% act) |
| 22 |
}) |
| 23 |
|
| 24 |
template = 'The value of a is <% a %>, so a + 1 is <% a + 1 %>' |
| 25 |
assert('error is thrown when delimiter is not a pair', { |
| 26 |
(has_error(knit_expand(text = template, a = 10, delim = '<%'))) |
| 27 |
}) |
| 28 |
|
| 29 |
template = 'The value of a is {{a}}, and b + 1 is {{b + 1}}' |
| 30 |
b = -1.21 |
| 31 |
exp = knit_expand(text = template, a = 10) |
| 32 |
act = "The value of a is 10, and b + 1 is -0.21" |
| 33 |
assert('templates use data from parent frame', { |
| 34 |
(exp %==% act) |
| 35 |
}) |