| 1 |
test_that("Metadata is available before pre_knit", { |
| 2 |
message_pre_knit = 'pre_knit handles metadata' |
| 3 |
fmt <- md_document() |
| 4 |
fmt$pre_knit <- function(input, ...) { |
| 5 |
# `metadata` requires `rmarkdown::`-prefix. Otherwise, it becomes `list()`. |
| 6 |
if (identical(rmarkdown::metadata, list(foo = 'bar'))) { |
| 7 |
message(message_pre_knit) |
| 8 |
} |
| 9 |
} |
| 10 |
input_file = tempfile(fileext = '.md') |
| 11 |
writeLines('---\nfoo: bar\n---', input_file) |
| 12 |
expect_message(render(input_file, fmt, quiet = TRUE), message_pre_knit) |
| 13 |
}) |
| 14 |
|
| 15 |
test_that("file_scope split correctly input file", { |
| 16 |
skip_if_not(getRversion() >= '3.5') |
| 17 |
rmd <- local_rmd_file(c("# H1", "content1", "# H2", "content2")) |
| 18 |
file_scope_fun <- function(file) { |
| 19 |
x <- xfun::read_utf8(file) |
| 20 |
list( |
| 21 |
list(name = "A", content = x[1:2]), |
| 22 |
list(name = "B", content = x[3:4]) |
| 23 |
) |
| 24 |
} |
| 25 |
splitted <- file_scope_split(rmd, file_scope_fun) |
| 26 |
expect_true(all(file.exists(splitted))) |
| 27 |
on.exit(unlink(splitted), add = TRUE, after = FALSE) |
| 28 |
expect_match(splitted, "[.]split[.]md$") |
| 29 |
expect_snapshot_file(splitted[1]) |
| 30 |
expect_snapshot_file(splitted[2]) |
| 31 |
}) |
| 32 |
|
| 33 |
test_that("Input file is not corrupted", { |
| 34 |
input <- tempfile() |
| 35 |
on.exit(unlink(input), add = TRUE, after = FALSE) |
| 36 |
saveRDS("test", input) |
| 37 |
# try() is necessary for Pandoc <= 2.14.2 |
| 38 |
try(render(input, quiet = TRUE)) |
| 39 |
expect_equal(readRDS(input), "test") |
| 40 |
}) |