summaryrefslogtreecommitdiffstats
path: root/tests/test-normalize.R
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 12:42:37 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 12:42:37 -0300
commit11d49bc25eb1643f1b742f9527212d8781f2e0de (patch)
treebae1cb090cbf6c9f82ab5abbaf1194206f92f539 /tests/test-normalize.R
downloadr-11d49bc25eb1643f1b742f9527212d8781f2e0de.tar.gz
Initial importv0.1.0
Diffstat (limited to 'tests/test-normalize.R')
-rw-r--r--tests/test-normalize.R39
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"))