tests/testthat/test-constraints.checkPattern.R

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

context("constraints.checkPattern")

# Constants

TESTS <- list(
  
  list('^test$', 'test', TRUE),
  
  list('^test$', 'TEST', FALSE),
  
  list('^test$', 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.checkPattern(TESTS[[j]]$constraint, TESTS[[j]]$value), TESTS[[j]]$result)
  })
}
frictionlessdata/tableschema-r documentation built on Oct. 1, 2022, 11:44 a.m.