Skip to content

Commit

Permalink
validated simplify
Browse files Browse the repository at this point in the history
Thanks, @nutterb. Ref #217
  • Loading branch information
wibeasley committed Jun 4, 2018
1 parent 4e53a69 commit ebbc8d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/constant.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
constant <- function( name, simplify=TRUE ) {
checkmate::assert_character(name, any.missing=F, min.chars=1L)
checkmate::assert_subset(name, names(constant_list), empty.ok=F)
checkmate::assert_logical(simplify, any.missing=F, len=1L)

# return( constant_list[[name]] )
sapply(
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-constant.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,25 @@ test_that("missing name", {
expected_error_message
)
})

test_that("bad simplify", {
# expected_error_message <- "Assertion on 'simplify' failed: Must be of type 'logical', not 'character'."
expect_error(
constant("form_complete", simplify="aa"),
"^Assertion on 'simplify' failed: Must be of type 'logical', not 'character'\\.$"
)
})
test_that("missing simplify", {
# expected_error_message <- "Assertion on 'simplify' failed: Must be of type 'logical', not 'NULL'. "
expect_error(
constant("form_complete", simplify=NULL),
"^Assertion on 'simplify' failed: Must be of type 'logical', not 'NULL'\\.$"
)
})
test_that("NA simplify", {
# expected_error_message <- "Assertion on 'simplify' failed: Contains missing values (element 1)."
expect_error(
constant("form_complete", simplify=NA_character_),
"^Assertion on 'simplify' failed: Contains missing values \\(element 1\\)\\.$"
)
})

0 comments on commit ebbc8d8

Please sign in to comment.