From 0282e340a3db44ddf69a880ac2c3e0aa448bed59 Mon Sep 17 00:00:00 2001 From: Lucas E Date: Mon, 24 Jun 2024 18:32:43 +0800 Subject: [PATCH 1/2] added tests --- DESCRIPTION | 3 ++- tests/testthat.R | 12 ++++++++++++ tests/testthat/test_as.R | 16 ++++++++++++++++ tests/testthat/test_null.R | 23 +++++++++++++++++++++++ yamlme.Rproj | 17 +++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_as.R create mode 100644 tests/testthat/test_null.R create mode 100644 yamlme.Rproj diff --git a/DESCRIPTION b/DESCRIPTION index 64042d9..f686c03 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Imports: yaml Suggests: knitr, - testthat + testthat (>= 3.0.0) Description: Setting layout through 'YAML' headers in 'R-Markdown' documents, enabling their automatic generation. Functions and methods may summarize 'R' objects in automatic reports, for @@ -39,3 +39,4 @@ Collate: 'render_rmd.R' 'update.R' 'write_rmd.R' +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..0cf50e3 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(yamlme) + +test_check("yamlme") diff --git a/tests/testthat/test_as.R b/tests/testthat/test_as.R new file mode 100644 index 0000000..7d870d9 --- /dev/null +++ b/tests/testthat/test_as.R @@ -0,0 +1,16 @@ +test_that("as works correctly", { + example_doc <- list( + title = "To yamlme, or not to yamlme", + author = "John Doe", + output = "html_document", + body = txt_body( + "# To yamlme, or not to yamlme. That is the question.", + "* just a test" + )) + + example_doc <- as(example_doc, "rmd_doc") + expect_s3_class(example_doc, "rmd_doc") + + example_doc <- as(example_doc, "list") + expect_s3_class(example_doc, "list") +}) \ No newline at end of file diff --git a/tests/testthat/test_null.R b/tests/testthat/test_null.R new file mode 100644 index 0000000..1b77209 --- /dev/null +++ b/tests/testthat/test_null.R @@ -0,0 +1,23 @@ +test_that("body can be set to NULL", { + my_document <- read_rmd( + file = file.path(path.package("yamlme"), "inst/taxlistjourney.Rmd"), + skip_head = TRUE + ) + + my_document <- update(my_document, + title = "A journey in rOpenSci", + author = "Miguel Alvarez", + output = "html_document" + ) + + # Set body to NULL explicitly + my_document$body <- NULL + + # Check that the body is NULL + expect_null(my_document$body) + + # Check that header elements are still present and unchanged + expect_equal(my_document$header$title, "A journey in rOpenSci") + expect_equal(my_document$header$author, "Miguel Alvarez") + expect_equal(my_document$header$output, "html_document") +}) diff --git a/yamlme.Rproj b/yamlme.Rproj new file mode 100644 index 0000000..8d82f1f --- /dev/null +++ b/yamlme.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source From 53a58b681fb1bbc08876fe686bde98c1275adef5 Mon Sep 17 00:00:00 2001 From: Lucas E Date: Mon, 24 Jun 2024 18:33:24 +0800 Subject: [PATCH 2/2] added tests --- yamlme.Rproj | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 yamlme.Rproj diff --git a/yamlme.Rproj b/yamlme.Rproj deleted file mode 100644 index 8d82f1f..0000000 --- a/yamlme.Rproj +++ /dev/null @@ -1,17 +0,0 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source