tests/testthat/test-tidyselect.R

test_that("tidyselecting tables works", {
  table_names <- c("table_1", "table_2", "table_3")
  quo <- quo(c(table_3_new = table_3, table_1_new = table_1))

  expect_identical(
    eval_select_table_indices(quo, table_names),
    c(table_3_new = 3L, table_1_new = 1L)
  )

  expect_identical(
    eval_select_table(quo, table_names),
    set_names(c("table_3", "table_1"), c("table_3_new", "table_1_new"))
  )

  expect_identical(
    eval_rename_table_all(quo, table_names),
    set_names(table_names, c("table_1_new", "table_2", "table_3_new"))
  )
})

test_that("output", {
  skip_if_not_installed("vctrs", "0.4.1")
  skip_if(packageVersion("tidyselect") > "1.2.0")

  expect_snapshot(error = TRUE, {
    dm_for_filter() %>%
      dm_select_tbl(tf_7)

    dm_for_filter() %>%
      dm_rename_tbl(tf_0 = tf_7)
  })
})
krlmlr/dm documentation built on April 19, 2024, 5:23 p.m.