diff --git a/R/summary.R b/R/summary.R index 4d14d5a..608147b 100644 --- a/R/summary.R +++ b/R/summary.R @@ -46,12 +46,22 @@ resultOverview <- function(result){ # present result_types resultTypes <- unique(sets$result_type) - s2 <- "- Results contain **{num(length(resultTypes))}** different result types: `{glue::glue_collapse(resultTypes, sep = '`, `', last = '` and `')}`." |> + rTypes <- ifelse( + length(resultTypes) == 0, + ".", + glue::glue(": `{glue::glue_collapse(resultTypes, sep = '`, `', last = '` and `')}`.") + ) + s2 <- "- Results contain **{num(length(resultTypes))}** different result types{rTypes}" |> glue::glue() # present cdm names cdmNames <- unique(result$cdm_name) - s3 <- "- Results contain data from **{num(length(cdmNames))}** different cdm objects: \"*{glue::glue_collapse(cdmNames, sep = '*\", \"*', last = '*\" and \"*')}*\"." |> + cNames <- ifelse( + length(cdmNames) == 0, + ".", + glue::glue(": \"*{glue::glue_collapse(cdmNames, sep = '*\", \"*', last = '*\" and \"*')}*\".") + ) + s3 <- "- Results contain data from **{num(length(cdmNames))}** different cdm objects{cNames}" |> glue::glue() c("### Result overview", s1, s2, s3) diff --git a/tests/testthat/_snaps/background.md b/tests/testthat/_snaps/background.md index d3aef79..a648a54 100644 --- a/tests/testthat/_snaps/background.md +++ b/tests/testthat/_snaps/background.md @@ -16,3 +16,17 @@ Output +# test cardFromMd + + Code + cat(as.character(bkg)) + Output +
+
This is the header of the background
+

Title

+

subtitle

+

content

+
+ +
+ diff --git a/tests/testthat/_snaps/summary.md b/tests/testthat/_snaps/summary.md index b7086d3..d327570 100644 --- a/tests/testthat/_snaps/summary.md +++ b/tests/testthat/_snaps/summary.md @@ -9,8 +9,8 @@

Result overview

Package versions

Result suppression

diff --git a/tests/testthat/test-background.R b/tests/testthat/test-background.R index bf4479a..705fe00 100644 --- a/tests/testthat/test-background.R +++ b/tests/testthat/test-background.R @@ -18,3 +18,18 @@ test_that("background", { expect_snapshot(createBackground(FALSE) |> cat(sep = "\n")) }) + +test_that("test cardFromMd", { + tfile <- tempfile(fileext = ".md") + def <- defaultBackground() + writeLines(def, con = tfile) + + expect_no_error(bkg <- cardFromMd(tfile)) + expect_true(inherits(bkg, "bslib_fragment")) + expect_snapshot(bkg |> as.character() |> cat()) + + expect_warning(nobkg <- cardFromMd("not file")) + expect_identical(nobkg, bslib::card()) + + unlink(tfile) +})