Add missing variable in templates regarding toc (#127)
Related to #123 and alignement with `html_document()` behavior
diff --git a/tests/testthat/helpers.R b/tests/testthat/helpers.R
new file mode 100644
index 0000000..ce5d6c4
--- /dev/null
+++ b/tests/testthat/helpers.R
@@ -0,0 +1,49 @@
+local_temp_rmd_file <- function(..., .env = parent.frame()) {
+ path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd")
+ xfun::write_utf8(c(...), path)
+ path
+}
+
+local_temp_draft <- function(.env = parent.frame()) {
+ path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd")
+ # TODO: Use `rmarkdown::draft()` when rmarkdown 2.12 is out.
+ pkg_file <- getFromNamespace("pkg_file", "rmarkdown")
+ template_path <- pkg_file("rmarkdown", "templates", "revealjs_presentation",
+ package = "revealjs")
+ rmarkdown::draft(path, template_path, edit = FALSE)
+}
+
+.render_and_read <- function(input, xml = TRUE, ...) {
+ skip_if_not_pandoc()
+ output_file <- withr::local_tempfile(fileext = ".html")
+ res <- rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...)
+ if (xml) {
+ xml2::read_html(res)
+ } else {
+ xfun::read_utf8(res)
+ }
+}
+
+# Use to test pandoc availability or version lower than
+skip_if_not_pandoc <- function(ver = NULL) {
+ if (!pandoc_available(ver)) {
+ msg <- if (is.null(ver)) {
+ "Pandoc is not available"
+ } else {
+ sprintf("Version of Pandoc is lower than %s.", ver)
+ }
+ skip(msg)
+ }
+}
+
+# Use to test version greater than
+skip_if_pandoc <- function(ver = NULL) {
+ if (pandoc_available(ver)) {
+ msg <- if (is.null(ver)) {
+ "Pandoc is available"
+ } else {
+ sprintf("Version of Pandoc is greater than %s.", ver)
+ }
+ skip(msg)
+ }
+}
\ No newline at end of file