tests/testthat/test-constraints.checkMaxLength.R

library(stringr)
library(tableschema.r)
library(testthat)
library(foreach)

context("constraints.checkMaxLength")

# Constants
TESTS <- list(
  
  list( 0, list(1),  FALSE),
  
  list( 1, list(1),  TRUE),
  
  list( 2, list(1),  TRUE),
  
  list( 2, NULL,  TRUE)
  
)

# Tests

foreach(j = seq_along(TESTS) ) %do% {
  
  TESTS[[j]] <- setNames(TESTS[[j]], c("constraint", "value", "result"))
  
  test_that(str_interp('constraint "${TESTS[[j]]$constraint}" should check "${TESTS[[j]]$value}" as "${TESTS[[j]]$result}"'), {
    
    expect_equal(constraints.checkMaxLength(TESTS[[j]]$constraint, TESTS[[j]]$value), TESTS[[j]]$result)
  })
}

Try the tableschema.r package in your browser

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

tableschema.r documentation built on Sept. 30, 2022, 1:06 a.m.