Skip to content

Commit

Permalink
Tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ElianHugh committed Dec 24, 2023
1 parent 0b7c59c commit f93059e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
8 changes: 5 additions & 3 deletions R/map.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
partial_qto_func <- function(f, collapse, sep) {
if (identical(f, qto_callout) || identical(f, qto_div)) {
if (identical(f, qto_callout)) {
function(...) f(...)
} else if ((identical(f, qto_div))) {
function(...) f(..., collapse = collapse)
} else {
function(...) f(..., collapse = collapse, sep = sep)
}
Expand Down Expand Up @@ -38,8 +40,8 @@ resolve_mapping_function <- function(f = NULL,
#' "heading".
#' @param .sep,.collapse Additional parameters passed to [qto_block()] if .f
#' does not return a quarto block class object. Ignored if .f does return a
#' quarto block class object. Also passed to the .type function if it is
#' a "heading" or "block".
#' quarto block class object. Also passed to the relevant .type function if it supports
#' the collapse and/or sep parameters.
#' @inheritParams rlang::args_error_context
#' @examples
#' qto_list <- map_qto(
Expand Down
4 changes: 2 additions & 2 deletions man/map_qto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/pmap_qto.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 37 additions & 3 deletions tests/testthat/test_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,46 @@ check_types <- function(lst) {
test_that("resolve_mapping_function works", {
expect_type(resolve_mapping_function(f = ~ .x + 1L), "closure")

fn <- resolve_mapping_function(type = "block", sep = " ", collapse = " ")
block_fn <- resolve_mapping_function(
type = "block",
sep = " ",
collapse = " "
)
expect_identical(
fn("Hello", c("world", "!")),
block_fn("Hello", c("world", "!")),
qto_block("Hello", c("world", "!"), sep = " ", collapse = " ")
)

div_fn <- resolve_mapping_function(
type = "div",
sep = " ",
collapse = "bar"
)
expect_identical(
div_fn("foo", "baz"),
qto_div("foo", "bar", "baz")
)

callout_fn <- resolve_mapping_function(
type = "callout",
sep = " ",
collapse = "bar"
)
expect_identical(
callout_fn("foo", "baz"),
qto_callout("foo", "baz")
)

heading_fn <- resolve_mapping_function(
type = "heading",
sep = " ",
collapse = " "
)
expect_identical(
heading_fn("foo", "baz"),
qto_heading("foo", "baz", collapse = " ", sep = " ")
)

})


Expand Down Expand Up @@ -62,5 +97,4 @@ test_that("pmap_qto works", {
expect_length(qto_list, 3L)
expect_true(check_types(qto_list))
expect_snapshot(qto_list)

})

0 comments on commit f93059e

Please sign in to comment.