1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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"))
|