Skip to content

Commit

Permalink
strip namespace for clock function translation
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 committed Aug 28, 2023
1 parent 77df050 commit 8eaa86e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ partial_eval_sym <- function(sym, data, env) {
}

is_namespaced_dplyr_call <- function(call) {
packages <- c("dplyr", "stringr", "lubridate")
packages <- c("dplyr", "stringr", "lubridate", "clock")
is_symbol(call[[1]], "::") && is_symbol(call[[2]], packages)
}

Expand Down
8 changes: 1 addition & 7 deletions tests/testthat/test-backend-mssql.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,9 @@ test_that("custom lubridate functions translated correctly", {

test_that("custom clock functions translated correctly", {
local_con(simulate_mssql())
expect_equal(test_translate_sql(add_years(x, 1L)), sql("DATEADD(YEAR, 1, `x`)"))
expect_equal(test_translate_sql(add_years(x, 1)), sql("DATEADD(YEAR, 1.0, `x`)"))
expect_equal(test_translate_sql(add_days(x, 1L)), sql("DATEADD(DAY, 1, `x`)"))
expect_equal(test_translate_sql(add_days(x, 1)), sql("DATEADD(DAY, 1.0, `x`)"))

expect_equal(test_translate_sql(clock::add_years(x, 1)), sql("DATEADD(YEAR, 1.0, `x`)"))
expect_equal(test_translate_sql(clock::add_days(x, 1)), sql("DATEADD(DAY, 1.0, `x`)"))

expect_error(test_translate_sql(add_days(x, 1, "dots must be empty")))
expect_error(test_translate_sql(add_days(x, 1, "dots", "must", "be empty")))
})

test_that("last_value_sql() translated correctly", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-tidyeval.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test_that("namespaced calls to dplyr functions are stripped", {
# hack to avoid check complaining about not declared imports
expect_equal(partial_eval(rlang::parse_expr("stringr::str_to_lower(x)"), lf), expr(str_to_lower(x)))
expect_equal(partial_eval(rlang::parse_expr("lubridate::today()"), lf), expr(today()))
expect_equal(partial_eval(rlang::parse_expr("clock::add_years(x, 1)"), lf), expr(add_years(x, 1)))
})

test_that("use quosure environment for unevaluted formulas", {
Expand Down

0 comments on commit 8eaa86e

Please sign in to comment.