@@ -538,7 +538,7 @@ test_that("codelist reader tests", {
538538 " SCREENING 1" , " UNSCHEDULED 1.1" , " UNSCHEDULED 1.2" , " UNSCHEDULED 1.3" , " SCREENING 2" , " BASELINE" , " UNSCHEDULED 3.1" , " AMBUL ECG PLACEMENT" , " WEEK 2" , " UNSCHEDULED 4.1" , " UNSCHEDULED 4.2" , " WEEK 4" , " UNSCHEDULED 5.1" , " AMBUL ECG REMOVAL" ,
539539 " UNSCHEDULED 6.1" , " WEEK 6" , " UNSCHEDULED 7.1" , " WEEK 8" , " WEEK 10 (T)" , " UNSCHEDULED 8.2" , " WEEK 12" , " WEEK 14 (T)" , " UNSCHEDULED 9.2" , " UNSCHEDULED 9.3" , " WEEK 16" , " WEEK 18 (T)" , " UNSCHEDULED 10.2" , " WEEK 20" , " WEEK 22 (T)" , " UNSCHEDULED 11.2" , " WEEK 24" , " UNSCHEDULED 12.1" , " WEEK 26" , " UNSCHEDULED 13.1" , " AE FOLLOW-UP" , " RETRIEVAL" , " Rash followup"
540540 )), " code_decode" ,
541- # "CL.Y_BLANK", "Y_BLANK", tibble(code = "Y", decode = "Yes"), "code_decode",
541+ # "CL.Y_BLANK", "Y_BLANK", tibble(code = "Y", decode = "Yes"), "code_decode",
542542 " CL.YN" , " YN" , tibble(code = c(" N" , " Y" ), decode = c(" No" , " Yes" )), " code_decode"
543543 )
544544
@@ -723,7 +723,7 @@ test_that("spec_type_to_value_spec auto-generates derivation_id from origin when
723723 Predecessor = c(NA_character_ , NA_character_ )
724724 )
725725 doc <- list (ValueSpec = val_sheet )
726- # No derivation_id in cols — auto -generated at lines 786-795
726+ # No derivation_id in cols. Auto -generated at lines 786-795
727727 cols <- c(
728728 dataset = " ^Dataset$" ,
729729 variable = " ^Variable$" ,
@@ -734,16 +734,16 @@ test_that("spec_type_to_value_spec auto-generates derivation_id from origin when
734734
735735 result <- spec_type_to_value_spec(doc , cols = cols , where_sep_sheet = FALSE , var_sheet = NULL )
736736
737- # origin "Assigned" → dataset.variable
737+ # origin "Assigned" to dataset.variable
738738 expect_equal(result $ derivation_id [result $ variable == " AGE" ], " ADSL.AGE" )
739- # other origin → pred.dataset.variable
739+ # other origin to pred.dataset.variable
740740 expect_equal(result $ derivation_id [result $ variable == " VISIT" ], " pred.ADSL.VISIT" )
741741})
742742
743743test_that(" spec_type_to_var_spec errors when duplicate variables have different metadata without dataset col" , {
744744 vars_sheet <- tibble :: tibble(
745745 Variable = c(" VISIT" , " VISIT" ),
746- Length = c(" 20" , " 40" ), # different lengths → same variable, different metadata
746+ Length = c(" 20" , " 40" ), # different lengths, same variable, different metadata
747747 Label = c(" Visit" , " Visit" ),
748748 Type = c(" Char" , " Char" ),
749749 Format = c(NA_character_ , NA_character_ )
@@ -770,7 +770,7 @@ test_that("spec_type_to_var_spec errors when duplicate variables have different
770770test_that(" spec_type_to_var_spec passes when duplicate variables have identical metadata without dataset col" , {
771771 vars_sheet <- tibble :: tibble(
772772 Variable = c(" VISIT" , " VISIT" ),
773- Length = c(" 20" , " 20" ), # identical rows — distinct() collapses to one
773+ Length = c(" 20" , " 20" ), # identical rows. distinct() collapses to one
774774 Label = c(" Visit" , " Visit" ),
775775 Type = c(" Char" , " Char" ),
776776 Format = c(NA_character_ , NA_character_ )
@@ -836,3 +836,62 @@ test_that("spec_to_metacore provides detailed information for failed regular exp
836836 ))
837837 )
838838})
839+
840+ # spec_type_to_codelist column-name validation --------------------------------
841+
842+ test_that(" spec_type_to_codelist errors when codelist_cols not provided" , {
843+ expect_error(
844+ spec_type_to_codelist(spec , codelist_cols = NULL ),
845+ regexp = " Codelist column names must be provided as `codelist_cols`"
846+ )
847+ })
848+
849+ test_that(" spec_type_to_codelist errors on bad codelist_cols names" , {
850+ expect_error(
851+ spec_type_to_codelist(spec , codelist_cols = c(" bad" = " ID" )),
852+ regexp = " Incorrect column names supplied for `codelist_cols`"
853+ )
854+ })
855+
856+ test_that(" spec_type_to_codelist errors on unnamed codelist_cols" , {
857+ expect_error(
858+ spec_type_to_codelist(spec , codelist_cols = c(" ID" , " Name" )),
859+ regexp = " Incorrect column names supplied for `codelist_cols`"
860+ )
861+ })
862+
863+ test_that(" spec_type_to_codelist errors on bad permitted_val_cols names" , {
864+ expect_error(
865+ spec_type_to_codelist(
866+ spec ,
867+ permitted_val_cols = c(" bad" = " ^Code|^Term" )
868+ ),
869+ regexp = " Incorrect column names supplied for `permitted_val_cols`"
870+ )
871+ })
872+
873+ test_that(" spec_type_to_codelist errors on bad dict_cols names" , {
874+ expect_error(
875+ spec_type_to_codelist(
876+ spec ,
877+ dict_cols = c(" bad" = " ID" )
878+ ),
879+ regexp = " Incorrect column names supplied for `dict_cols`"
880+ )
881+ })
882+
883+ # spec_type_to_derivations var_cols validation --------------------------------
884+
885+ test_that(" spec_type_to_derivations errors on bad var_cols names" , {
886+ expect_error(
887+ spec_type_to_derivations(spec , var_cols = c(" bad" = " [D|d]ataset" )),
888+ regexp = " Incorrect column names supplied for `var_cols`"
889+ )
890+ })
891+
892+ test_that(" spec_type_to_derivations errors on unnamed var_cols" , {
893+ expect_error(
894+ spec_type_to_derivations(spec , var_cols = c(" [D|d]ataset" , " [V|v]ariable" )),
895+ regexp = " Incorrect column names supplied for `var_cols`"
896+ )
897+ })
0 commit comments