Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some tests #17

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Imports:
yaml
Suggests:
knitr,
testthat
testthat (>= 3.0.0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting suggested changes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
Expand All @@ -39,3 +39,4 @@ Collate:
'render_rmd.R'
'update.R'
'write_rmd.R'
Config/testthat/edition: 3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
Comment on lines +1 to +12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

16 changes: 16 additions & 0 deletions tests/testthat/test_as.R
Original file line number Diff line number Diff line change
@@ -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")
})
Comment on lines +1 to +16
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

23 changes: 23 additions & 0 deletions tests/testthat/test_null.R
Original file line number Diff line number Diff line change
@@ -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")
})
Comment on lines +1 to +23
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Loading