diff --git a/R/funs-string.R b/R/funs-string.R index 16535213..f94a2c2c 100644 --- a/R/funs-string.R +++ b/R/funs-string.R @@ -242,8 +242,8 @@ pl_str_sub_stringr <- function(string, start, end = NULL) { length )$otherwise(2000) - foo2 <- pl$when(start_is_zero & (end_is_null | end$abs() <= len_string))$then( - len_string - end - 1 + foo2 <- pl$when(start_is_zero & end > 0 & end <= len_string)$then( + end )$otherwise(2000) foo3 <- pl$when(start >= 0 & end_is_null)$then(len_string - start)$otherwise( @@ -282,6 +282,9 @@ pl_str_sub_stringr <- function(string, start, end = NULL) { when(start_is_zero & end > 0 & end <= len_string)$ then(string$str$slice(0, foo2))$ + when(start_is_zero & end > 0 & end > len_string)$ + then(string)$ + when(start_is_zero & end < 0 & end$abs() <= len_string)$ then(string$str$slice(0, foo6))$ @@ -318,6 +321,9 @@ pl_str_sub_stringr <- function(string, start, end = NULL) { when(start < 0 & end < 0 & start$abs() > len_string & end$abs() > len_string)$ then(pl$lit(""))$ + when(start < 0 & end_is_zero & start$abs() > len_string)$ + then(pl$lit(""))$ + when(start > 0 & end > 0 & start > end)$then(pl$lit("")) } diff --git a/tests/testthat/test-funs-string-lazy.R b/tests/testthat/test-funs-string-lazy.R index 80ae5b4a..f6467238 100644 --- a/tests/testthat/test-funs-string-lazy.R +++ b/tests/testthat/test-funs-string-lazy.R @@ -3,100 +3,100 @@ Sys.setenv('TIDYPOLARS_TEST' = TRUE) test_that("paste() and paste0() work", { - for_all( - tests = 40, - string = character_(any_na = TRUE), - separator = character_(len = 1), - property = function(string, separator) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - expect_equal_lazy( - mutate(test, foo = paste(x1, "he")) |> - pull(foo), - mutate(test_df, foo = paste(x1, "he")) |> - pull(foo) - ) - - expect_equal_lazy( - mutate(test, foo = paste(x1, "he", sep = separator)) |> - pull(foo), - mutate(test_df, foo = paste(x1, "he", sep = separator)) |> - pull(foo) - ) - - expect_equal_lazy( - mutate(test, foo = paste0(x1, "he")) |> - pull(foo), - mutate(test_df, foo = paste0(x1, "he")) |> - pull(foo) - ) - - expect_equal_lazy( - mutate(test, foo = paste0(x1, "he", x1)) |> - pull(foo), - mutate(test_df, foo = paste0(x1, "he", x1)) |> - pull(foo) - ) - } - ) + for_all( + tests = 40, + string = character_(any_na = TRUE), + separator = character_(len = 1), + property = function(string, separator) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + expect_equal_lazy( + mutate(test, foo = paste(x1, "he")) |> + pull(foo), + mutate(test_df, foo = paste(x1, "he")) |> + pull(foo) + ) + + expect_equal_lazy( + mutate(test, foo = paste(x1, "he", sep = separator)) |> + pull(foo), + mutate(test_df, foo = paste(x1, "he", sep = separator)) |> + pull(foo) + ) + + expect_equal_lazy( + mutate(test, foo = paste0(x1, "he")) |> + pull(foo), + mutate(test_df, foo = paste0(x1, "he")) |> + pull(foo) + ) + + expect_equal_lazy( + mutate(test, foo = paste0(x1, "he", x1)) |> + pull(foo), + mutate(test_df, foo = paste0(x1, "he", x1)) |> + pull(foo) + ) + } + ) }) patrick::with_parameters_test_that( - "several non-regex functions work", - { - for_all( - tests = 40, - string = character_(any_na = TRUE), - property = function(string) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - pl_code <- paste0("mutate(test, foo = ", fun, "(string)) |> pull(foo)") - tv_code <- paste0( - "mutate(test_df, foo = ", - fun, - "(string)) |> pull(foo)" - ) - - expect_equal_lazy( - eval(parse(text = pl_code)), - eval(parse(text = tv_code)), - ) - } - ) - }, - fun = c("str_to_upper", "str_to_lower", "str_length", "str_squish") + "several non-regex functions work", + { + for_all( + tests = 40, + string = character_(any_na = TRUE), + property = function(string) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + pl_code <- paste0("mutate(test, foo = ", fun, "(string)) |> pull(foo)") + tv_code <- paste0( + "mutate(test_df, foo = ", + fun, + "(string)) |> pull(foo)" + ) + + expect_equal_lazy( + eval(parse(text = pl_code)), + eval(parse(text = tv_code)), + ) + } + ) + }, + fun = c("str_to_upper", "str_to_lower", "str_length", "str_squish") ) test_that("str_trim() works", { - for_all( - tests = 40, - string = character_(any_na = TRUE), - side = quickcheck::one_of( - constant("both"), - constant("left"), - constant("right") - ), - property = function(string, side) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - expect_equal_lazy( - mutate(test, foo = str_trim(x1)) |> - pull(foo), - mutate(test_df, foo = str_trim(x1)) |> - pull(foo) - ) - - expect_equal_lazy( - mutate(test, foo = str_trim(x1, side = side)) |> - pull(foo), - mutate(test_df, foo = str_trim(x1, side = side)) |> - pull(foo) - ) - } - ) + for_all( + tests = 40, + string = character_(any_na = TRUE), + side = quickcheck::one_of( + constant("both"), + constant("left"), + constant("right") + ), + property = function(string, side) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + expect_equal_lazy( + mutate(test, foo = str_trim(x1)) |> + pull(foo), + mutate(test_df, foo = str_trim(x1)) |> + pull(foo) + ) + + expect_equal_lazy( + mutate(test, foo = str_trim(x1, side = side)) |> + pull(foo), + mutate(test_df, foo = str_trim(x1, side = side)) |> + pull(foo) + ) + } + ) }) # TODO: Problem is that I don't have a way to check that length of string is the @@ -134,68 +134,68 @@ test_that("str_trim() works", { # }) test_that("str_dup() works", { - for_all( - tests = 100, - string = character_(any_na = TRUE), - # Very high numbers crash the session, I guess because of stringr - times = numeric_bounded(-10000, 10000, any_na = TRUE), - property = function(string, times) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = str_dup(x1, times = times)) |> - pull(foo), - mutate(test_df, foo = str_dup(x1, times = times)) |> - pull(foo) - ) - } - ) + for_all( + tests = 100, + string = character_(any_na = TRUE), + # Very high numbers crash the session, I guess because of stringr + times = numeric_bounded(-10000, 10000, any_na = TRUE), + property = function(string, times) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = str_dup(x1, times = times)) |> + pull(foo), + mutate(test_df, foo = str_dup(x1, times = times)) |> + pull(foo) + ) + } + ) }) test_that("str_sub() works", { - for_all( - tests = 200, - string = character_(any_na = TRUE), - start = numeric_(any_na = TRUE), - end = numeric_(any_na = TRUE), - property = function(string, start, end) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = str_sub(x1, start, end)) |> - pull(foo), - mutate(test_df, foo = str_sub(x1, start, end)) |> - pull(foo) - ) - } - ) + for_all( + tests = 200, + string = character_(any_na = TRUE), + start = numeric_(any_na = TRUE), + end = numeric_(any_na = TRUE), + property = function(string, start, end) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = str_sub(x1, start, end)) |> + pull(foo), + mutate(test_df, foo = str_sub(x1, start, end)) |> + pull(foo) + ) + } + ) }) test_that("substr() works", { - # substr() doesn't error with different lengths but polars does. I don't want - # this weird case to prevent quickcheck to run, especially since this is a - # weird behavior in base R and we're more conservative on this. - length <- sample(1:10, 1) - - for_all( - tests = 200, - string = character_(any_na = TRUE, len = length), - start = numeric_(any_na = TRUE, len = length), - end = numeric_(any_na = TRUE, len = length), - property = function(string, start, end) { - test_df <- data.frame(x1 = string) - test <- pl$LazyFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = substr(x1, start, end)) |> - pull(foo), - mutate(test_df, foo = substr(x1, start, end)) |> - pull(foo) - ) - } - ) + # substr() doesn't error with different lengths but polars does. I don't want + # this weird case to prevent quickcheck to run, especially since this is a + # weird behavior in base R and we're more conservative on this. + length <- sample(1:10, 1) + + for_all( + tests = 200, + string = character_(any_na = TRUE, len = length), + start = numeric_(any_na = TRUE, len = length), + end = numeric_(any_na = TRUE, len = length), + property = function(string, start, end) { + test_df <- data.frame(x1 = string) + test <- pl$LazyFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = substr(x1, start, end)) |> + pull(foo), + mutate(test_df, foo = substr(x1, start, end)) |> + pull(foo) + ) + } + ) }) Sys.setenv('TIDYPOLARS_TEST' = FALSE) diff --git a/tests/testthat/test-funs-string.R b/tests/testthat/test-funs-string.R index 11f79831..b867f6e9 100644 --- a/tests/testthat/test-funs-string.R +++ b/tests/testthat/test-funs-string.R @@ -1,98 +1,98 @@ test_that("paste() and paste0() work", { - for_all( - tests = 40, - string = character_(any_na = TRUE), - separator = character_(len = 1), - property = function(string, separator) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - expect_equal( - mutate(test, foo = paste(x1, "he")) |> - pull(foo), - mutate(test_df, foo = paste(x1, "he")) |> - pull(foo) - ) - - expect_equal( - mutate(test, foo = paste(x1, "he", sep = separator)) |> - pull(foo), - mutate(test_df, foo = paste(x1, "he", sep = separator)) |> - pull(foo) - ) - - expect_equal( - mutate(test, foo = paste0(x1, "he")) |> - pull(foo), - mutate(test_df, foo = paste0(x1, "he")) |> - pull(foo) - ) - - expect_equal( - mutate(test, foo = paste0(x1, "he", x1)) |> - pull(foo), - mutate(test_df, foo = paste0(x1, "he", x1)) |> - pull(foo) - ) - } - ) + for_all( + tests = 40, + string = character_(any_na = TRUE), + separator = character_(len = 1), + property = function(string, separator) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + expect_equal( + mutate(test, foo = paste(x1, "he")) |> + pull(foo), + mutate(test_df, foo = paste(x1, "he")) |> + pull(foo) + ) + + expect_equal( + mutate(test, foo = paste(x1, "he", sep = separator)) |> + pull(foo), + mutate(test_df, foo = paste(x1, "he", sep = separator)) |> + pull(foo) + ) + + expect_equal( + mutate(test, foo = paste0(x1, "he")) |> + pull(foo), + mutate(test_df, foo = paste0(x1, "he")) |> + pull(foo) + ) + + expect_equal( + mutate(test, foo = paste0(x1, "he", x1)) |> + pull(foo), + mutate(test_df, foo = paste0(x1, "he", x1)) |> + pull(foo) + ) + } + ) }) patrick::with_parameters_test_that( - "several non-regex functions work", - { - for_all( - tests = 40, - string = character_(any_na = TRUE), - property = function(string) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - pl_code <- paste0("mutate(test, foo = ", fun, "(string)) |> pull(foo)") - tv_code <- paste0( - "mutate(test_df, foo = ", - fun, - "(string)) |> pull(foo)" - ) - - expect_equal( - eval(parse(text = pl_code)), - eval(parse(text = tv_code)), - ) - } - ) - }, - fun = c("str_to_upper", "str_to_lower", "str_length", "str_squish") + "several non-regex functions work", + { + for_all( + tests = 40, + string = character_(any_na = TRUE), + property = function(string) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + pl_code <- paste0("mutate(test, foo = ", fun, "(string)) |> pull(foo)") + tv_code <- paste0( + "mutate(test_df, foo = ", + fun, + "(string)) |> pull(foo)" + ) + + expect_equal( + eval(parse(text = pl_code)), + eval(parse(text = tv_code)), + ) + } + ) + }, + fun = c("str_to_upper", "str_to_lower", "str_length", "str_squish") ) test_that("str_trim() works", { - for_all( - tests = 40, - string = character_(any_na = TRUE), - side = quickcheck::one_of( - constant("both"), - constant("left"), - constant("right") - ), - property = function(string, side) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - expect_equal( - mutate(test, foo = str_trim(x1)) |> - pull(foo), - mutate(test_df, foo = str_trim(x1)) |> - pull(foo) - ) - - expect_equal( - mutate(test, foo = str_trim(x1, side = side)) |> - pull(foo), - mutate(test_df, foo = str_trim(x1, side = side)) |> - pull(foo) - ) - } - ) + for_all( + tests = 40, + string = character_(any_na = TRUE), + side = quickcheck::one_of( + constant("both"), + constant("left"), + constant("right") + ), + property = function(string, side) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + expect_equal( + mutate(test, foo = str_trim(x1)) |> + pull(foo), + mutate(test_df, foo = str_trim(x1)) |> + pull(foo) + ) + + expect_equal( + mutate(test, foo = str_trim(x1, side = side)) |> + pull(foo), + mutate(test_df, foo = str_trim(x1, side = side)) |> + pull(foo) + ) + } + ) }) # TODO: Problem is that I don't have a way to check that length of string is the @@ -130,66 +130,66 @@ test_that("str_trim() works", { # }) test_that("str_dup() works", { - for_all( - tests = 100, - string = character_(any_na = TRUE), - # Very high numbers crash the session, I guess because of stringr - times = numeric_bounded(-10000, 10000, any_na = TRUE), - property = function(string, times) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = str_dup(x1, times = times)) |> - pull(foo), - mutate(test_df, foo = str_dup(x1, times = times)) |> - pull(foo) - ) - } - ) + for_all( + tests = 100, + string = character_(any_na = TRUE), + # Very high numbers crash the session, I guess because of stringr + times = numeric_bounded(-10000, 10000, any_na = TRUE), + property = function(string, times) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = str_dup(x1, times = times)) |> + pull(foo), + mutate(test_df, foo = str_dup(x1, times = times)) |> + pull(foo) + ) + } + ) }) test_that("str_sub() works", { - for_all( - tests = 200, - string = character_(any_na = TRUE), - start = numeric_(any_na = TRUE), - end = numeric_(any_na = TRUE), - property = function(string, start, end) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = str_sub(x1, start, end)) |> - pull(foo), - mutate(test_df, foo = str_sub(x1, start, end)) |> - pull(foo) - ) - } - ) + for_all( + tests = 200, + string = character_(any_na = TRUE), + start = numeric_(any_na = TRUE), + end = numeric_(any_na = TRUE), + property = function(string, start, end) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = str_sub(x1, start, end)) |> + pull(foo), + mutate(test_df, foo = str_sub(x1, start, end)) |> + pull(foo) + ) + } + ) }) test_that("substr() works", { - # substr() doesn't error with different lengths but polars does. I don't want - # this weird case to prevent quickcheck to run, especially since this is a - # weird behavior in base R and we're more conservative on this. - length <- sample(1:10, 1) - - for_all( - tests = 200, - string = character_(any_na = TRUE, len = length), - start = numeric_(any_na = TRUE, len = length), - end = numeric_(any_na = TRUE, len = length), - property = function(string, start, end) { - test_df <- data.frame(x1 = string) - test <- pl$DataFrame(x1 = string) - - expect_equal_or_both_error( - mutate(test, foo = substr(x1, start, end)) |> - pull(foo), - mutate(test_df, foo = substr(x1, start, end)) |> - pull(foo) - ) - } - ) + # substr() doesn't error with different lengths but polars does. I don't want + # this weird case to prevent quickcheck to run, especially since this is a + # weird behavior in base R and we're more conservative on this. + length <- sample(1:10, 1) + + for_all( + tests = 200, + string = character_(any_na = TRUE, len = length), + start = numeric_(any_na = TRUE, len = length), + end = numeric_(any_na = TRUE, len = length), + property = function(string, start, end) { + test_df <- data.frame(x1 = string) + test <- pl$DataFrame(x1 = string) + + expect_equal_or_both_error( + mutate(test, foo = substr(x1, start, end)) |> + pull(foo), + mutate(test_df, foo = substr(x1, start, end)) |> + pull(foo) + ) + } + ) }) diff --git a/tests/testthat/test-utils_expr-lazy.R b/tests/testthat/test-utils_expr-lazy.R index 9f4bbc3a..4b2d6b45 100644 --- a/tests/testthat/test-utils_expr-lazy.R +++ b/tests/testthat/test-utils_expr-lazy.R @@ -3,63 +3,65 @@ Sys.setenv('TIDYPOLARS_TEST' = TRUE) test_that("internally, expressions are correctly split in pools", { - pl_iris <- as_polars_lf(iris) + pl_iris <- as_polars_lf(iris) - result <- translate_dots( - pl_iris, - x = Sepal.Length * 3, - Petal.Length = Petal.Length / x, - x = NULL, - mean_pl = mean(Petal.Length), - foo = Sepal.Width + Petal.Width, - env = rlang::current_env(), - caller = rlang::current_env() - ) - expected <- list( - pool_exprs_1 = list( - x = pl$col("Sepal.Length") * 3, - foo = pl$col("Sepal.Width") + pl$col("Petal.Width") - ), - pool_exprs_2 = list( - Petal.Length = pl$col("Petal.Length") / pl$col("x"), - x = NULL - ), - pool_exprs_3 = list( - mean_pl = pl$col("Petal.Length")$mean() - ) - ) + result <- translate_dots( + pl_iris, + x = Sepal.Length * 3, + Petal.Length = Petal.Length / x, + x = NULL, + mean_pl = mean(Petal.Length), + foo = Sepal.Width + Petal.Width, + env = rlang::current_env(), + caller = rlang::current_env() + ) + expected <- list( + pool_exprs_1 = list( + x = pl$col("Sepal.Length") * 3, + foo = pl$col("Sepal.Width") + pl$col("Petal.Width") + ), + pool_exprs_2 = list( + Petal.Length = pl$col("Petal.Length") / pl$col("x"), + x = NULL + ), + pool_exprs_3 = list( + mean_pl = pl$col("Petal.Length")$mean() + ) + ) - expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) - expect_true(result$pool_exprs_1$foo$meta$eq(expected$pool_exprs_1$foo)) - expect_true(result$pool_exprs_2$Petal.Length$meta$eq(expected$pool_exprs_2$Petal.Length)) + expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) + expect_true(result$pool_exprs_1$foo$meta$eq(expected$pool_exprs_1$foo)) + expect_true( + result$pool_exprs_2$Petal.Length$meta$eq(expected$pool_exprs_2$Petal.Length) + ) - result <- translate_dots( - pl_iris, - x = 1, - x = "a", - x = NULL, - env = rlang::current_env(), - caller = rlang::current_env() - ) - expected <- list( - pool_exprs_1 = list(x = pl$lit(1)), - pool_exprs_2 = list(x = pl$lit("a")), - pool_exprs_3 = list(x = NULL) - ) - expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) - expect_true(result$pool_exprs_2$x$meta$eq(expected$pool_exprs_2$x)) + result <- translate_dots( + pl_iris, + x = 1, + x = "a", + x = NULL, + env = rlang::current_env(), + caller = rlang::current_env() + ) + expected <- list( + pool_exprs_1 = list(x = pl$lit(1)), + pool_exprs_2 = list(x = pl$lit("a")), + pool_exprs_3 = list(x = NULL) + ) + expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) + expect_true(result$pool_exprs_2$x$meta$eq(expected$pool_exprs_2$x)) }) test_that("error messages when error in known function is good", { - pl_iris <- as_polars_lf(iris) - expect_snapshot_lazy( - pl_iris |> mutate(foo = min_rank()), - error = TRUE - ) - expect_snapshot_lazy( - pl_iris |> mutate(foo = dplyr::min_rank()), - error = TRUE - ) + pl_iris <- as_polars_lf(iris) + expect_snapshot_lazy( + pl_iris |> mutate(foo = min_rank()), + error = TRUE + ) + expect_snapshot_lazy( + pl_iris |> mutate(foo = dplyr::min_rank()), + error = TRUE + ) }) Sys.setenv('TIDYPOLARS_TEST' = FALSE) diff --git a/tests/testthat/test-utils_expr.R b/tests/testthat/test-utils_expr.R index 81e4865f..8144ef5f 100644 --- a/tests/testthat/test-utils_expr.R +++ b/tests/testthat/test-utils_expr.R @@ -1,59 +1,61 @@ test_that("internally, expressions are correctly split in pools", { - pl_iris <- as_polars_df(iris) + pl_iris <- as_polars_df(iris) - result <- translate_dots( - pl_iris, - x = Sepal.Length * 3, - Petal.Length = Petal.Length / x, - x = NULL, - mean_pl = mean(Petal.Length), - foo = Sepal.Width + Petal.Width, - env = rlang::current_env(), - caller = rlang::current_env() - ) - expected <- list( - pool_exprs_1 = list( - x = pl$col("Sepal.Length") * 3, - foo = pl$col("Sepal.Width") + pl$col("Petal.Width") - ), - pool_exprs_2 = list( - Petal.Length = pl$col("Petal.Length") / pl$col("x"), - x = NULL - ), - pool_exprs_3 = list( - mean_pl = pl$col("Petal.Length")$mean() - ) - ) + result <- translate_dots( + pl_iris, + x = Sepal.Length * 3, + Petal.Length = Petal.Length / x, + x = NULL, + mean_pl = mean(Petal.Length), + foo = Sepal.Width + Petal.Width, + env = rlang::current_env(), + caller = rlang::current_env() + ) + expected <- list( + pool_exprs_1 = list( + x = pl$col("Sepal.Length") * 3, + foo = pl$col("Sepal.Width") + pl$col("Petal.Width") + ), + pool_exprs_2 = list( + Petal.Length = pl$col("Petal.Length") / pl$col("x"), + x = NULL + ), + pool_exprs_3 = list( + mean_pl = pl$col("Petal.Length")$mean() + ) + ) - expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) - expect_true(result$pool_exprs_1$foo$meta$eq(expected$pool_exprs_1$foo)) - expect_true(result$pool_exprs_2$Petal.Length$meta$eq(expected$pool_exprs_2$Petal.Length)) + expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) + expect_true(result$pool_exprs_1$foo$meta$eq(expected$pool_exprs_1$foo)) + expect_true( + result$pool_exprs_2$Petal.Length$meta$eq(expected$pool_exprs_2$Petal.Length) + ) - result <- translate_dots( - pl_iris, - x = 1, - x = "a", - x = NULL, - env = rlang::current_env(), - caller = rlang::current_env() - ) - expected <- list( - pool_exprs_1 = list(x = pl$lit(1)), - pool_exprs_2 = list(x = pl$lit("a")), - pool_exprs_3 = list(x = NULL) - ) - expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) - expect_true(result$pool_exprs_2$x$meta$eq(expected$pool_exprs_2$x)) + result <- translate_dots( + pl_iris, + x = 1, + x = "a", + x = NULL, + env = rlang::current_env(), + caller = rlang::current_env() + ) + expected <- list( + pool_exprs_1 = list(x = pl$lit(1)), + pool_exprs_2 = list(x = pl$lit("a")), + pool_exprs_3 = list(x = NULL) + ) + expect_true(result$pool_exprs_1$x$meta$eq(expected$pool_exprs_1$x)) + expect_true(result$pool_exprs_2$x$meta$eq(expected$pool_exprs_2$x)) }) test_that("error messages when error in known function is good", { - pl_iris <- as_polars_df(iris) - expect_snapshot( - pl_iris |> mutate(foo = min_rank()), - error = TRUE - ) - expect_snapshot( - pl_iris |> mutate(foo = dplyr::min_rank()), - error = TRUE - ) + pl_iris <- as_polars_df(iris) + expect_snapshot( + pl_iris |> mutate(foo = min_rank()), + error = TRUE + ) + expect_snapshot( + pl_iris |> mutate(foo = dplyr::min_rank()), + error = TRUE + ) })