# WARNING - Generated by {fusen} from dev/flat_detect_chars_structure_datasets.Rmd: do not edit by hand

test_that("Valid outputs are consistent", {

  mydir <- system.file("detect_chars_structure_datasets", package = "scrutr")
  outfile <- file.path(tempdir(), "detect_college.rds")

  detect <- detect_chars_structure_datasets(
  datasets_folderpath = mydir,
  considered_extensions = "xlsx",
  patterns = "(?i)college",
  output_filepath = outfile,
  get_output_in_session = TRUE)

  expect_true(file.exists(outfile))
  on.exit(unlink(outfile), add = TRUE)

  expect_equal(head(lapply(detect, head)),
               list(AK.xlsx = structure(list(var = c("School Code", "School Name",
                                                     "Address", "City", "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                             TRUE, FALSE, FALSE, FALSE, FALSE), examples = c("NA", "ALASKA BIBLE COLLEGE / ALASKA CAREER COLLEGE / CHARTER COLLEGE / ILISAGVIK COLLEGE / ALASKA CHRISTIAN COLLEGE",
                                                                                                                                                                             "NA", "NA", "NA", "NA")), row.names = c(NA, 6L), class = "data.frame"),
                    AL.xlsx = structure(list(var = c("School Code", "School Name",
                                                     "Address", "City", "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                             TRUE, TRUE, FALSE, FALSE, FALSE), examples = c("NA", "EDWARD VIA VIRGINIA COLLEGE OF OSTEOPATH / CENTRAL ALABAMA COMMUNITY COLLEGE / BIRMINGHAM SOUTHERN COLLEGE / CALHOUN COMMUNITY COLLEGE / ENTERPRISE STATE COMMUNITY COLLEGE / GADSDEN STATE COMMUNITY COLLEGE / GEORGE C WALLACE COMMUNITY COLLEGE / HUNTINGDON COLLEGE / COASTAL ALABAMA COMMUNITY COLLEGE - BREW / JEFFERSON STATE COMMUNITY COLLEGE",
                                                                                                                                                                            "5735 COLLEGE PARKWAY / 2602 COLLEGE DRIVE", "NA", "NA",
                                                                                                                                                                            "NA")), row.names = c(NA, 6L), class = "data.frame"), AR.xlsx = structure(list(
                                                                                                                                                                              var = c("School Code", "School Name", "Address", "City",
                                                                                                                                                                                      "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                                                                                                                                           TRUE, TRUE, FALSE, FALSE, FALSE), examples = c("NA",
                                                                                                                                                                                                                                                                                          "ARKANSAS BAPTIST COLLEGE / LYON COLLEGE / CENTRAL BAPTIST COLLEGE / CROWLEYS RIDGE COLLEGE / HENDRIX COLLEGE / PHILANDER SMITH COLLEGE / PHILLIPS COUNTY COMMUNITY COLLEGE / SHORTER COLLEGE / U OF A COMM COLLEGE AT MORRILTON / UNIVERSITY OF ARKANSAS COMMUNITY COLLEGE",
                                                                                                                                                                                                                                                                                          "1501 COLLEGE AVENUE / 415 COLLEGE AVENUE / 100 COLLEGE DRIVE / ONE COLLEGE CIRCLE / 101 COLLEGE DR / 183 COLLEGE DRIVE / 1100 COLLEGE DRIVE / 218 COLLEGE DRIVE / ONE COLLEGE DRIVE / 1600 SOUTH COLLEGE STREET",
                                                                                                                                                                                                                                                                                          "NA", "NA", "NA")), row.names = c(NA, 6L), class = "data.frame"),
                    AS.xlsx = structure(list(var = c("School Code", "School Name",
                                                     "Address", "City", "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                             TRUE, FALSE, FALSE, FALSE, FALSE), examples = c("NA", "AMERICAN SAMOA CMNTY COLLEGE",
                                                                                                                                                                             "NA", "NA", "NA", "NA")), row.names = c(NA, 6L), class = "data.frame"),
                    AZ.xlsx = structure(list(var = c("School Code", "School Name",
                                                     "Address", "City", "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                             TRUE, FALSE, FALSE, FALSE, FALSE), examples = c("NA", "BROOKLINE COLLEGE - MESA / BROOKLINE COLLEGE - TUCSON / ARIZONA WESTERN COLLEGE / COCHISE COLLEGE / EASTERN ARIZONA COLLEGE / GLENDALE COMMUNITY COLLEGE / MESA COMMUNITY COLLEGE / PHOENIX COLLEGE / YAVAPAI COLLEGE / PIMA COUNTY COMMUNITY COLLEGE",
                                                                                                                                                                             "NA", "NA", "NA", "NA")), row.names = c(NA, 6L), class = "data.frame"),
                    CA.xlsx = structure(list(var = c("School Code", "School Name",
                                                     "Address", "City", "State Code", "Zip Code"), any_defined_structure = c(FALSE,
                                                                                                                             TRUE, TRUE, FALSE, FALSE, FALSE), examples = c("NA", "PLATT COLLEGE / PLATT COLLEGE - ANAHEIM / BRIGHTWOOD COLLEGE - CHULA VISTA / UNITED EDUCATION INSTITUTE - UEI COLLEGE / UEI COLLEGE-RIVERSIDE / PLATT COLLEGE - RIVERSIDE / UEI COLLEGE - BAKERSFIELD / UEI COLLEGE - SACRAMENTO / UC-HASTINGS COLLEGE OF THE LAW / ALLAN HANCOCK COLLEGE",
                                                                                                                                                                            "800 SO COLLEGE DRIVE / 550 N COLLEGE AVE / 835 COLLEGE AVENUE / 800 COLLEGE AVE / 8800 GROSSMONT COLLEGE DR / 4700 COLLEGE OAK DR / 435 COLLEGE AVE / ONE COLLEGE DRIVE / 100 EAST COLLEGE AVE / 7250 MESA COLLEGE DRIVE",
                                                                                                                                                                            "NA", "NA", "NA")), row.names = c(NA, 6L), class = "data.frame")))
})

test_that("Errors are consistent", {
  
  mydir <- system.file("detect_chars_structure_datasets", package = "scrutr")
  
  expect_error(detect_chars_structure_datasets(datasets_folderpath = "noexist"),
               regexp = "datasets_folderpath must be a valid folder path")
  
  expect_error(detect_chars_structure_datasets(
    datasets_folderpath = mydir, 
    considered_extensions = "xlsx", 
    patterns = "(?i)college", 
    output_filepath = "noexist/noexist.ext",
    get_output_in_session = FALSE),
    regexp = "Folder path of output_filepath must be a valid one")
})
