Skip to content

Commit

Permalink
Add test for mapping fn resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ElianHugh committed Dec 22, 2023
1 parent dca452f commit 1f848f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 2 additions & 6 deletions R/map.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolve_mapping_function <- function(.f, .type, .call) {
resolve_mapping_function <- function(.f = NULL, .type = NULL, .call = NULL) {
.f <- .f %||% switch(.type,
block = qto_block,
div = qto_div,
Expand Down Expand Up @@ -51,11 +51,7 @@ map_qto <- function(.x,
.x,
function(x) {
x <- .f(x, ...)

if (inherits(x, "quarto_block")) {
return(x)
}

if (inherits(x, "quarto_block")) return(x)
qto_block(x, sep = .sep, collapse = .collapse, .call = .call)
}
)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ check_types <- function(lst) {
all(res)
}

test_that("mapping function is resolved correctly", {
expect_identical(
resolve_mapping_function(.type = "block"),
qto_block
)
expect_type(resolve_mapping_function(.f = ~.x + 1L), "closure")
})

test_that("map_qto works", {
qto_list <- map_qto(
list("This is a note.", "And this is a note.", "And this is a note"),
Expand Down

0 comments on commit 1f848f9

Please sign in to comment.