Skip to content

Commit ebbc8d8

Browse files
committed
validated simplify
Thanks, @nutterb. Ref #217
1 parent 4e53a69 commit ebbc8d8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

R/constant.R

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
constant <- function( name, simplify=TRUE ) {
4747
checkmate::assert_character(name, any.missing=F, min.chars=1L)
4848
checkmate::assert_subset(name, names(constant_list), empty.ok=F)
49+
checkmate::assert_logical(simplify, any.missing=F, len=1L)
4950

5051
# return( constant_list[[name]] )
5152
sapply(

tests/testthat/test-constant.R

+22
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,25 @@ test_that("missing name", {
5252
expected_error_message
5353
)
5454
})
55+
56+
test_that("bad simplify", {
57+
# expected_error_message <- "Assertion on 'simplify' failed: Must be of type 'logical', not 'character'."
58+
expect_error(
59+
constant("form_complete", simplify="aa"),
60+
"^Assertion on 'simplify' failed: Must be of type 'logical', not 'character'\\.$"
61+
)
62+
})
63+
test_that("missing simplify", {
64+
# expected_error_message <- "Assertion on 'simplify' failed: Must be of type 'logical', not 'NULL'. "
65+
expect_error(
66+
constant("form_complete", simplify=NULL),
67+
"^Assertion on 'simplify' failed: Must be of type 'logical', not 'NULL'\\.$"
68+
)
69+
})
70+
test_that("NA simplify", {
71+
# expected_error_message <- "Assertion on 'simplify' failed: Contains missing values (element 1)."
72+
expect_error(
73+
constant("form_complete", simplify=NA_character_),
74+
"^Assertion on 'simplify' failed: Contains missing values \\(element 1\\)\\.$"
75+
)
76+
})

0 commit comments

Comments
 (0)