@@ -38,3 +38,28 @@ test_that("function kvlist_to_table works", {
3838 guide <- list (otherstuff = list (" a" = " A" , " b" = " B" ))
3939 expect_error(kvlist_to_table(kvlist , guide , reverse.translate = TRUE ))
4040})
41+
42+ test_that(" function coerce works" , {
43+ expect_equal(as.character(coerce(45748L , " date" )), " 2025-04-01" )
44+ expect_equal(as.character(coerce(as.Date(" 2025-04-01" ), " date" )), " 2025-04-01" )
45+ expect_equal(coerce(" 45748" , " integer" ), 45748L )
46+ expect_equal(coerce(" 45748" , " numeric" ), 45748 )
47+ expect_equal(coerce(45748L , " character" ), " 45748" )
48+ expect_equal(coerce(" true" , " logical" ), TRUE )
49+ })
50+
51+ test_that(" Reading dates from an excel file yield correct dates" , {
52+ excel_file <- test_path(" testdata/dates_linux.xlsx" )
53+ date1 <- readxl :: read_excel(excel_file , sheet = 1 , range = " A1:A2" )
54+ date2 <- readxl :: read_excel(excel_file , sheet = 1 , range = " B1:B2" )
55+ date3 <- readxl :: read_excel(excel_file , sheet = 1 , range = " C1:C2" )
56+ expect_equal(coerce(date1 | > dplyr :: pull(1 ), " date" ), as.Date(" 1962-10-27" ))
57+ expect_equal(coerce(date2 | > dplyr :: pull(1 ), " date" ), as.Date(" 1962-10-27" ))
58+ expect_equal(coerce(date3 | > dplyr :: pull(1 ), " date" ), as.Date(" 1962-10-27" ))
59+ date4 <- readxl :: read_excel(excel_file , sheet = 1 , range = " D1:D2" )
60+ date5 <- readxl :: read_excel(excel_file , sheet = 1 , range = " E1:E2" )
61+ date6 <- readxl :: read_excel(excel_file , sheet = 1 , range = " F1:F2" )
62+ expect_equal(coerce(date4 | > dplyr :: pull(1 ), " date" ), as.Date(" 2025-04-01" ))
63+ expect_equal(coerce(date5 | > dplyr :: pull(1 ), " date" ), as.Date(" 2025-04-01" ))
64+ expect_equal(coerce(date6 | > dplyr :: pull(1 ), " date" ), as.Date(" 2025-04-01" ))
65+ })
0 commit comments