Skip to content

Commit

Permalink
Expand testing
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Nov 6, 2024
1 parent 1ff4e40 commit 8b549f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
18 changes: 1 addition & 17 deletions R/packer.R
Original file line number Diff line number Diff line change
Expand Up @@ -505,23 +505,7 @@ unpack_vector <- function(x, nms, len, idx, shape, fixed, process) {
res <- c(res, fixed)
}
if (!is.null(process)) {
extra <- process(res)
err <- intersect(names(extra), names(res))
if (length(err) > 0) {
cli::cli_abort(
c("'process()' is trying to overwrite entries in your list",
i = paste("The 'process()' function should only create elements",
"that are not already present in 'scalar', 'array'",
"or 'fixed', as this lets us reverse the transformation",
"process"),
x = "{?Entry/Entries} already present: {squote(err)}"))
}
## TODO: check names?
##
## TODO: this fails the multi-region use - but I think that we
## might want a different interface there anyway as we'll
## struggle to hold all the options here.
res <- c(res, extra)
res <- unpack_vector_process(res, process)
}
res
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-packer-grouped.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,10 @@ test_that("can used process with grouped packer", {
list(a = list(x = 1, y = 2, z = 3),
b = list(x = 3, y = 4, z = 7)))
})


test_that("can used process with grouped packer", {
expect_error(
monty_packer_grouped(c("a", "b"), c("x", "y"), process = TRUE),
"Expected a function for 'process'")
})

0 comments on commit 8b549f0

Please sign in to comment.