From 0c19ade80555a869a0f711542a5d2dae6a4df3b3 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Tue, 17 Sep 2024 14:38:21 -0700 Subject: [PATCH] add tests --- tests/testthat/_snaps/coerce.md | 24 +++++++++++++++++++++ tests/testthat/test-coerce.R | 37 ++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/coerce.md b/tests/testthat/_snaps/coerce.md index 4160978..26ddd55 100644 --- a/tests/testthat/_snaps/coerce.md +++ b/tests/testthat/_snaps/coerce.md @@ -31,6 +31,22 @@ sparsevctrs: Sparse vector materialized sparsevctrs: Sparse vector materialized +# coerce_to_sparse_matrix() can pass through error call + + Code + tmp_fun(1) + Condition + Error in `tmp_fun()`: + ! `x` must be a , not a number. + +--- + + Code + tmp_fun(1) + Condition + Error in `tmp_fun()`: + ! `x` must be a , not a number. + # coerce_to_sparse_data_frame() errors with no column names Code @@ -55,6 +71,14 @@ Error in `coerce_to_sparse_data_frame()`: ! `x` must be a , not an integer vector. +# coerce_to_sparse_data_frame() can pass through error call + + Code + tmp_fun(1) + Condition + Error in `tmp_fun()`: + ! `x` must be a , not a number. + # coerce_to_sparse_tibble() errors with no column names Code diff --git a/tests/testthat/test-coerce.R b/tests/testthat/test-coerce.R index 854a9e4..51b47ee 100644 --- a/tests/testthat/test-coerce.R +++ b/tests/testthat/test-coerce.R @@ -79,6 +79,17 @@ test_that("coerce_to_sparse_matrix() materializes non-zero defaulted columns", { expect_identical(res, exp) }) +test_that("coerce_to_sparse_matrix() can pass through error call", { + tmp_fun <- function(x) { + coerce_to_sparse_matrix(x, call = rlang::caller_env(0)) + } + + expect_snapshot( + error = TRUE, + tmp_fun(1) + ) +}) + ### coerce_to_sparse_data_frame ------------------------------------------------ test_that("coerce_to_sparse_data_frame() works", { @@ -140,6 +151,17 @@ test_that("coerce_to_sparse_data_frame() errors with wrong input", { ) }) +test_that("coerce_to_sparse_data_frame() can pass through error call", { + tmp_fun <- function(x) { + coerce_to_sparse_data_frame(x, call = rlang::caller_env(0)) + } + + expect_snapshot( + error = TRUE, + tmp_fun(1) + ) +}) + ### coerce_to_sparse_tibble ---------------------------------------------------- test_that("coerce_to_sparse_tibble() works", { @@ -204,6 +226,19 @@ test_that("coerce_to_sparse_tibble() errors with wrong input", { ) }) +test_that("coerce_to_sparse_matrix() can pass through error call", { + tmp_fun <- function(x) { + coerce_to_sparse_tibble(x, call = rlang::caller_env(0)) + } + + expect_snapshot( + error = TRUE, + tmp_fun(1) + ) +}) + +### .sparse_matrix_to_list ----------------------------------------------------- + test_that(".sparse_matrix_to_list() handles fully sparse columns (#69)", { skip_if_not_installed("Matrix") @@ -220,4 +255,4 @@ test_that(".sparse_matrix_to_list() handles fully sparse columns (#69)", { coerce_to_sparse_data_frame(x_mat_sparse), x_df ) -}) \ No newline at end of file +})