test_that("prepend is deprecated", { expect_snapshot({ . <- prepend(1, 2) }) }) test_that("prepend is clearer version of merging with c()", { local_options(lifecycle_verbosity = "quiet") x <- 1:3 expect_identical( x %>% prepend(4), x %>% c(4, .) ) expect_identical( x %>% prepend(4, before = 3), x %>% { c(.[1:2], 4, .[3]) } ) }) test_that("prepend appends at the beginning for empty list by default", { local_options(lifecycle_verbosity = "quiet") x <- list() expect_identical( x %>% prepend(1), x %>% c(1, .) ) }) test_that("prepend throws error if before param is neither NULL nor between 1 and length(x)", { local_options(lifecycle_verbosity = "quiet") expect_error( prepend(list(), 1, before = 1), "is.null(before) || (before > 0 && before <= n) is not TRUE" ) x <- as.list(1:3) expect_error( x %>% prepend(4, before = 0), "is.null(before) || (before > 0 && before <= n) is not TRUE" ) expect_error( x %>% prepend(4, before = 4), "is.null(before) || (before > 0 && before <= n) is not TRUE" ) })
Generated by dwww version 1.15 on Sat May 18 08:01:19 CEST 2024.