tests/testthat/test-valid.R

context("valid functions")

ph <- phone(ph_raw, "AU")

test_that("is_parsed", {
  expect_error(is_parsed(FALSE))
  expect_equal(is_parsed(ph), c(F, T, T, T, T, T))
})

test_that("is_valid", {
  expect_error(is_valid(FALSE))
  expect_equal(is_valid(get_example(region = regions)),
               rep(TRUE, times = length(regions)))
  
  expect_equal(is_valid(get_example(region = regions, valid = FALSE)),
               rep(FALSE, times = length(regions)))
})

test_that("is_possible", {
  expect_error(is_possible(FALSE))
  
  expect_equal(is_possible(ph), c(F, F, T, T, T, T))
  expect_equal(is_possible(ph, detailed = TRUE),
               c(NA, "TOO_SHORT", "IS_POSSIBLE", "IS_POSSIBLE",
                 "IS_POSSIBLE", "IS_POSSIBLE"))
  
  expect_equal(is_possible(ph, type = "MOBILE"), c(F, F, T, T, T, T))
  expect_equal(is_possible(ph, detailed = TRUE, type = "MOBILE"),
               c(NA, "TOO_SHORT", "IS_POSSIBLE", "IS_POSSIBLE",
                 "IS_POSSIBLE", "IS_POSSIBLE"))
  expect_equal(is_possible(ph, type = "TOLL_FREE"), c(F, F, F, F, F, T))
  expect_equal(is_possible(ph, detailed = TRUE, type = "TOLL_FREE"),
               c(NA, "TOO_SHORT", "INVALID_LENGTH", "INVALID_LENGTH",
                 "INVALID_LENGTH", "IS_POSSIBLE"))
})

Try the dialr package in your browser

Any scripts or data that you put into this service are public.

dialr documentation built on Oct. 17, 2023, 1:11 a.m.