diff options
Diffstat (limited to 'tests/test-normalize.R')
| -rw-r--r-- | tests/test-normalize.R | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test-normalize.R b/tests/test-normalize.R new file mode 100644 index 0000000..cbfe67f --- /dev/null +++ b/tests/test-normalize.R @@ -0,0 +1,39 @@ +library(cepis) +source(file.path("helper", "utils.R")) + +for (value in c("01001000", "01001-000", " 01001-000 ", "01001.000")) { + check( + paste0("normalize_cep accepts ", value), + identical(normalize_cep(value), "01001000") + ) +} + +for (value in c("", "123", "0100100a", "010010000", "abcdefgh")) { + check_condition( + paste0("normalize_cep rejects ", value), + normalize_cep(value), + "cepis_invalid_cep" + ) +} + +check_condition( + "normalize_cep rejects a number, which has lost its leading zero", + normalize_cep(1001000), + "cepis_invalid_cep" +) + +check_condition( + "normalize_cep rejects a vector of length two", + normalize_cep(c("01001000", "20040020")), + "cepis_invalid_cep" +) + +condition <- caught(normalize_cep("123")) +check( + "the condition is catchable as cepis_error and as error", + inherits(condition, "cepis_error") && inherits(condition, "error") +) +check("the condition carries the offending value", identical(condition$value, "123")) + +check("formatted_cep adds the mask", identical(formatted_cep("01001000"), "01001-000")) +check("formatted_cep leaves a non-CEP alone", identical(formatted_cep("x"), "x")) |