packrat/lib/x86_64-w64-mingw32/3.6.1/rmarkdown/tests/testthat/test-yml-parsing.R

context("yaml front matter")

test_that("yaml header is correctly parsed", {
  tmp_file <- tempfile(fileext = ".Rmd")
  on.exit(unlink(tmp_file), add = TRUE)
  yaml_header <- c(
    "---",
    "title: test",
    "output: html_document",
    "---"
  )
  xfun::write_utf8(yaml_header,
                   tmp_file)
  yml_parsed <- list(title = "test", output = "html_document")
  expect_equal(yaml_front_matter(tmp_file),
               yml_parsed)
  xfun::write_utf8(c("", "", yaml_header),
                   tmp_file)
  expect_equal(yaml_front_matter(tmp_file),
               yml_parsed)
  xfun::write_utf8(c("", "<!-- rnb-text-begin -->", "", yaml_header),
                   tmp_file)
  expect_equal(yaml_front_matter(tmp_file),
               yml_parsed)
  xfun::write_utf8(c("", "anything", "", yaml_header),
                   tmp_file)
  expect_length(yaml_front_matter(tmp_file), 0L)
})
jmcascalheira/LGMIberiaCluster documentation built on June 8, 2021, 10 a.m.