Skip to content

Commit

Permalink
test: Fix snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Feb 24, 2024
1 parent 098d4c7 commit 1d54154
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test_backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ test_that("snapshots of dbplyr generic scalar translation", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
translate(as.character(1))
translate(as.character(1L))
Expand Down Expand Up @@ -263,6 +265,8 @@ test_that("snapshots of duckdb custom scalars translations", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
# translate(as(1,"CHARACTER")) # Not implemented
translate(as.raw(10))
Expand Down Expand Up @@ -304,6 +308,8 @@ test_that("snapshot tests for pasting translate", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
translate(paste("hi", "bye"))
translate(paste("hi", "bye", sep = "-"))
Expand All @@ -327,6 +333,8 @@ test_that("snapshots for custom lubridate functions translated correctly", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
translate(yday(x))
translate(quarter(x))
Expand Down Expand Up @@ -371,6 +379,8 @@ test_that("snapshots for custom stringr functions translated correctly", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
translate(str_c(x, y))
# translate(str_c(x, collapse = "")) # Error
Expand Down Expand Up @@ -399,6 +409,8 @@ test_that("snapshots datetime escaping working as in DBI", {
local_edition(3)
escape <- function(...) dbplyr::escape(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
test_date <- as.Date("2020-01-01")
escape(test_date)
Expand All @@ -422,6 +434,8 @@ test_that("two variable aggregates are translated correctly", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot({
translate(cor(x, y), window = FALSE)
translate(cor(x, y), window = TRUE)
Expand All @@ -436,6 +450,8 @@ test_that("these should give errors", {
local_edition(3)
translate <- function(...) dbplyr::translate_sql(..., con = con)

rlang::local_options(cli.num_colors = 1)

expect_snapshot(error = TRUE, {
translate(grepl("dummy", txt, perl = TRUE)) # Expected error
# translate(paste0(x, collapse = ""), window = FALSE) # Skip because of changing rlang_error (sql_paste())
Expand Down

0 comments on commit 1d54154

Please sign in to comment.