| 1 |
context("yaml front matter") |
| 2 |
|
| 3 |
test_that("yaml header is correctly parsed", { |
| 4 |
tmp_file <- tempfile(fileext = ".Rmd") |
| 5 |
on.exit(unlink(tmp_file), add = TRUE) |
| 6 |
yaml_header <- c( |
| 7 |
"---", |
| 8 |
"title: test", |
| 9 |
"output: html_document", |
| 10 |
"---" |
| 11 |
) |
| 12 |
xfun::write_utf8(yaml_header, |
| 13 |
tmp_file) |
| 14 |
yml_parsed <- list(title = "test", output = "html_document") |
| 15 |
expect_equal(yaml_front_matter(tmp_file), |
| 16 |
yml_parsed) |
| 17 |
xfun::write_utf8(c("", "", yaml_header), |
| 18 |
tmp_file) |
| 19 |
expect_equal(yaml_front_matter(tmp_file), |
| 20 |
yml_parsed) |
| 21 |
xfun::write_utf8(c("", "<!-- rnb-text-begin -->", "", yaml_header), |
| 22 |
tmp_file) |
| 23 |
expect_equal(yaml_front_matter(tmp_file), |
| 24 |
yml_parsed) |
| 25 |
xfun::write_utf8(c("", "anything", "", yaml_header), |
| 26 |
tmp_file) |
| 27 |
expect_length(yaml_front_matter(tmp_file), 0L) |
| 28 |
}) |