Skip to content

Commit

Permalink
More testing
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Jul 18, 2023
1 parent 143854a commit c89f98a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R/outpack_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,22 @@ validate_file_from_to <- function(x, environment,
to[i] <- from[i]
}
} else {
cli::cli_abort(c(
sprintf("Unexpected object type for '%s'", name),
x = sprintf("Given object of class %s", collapseq(class(x))),
i = "Expected a (named) character vector"))
cli::cli_abort(
c(sprintf("Unexpected object type for '%s'", name),
x = sprintf("Given object of class %s", collapseq(class(x))),
i = "Expected a (named) character vector"),
call = call)
}

to_value <- string_interpolate_simple(to, environment, call)

## TODO: disallow duplicates
## TODO: disallow interpolation in from
## TODO: do we cope with trailing slashes in to?
if (any(duplicated(to_value))) {
dups <- unique(to_value[duplicated(to_value)])
cli::cli_abort(
c(sprintf("Every destination filename (in '%s') must be unique", name),
i = sprintf("Duplicate names: %s", collapseq(dups))),
call = call)
}

data_frame(from = from, to = to_value)
}
9 changes: 9 additions & 0 deletions tests/testthat/test-outpack-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ test_that("can validate file renaming inputs", {
err$body,
c(x = "Given object of class 'numeric'",
i = "Expected a (named) character vector"))

expect_error(
validate_file_from_to(c("a", "a"), env, "files"),
"Every destination filename (in 'files') must be unique",
fixed = TRUE)
expect_error(
validate_file_from_to(c("a" = "x", "a" = "y"), env, "files"),
"Every destination filename (in 'files') must be unique",
fixed = TRUE)
})

0 comments on commit c89f98a

Please sign in to comment.