| 1 |
test_that("input validation works", { |
| 2 |
expect_error(parse_template("Hey", .config = TRUE)) |
| 3 |
}) |
| 4 |
|
| 5 |
test_that("storing parsed document works", { |
| 6 |
x <- parse_template("Hello {{ name }}!") |
| 7 |
|
| 8 |
expect_s3_class(x, "jinjar_template") |
| 9 |
|
| 10 |
expect_equal(render(x, name = "world"), "Hello world!") |
| 11 |
expect_equal(render(x, name = "David"), "Hello David!") |
| 12 |
}) |
| 13 |
|
| 14 |
cli::test_that_cli("printing parsed document works", { |
| 15 |
template <- 'Humans of A New Hope |
| 16 |
{# put a comment here #} |
| 17 |
{% for person in people -%} |
| 18 |
{% if "A New Hope" in person.films and default(person.species, "Unknown") == "Human" -%} |
| 19 |
* {{ person.name }} ({{ person.homeworld }}) |
| 20 |
{% endif -%} |
| 21 |
{% endfor -%} |
| 22 |
' |
| 23 |
|
| 24 |
x <- parse_template(template) |
| 25 |
expect_snapshot(print(x, n = Inf)) |
| 26 |
expect_snapshot(print(x, n = 5)) |
| 27 |
|
| 28 |
expect_error(print(x, n = 2.5)) |
| 29 |
}) |
| 30 |
|
| 31 |
cli::test_that_cli("print spans with overlap works", { |
| 32 |
tmpl <- "{# {{ this }} is a {{ comment }} #}" |
| 33 |
x <- parse_template(tmpl) |
| 34 |
expect_snapshot(print(x)) |
| 35 |
}) |
| 36 |
|
| 37 |
cli::test_that_cli("parse error", { |
| 38 |
expect_snapshot(parse_template("Hello {{ name }!"), error = TRUE) |
| 39 |
}) |