Skip to content

Commit

Permalink
setup_address_fields() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Dec 11, 2024
1 parent c511352 commit e864699
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
5 changes: 1 addition & 4 deletions R/setup_address_fields.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ setup_address_fields <- function(logradouro = NULL,

error_null_address_fields <- function() {
geocodebr_error(
paste0(
"At least one of {.fn address_fields_const} ",
"arguments must not be {.code NULL}."
),
"At least one of the arguments must not be {.code NULL}.",
call = rlang::caller_env()
)
}
2 changes: 1 addition & 1 deletion man/setup_address_fields.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/setup_address_fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# errors when all fields are NULL

Code
tester()
Condition <geocodebr_error_null_address_fields>
Error in `setup_address_fields()`:
! At least one of the arguments must not be `NULL`.

74 changes: 74 additions & 0 deletions tests/testthat/test-setup_address_fields.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
tester <- function(logradouro = NULL,
numero = NULL,
complemento = NULL,
cep = NULL,
bairro = NULL,
municipio = NULL,
estado = NULL) {
setup_address_fields(
logradouro,
numero,
complemento,
cep,
bairro,
municipio,
estado
)
}

test_that("errors with incorrect input", {
expect_error(tester(logradouro = 1))
expect_error(tester(logradouro = c("aaa", "bbb")))

expect_error(tester(numero = 1))
expect_error(tester(numero = c("aaa", "bbb")))

expect_error(tester(complemento = 1))
expect_error(tester(complemento = c("aaa", "bbb")))

expect_error(tester(cep = 1))
expect_error(tester(cep = c("aaa", "bbb")))

expect_error(tester(bairro = 1))
expect_error(tester(bairro = c("aaa", "bbb")))

expect_error(tester(municipio = 1))
expect_error(tester(municipio = c("aaa", "bbb")))

expect_error(tester(estado = 1))
expect_error(tester(estado = c("aaa", "bbb")))
})

test_that("errors when all fields are NULL", {
expect_error(tester(), class = "geocodebr_error_null_address_fields")

expect_snapshot(tester(), error = TRUE, cnd_class = TRUE)
})

test_that("returns a character vector", {
expect_identical(
tester(
logradouro = "Nome_logradouro",
numero = "Numero",
complemento = "Comp",
cep = "CEP",
bairro = "Bairro",
municipio = "Cidade",
estado = "UF"
),
c(
logradouro = "Nome_logradouro",
numero = "Numero",
complemento = "Comp",
cep = "CEP",
bairro = "Bairro",
municipio = "Cidade",
estado = "UF"
)
)

expect_identical(
tester(logradouro = "oi", numero = "ola"),
c(logradouro = "oi", numero = "ola")
)
})

0 comments on commit e864699

Please sign in to comment.