From 8b549f077d01a95cd160753a4767bd2ad6e92f1a Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 5 Nov 2024 15:47:40 +0000 Subject: [PATCH] Expand testing --- R/packer.R | 18 +----------------- tests/testthat/test-packer-grouped.R | 7 +++++++ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/R/packer.R b/R/packer.R index 9e584eca..eb0000f2 100644 --- a/R/packer.R +++ b/R/packer.R @@ -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 } diff --git a/tests/testthat/test-packer-grouped.R b/tests/testthat/test-packer-grouped.R index a1ef64a6..7c445a8c 100644 --- a/tests/testthat/test-packer-grouped.R +++ b/tests/testthat/test-packer-grouped.R @@ -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'") +})