@@ -58,7 +58,8 @@ mc <- suppressWarnings(
5858 )
5959)
6060
61- test_that(" Check that add_labels applies labels properly" , {
61+ # add_labels() tests ----
62+ test_that(" add_labels applies labels properly" , {
6263 x <- mtcars %> %
6364 add_labels(
6465 mpg = " Miles Per Gallon" ,
@@ -69,14 +70,15 @@ test_that("Check that add_labels applies labels properly", {
6970 expect_equal(attr(x $ cyl , " label" ), " Cylinders" )
7071})
7172
72- test_that(" Check that add_labels errors properly " , {
73+ test_that(" add_labels errors on invalid input " , {
7374 expect_error(add_labels(TRUE , x = " label" ))
7475 expect_error(add_labels(mtcars , " label" ))
7576 expect_error(add_labels(mtcars , bad = " label" ))
7677 expect_error(add_labels(mtcars , mpg = 1 ))
7778})
7879
79- test_that(" set_variable_labels applies labels properly" , {
80+ # set_variable_labels() tests ----
81+ test_that(" set_variable_labels applies labels from metacore properly" , {
8082 # Load in the metacore test object and example data
8183 suppressMessages(
8284 mc <- metacore :: spec_to_metacore(metacore :: metacore_example(" p21_mock.xlsx" ), quiet = TRUE ) %> %
@@ -94,27 +96,27 @@ test_that("set_variable_labels applies labels properly", {
9496 expect_equal(labs , mc $ var_spec $ label )
9597})
9698
97- test_that(" set_variable_labels raises warnings properly " , {
99+ test_that(" set_variable_labels warns on variable mismatches " , {
98100 # This is metadata for the dplyr::starwars dataset
99101 mc <- suppressWarnings(
100102 suppressMessages(
101103 metacore :: metacore(ds_spec , ds_vars , var_spec , value_spec , derivations , code_id )
102104 )
103105 ) %> % select_dataset(" Starwars" , quiet = TRUE )
104106
107+ # Variables in data not in metadata
105108 starwars_short2 <- starwars_short
106109 starwars_short2 $ new_var <- " "
107-
108- # Variables in data not in metadata
109110 expect_warning(set_variable_labels(starwars_short2 , mc ))
110111
111- mc <- suppressWarnings(
112+ # Variables in metadata not in data
113+ mc_subset <- suppressWarnings(
112114 suppressMessages(
113115 metacore :: metacore(ds_spec , ds_vars [1 : 4 , ], var_spec [1 : 4 , ], value_spec , derivations , code_id ) %> %
114116 metacore :: select_dataset(" Starwars" , quiet = TRUE )
115117 )
116118 )
117- expect_warning(set_variable_labels(starwars_short , mc ))
119+ expect_warning(set_variable_labels(starwars_short , mc_subset ))
118120})
119121
120122test_that(" set_variable_labels respects verbose parameter" , {
@@ -151,6 +153,7 @@ test_that("set_variable_labels respects verbose parameter", {
151153 )
152154})
153155
156+ # remove_labels() tests ----
154157test_that(" remove_labels removes labels properly" , {
155158 # Add labels first
156159 x <- mtcars | >
0 commit comments