| 1 |
context("spin") |
| 2 |
|
| 3 |
test_that("default metadata are included if no metadata is provided", { |
| 4 |
content <- c( |
| 5 |
"#' # Header 1", |
| 6 |
"print('Hello World!')" |
| 7 |
) |
| 8 |
input_file <- tempfile(fileext = ".R") |
| 9 |
on.exit(unlink(input_file), add = TRUE) |
| 10 |
xfun::write_utf8(content, input_file) |
| 11 |
output_file <- tempfile(fileext = ".html") |
| 12 |
on.exit(unlink(output_file), add = TRUE) |
| 13 |
res <- render(input_file, |
| 14 |
output_format = "html_document", |
| 15 |
output_file = output_file, |
| 16 |
quiet = TRUE) |
| 17 |
output <- xfun::read_utf8(res) |
| 18 |
expect_match(grep("<title>", output, value = TRUE), |
| 19 |
paste0("<title>", basename(input_file), "</title>")) |
| 20 |
}) |
| 21 |
|
| 22 |
test_that("included YAML metadata are respected", { |
| 23 |
content <- c( |
| 24 |
"#' ---", |
| 25 |
"#' title: Test title", |
| 26 |
"#' ---", |
| 27 |
"print('Hello World!')" |
| 28 |
) |
| 29 |
input_file <- tempfile(fileext = ".R") |
| 30 |
on.exit(unlink(input_file), add = TRUE) |
| 31 |
xfun::write_utf8(content, input_file) |
| 32 |
output_file <- tempfile(fileext = ".html") |
| 33 |
on.exit(unlink(output_file), add = TRUE) |
| 34 |
res <- render(input_file, |
| 35 |
output_format = "html_document", |
| 36 |
output_file = output_file, |
| 37 |
quiet = TRUE) |
| 38 |
output <- xfun::read_utf8(res) |
| 39 |
expect_match(grep("<title>", output, value = TRUE), "<title>Test title</title>") |
| 40 |
}) |