Skip to content

Commit

Permalink
add test; tweak error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Oct 23, 2024
1 parent 9f97483 commit ffac7fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/table-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ require_col <- function(data,col,context=NULL) {
gluet <- function(x, .envir = parent.frame(), ...) {
x <- force(x)
if(!is.environment(.envir)) {
abort("pmtables error: cannot glue into .envir that is not environment")
abort("pmtables error: cannot `glue()` - .envir is not an environment.")
}
glue(x,.open = "<", .close = ">", .envir = .envir)
}
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-table-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,12 @@ test_that("table-utils paste units [PMT-TEST-0239]", {
c("B mg", "E", "D kg", "C pounds", "A")
)
})

test_that("error is generated when calling gluet with non-environment", {
x <- list(a = 1, b = 2, c = 3)
what <- "<b><a><c>"
expect_error(pmtables:::gluet(what, .envir = x), "pmtables error:")
env <- as.environment(x)
ans <- pmtables:::gluet(what, .envir = env)
expect_identical(unclass(ans), "213")
})

0 comments on commit ffac7fd

Please sign in to comment.