@@ -302,7 +302,7 @@ test_that("can sort raw", {
302
302
303
303
test_that(" safe casts work as expected" , {
304
304
expect_equal(vec_cast(NULL , list ()), NULL )
305
- expect_equal(vec_cast(NA , list ()), list (NA ))
305
+ expect_equal(vec_cast(NA , list ()), list (NULL ))
306
306
expect_equal(vec_cast(1 : 2 , list ()), list (1L , 2L ))
307
307
expect_equal(vec_cast(list (1L , 2L ), list ()), list (1L , 2L ))
308
308
})
@@ -320,6 +320,28 @@ test_that("data frames are cast to list row wise (#639)", {
320
320
expect_equal(vec_cast(x , list ()), expect )
321
321
})
322
322
323
+ test_that(" data frames can be cast to shaped lists" , {
324
+ to <- array (list (), dim = c(0 , 2 , 1 ))
325
+ x <- data.frame (x = 1 : 2 , y = 3 : 4 )
326
+
327
+ expect <- list (vec_slice(x , 1 ), vec_slice(x , 2 ))
328
+ expect <- array (expect , dim = c(2 , 2 , 1 ))
329
+
330
+ expect_equal(vec_cast(x , to ), expect )
331
+ })
332
+
333
+ test_that(" Casting atomic `NA` values to list results in a `NULL`" , {
334
+ x <- c(NA , 1 )
335
+ expect <- list (NULL , 1 )
336
+ expect_equal(vec_cast(x , list ()), expect )
337
+ })
338
+
339
+ test_that(" Casting data frame `NA` rows to list results in a `NULL`" , {
340
+ x <- data.frame (x = c(NA , NA , 1 ), y = c(NA , 1 , 2 ))
341
+ expect <- list (NULL , vec_slice(x , 2 ), vec_slice(x , 3 ))
342
+ expect_equal(vec_cast(x , list ()), expect )
343
+ })
344
+
323
345
# Unspecified
324
346
325
347
test_that(" unspecified can be cast to bare methods" , {
0 commit comments