| 1 |
cli::test_that_cli("path_loader works", { |
| 2 |
expect_error(path_loader("unknown")) |
| 3 |
|
| 4 |
test_path <- fs::path_home_r() |
| 5 |
|
| 6 |
x <- path_loader(test_path) |
| 7 |
expect_s3_class(x, c("path_loader", "jinjar_loader")) |
| 8 |
expect_equal(x$path, test_path) |
| 9 |
expect_snapshot( |
| 10 |
print(x), |
| 11 |
transform = function(x) gsub(test_path, "/path/to/templates", x, fixed = TRUE) |
| 12 |
) |
| 13 |
}) |
| 14 |
|
| 15 |
cli::test_that_cli("package_loader works", { |
| 16 |
expect_error(package_loader("unknown")) |
| 17 |
|
| 18 |
x <- package_loader("jinjar", "R") |
| 19 |
expect_s3_class(x, c("package_loader", "path_loader", "jinjar_loader")) |
| 20 |
expect_equal(x$path, fs::path_package("jinjar", "R")) |
| 21 |
expect_snapshot(print(x)) |
| 22 |
}) |
| 23 |
|
| 24 |
cli::test_that_cli("list_loader works", { |
| 25 |
expect_error(list_loader(list())) |
| 26 |
|
| 27 |
x <- list_loader(list("a" = "b")) |
| 28 |
expect_s3_class(x, c("list_loader", "jinjar_loader")) |
| 29 |
expect_equal(x$a, "b") |
| 30 |
|
| 31 |
short_names <- list(x = "a", y = "b", z = "c") |
| 32 |
long_names <- list( |
| 33 |
"here_is_a_very_long_template_name" = "a", |
| 34 |
"and_one_more_just_for_good_luck" = "b" |
| 35 |
) |
| 36 |
expect_snapshot({ |
| 37 |
print(list_loader(short_names)) |
| 38 |
print(list_loader(long_names)) |
| 39 |
}) |
| 40 |
}) |