R Under development (unstable) (2026-01-23 r89325 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(mfdb) > library(unittest, quietly = TRUE) > helpers <- c('utils/helpers.R', 'tests/utils/helpers.R') ; source(helpers[file.exists(helpers)]) > > mdb <- fake_mdb() > even <- function (x) x %% 2 == 0 > > # Capture all output, filtering log messages > cap <- function(code) { + grep("\\d{4}-\\d{2}-\\d{2}", capture.output({ + x <- code + cat("Return Value:\n") + str(x) + }), value = TRUE, invert = TRUE) + } > > ok_group("sanitise_col", local({ + # Case insensitive matching of column name (but no partial matching) + ok(cmp(sanitise_col(mdb, data.frame(aaaa=1,b=2,aa=3), 'aaaa'), 1), "Picked correct column (aaaa)") + ok(cmp(sanitise_col(mdb, data.frame(aaaa=1,b=2,aa=3), 'aa'), 3), "Picked correct column (aa)") + ok(cmp(sanitise_col(mdb, data.frame(aaaa=9,b=8,aa=7), 'AaAa'), 9), "Case is insensitive (AaAa)") + ok(cmp(sanitise_col(mdb, data.frame(aaaa=9,b=8,aa=7), 'Aa'), 7), "Case is insensitive (Aa)") + + # Defaults used if column name not mentioned + ok(cmp_error(sanitise_col(mdb, data.frame(a=9,b=8,c=7), 'bueller'), 'bueller'), "Complained about missing column when no default supplied") + ok(cmp(sanitise_col(mdb, data.frame(a=9,b=8,c=7), 'x', default = 99), 99), "No column x, used default") + ok(cmp(sanitise_col(mdb, data.frame(a=9,b=8,x=7), 'x', default = 99), 7), "Column overrode default") + + # Checks test all column content + ok(cmp( + sanitise_col(mdb, data.frame(gerald = c(2,4,6,8), freda = c(1,2,3,5)), 'gerald', test = even), + c(2,4,6,8)), "All of gerald passes test") + ok(cmp_error( + sanitise_col(mdb, data.frame(gerald = c(2,4,6,8), freda = c(1,2,3,5)), 'freda', test = even), + "freda"), "Freda does not") + ok(cmp_error( + sanitise_col(mdb, data.frame(gerald = c(2,4,6,8), freda = c(1,2,3,5)), 'freda', test = even), + "1,3,5$"), "Which items that don't match are mentioned") + ok(cmp_error( + sanitise_col(mdb, data.frame(freda = c(1:150)), 'freda', test = even), + paste(c(seq(1, 50 * 2 - 1, 2), " \\.\\.\\.$"), collapse=",")), "Give up complaining after 50 items") + + }, asNamespace('mfdb'))) # sanitise_col ok - Picked correct column (aaaa) ok - Picked correct column (aa) ok - Case is insensitive (AaAa) ok - Case is insensitive (Aa) ok - Complained about missing column when no default supplied ok - No column x, used default ok - Column overrode default ok - All of gerald passes test ok - Freda does not ok - Which items that don't match are mentioned ok - Give up complaining after 50 items > > proc.time() user system elapsed 0.65 0.14 0.76 1..11 # Looks like you passed all 11 tests.