diff --git a/R/setup_address_fields.R b/R/setup_address_fields.R index 4cde5b6..9bf0cf6 100644 --- a/R/setup_address_fields.R +++ b/R/setup_address_fields.R @@ -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() ) } diff --git a/man/setup_address_fields.Rd b/man/setup_address_fields.Rd index 6a9efd0..8af2cc9 100644 --- a/man/setup_address_fields.Rd +++ b/man/setup_address_fields.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/address_fields_const.R +% Please edit documentation in R/setup_address_fields.R \name{setup_address_fields} \alias{setup_address_fields} \title{Specify the columns describing the address fields} diff --git a/tests/testthat/_snaps/setup_address_fields.md b/tests/testthat/_snaps/setup_address_fields.md new file mode 100644 index 0000000..5fa95a0 --- /dev/null +++ b/tests/testthat/_snaps/setup_address_fields.md @@ -0,0 +1,8 @@ +# errors when all fields are NULL + + Code + tester() + Condition + Error in `setup_address_fields()`: + ! At least one of the arguments must not be `NULL`. + diff --git a/tests/testthat/test-setup_address_fields.R b/tests/testthat/test-setup_address_fields.R new file mode 100644 index 0000000..0834bb1 --- /dev/null +++ b/tests/testthat/test-setup_address_fields.R @@ -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") + ) +})