From ad7c31e042788dbc80a15e1674c1e2827af1041b Mon Sep 17 00:00:00 2001 From: we Date: Mon, 17 Jul 2023 10:08:24 +0800 Subject: [PATCH] test no error for variable end with `_temp`(#2012) --- tests/testthat/test-derive_vars_dy.R | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/testthat/test-derive_vars_dy.R b/tests/testthat/test-derive_vars_dy.R index e619550f76..e567195dd9 100644 --- a/tests/testthat/test-derive_vars_dy.R +++ b/tests/testthat/test-derive_vars_dy.R @@ -285,3 +285,35 @@ test_that("derive_vars_dy Test 9: Single named --DT input when ref date is --DTM keys = c("STUDYID", "USUBJID") ) }) + +## Test 10: no error if input with variable end with `_temp` ---- +test_that("derive_vars_dy Test 10: no error if input with variable end with `_temp`", { + datain <- tibble::tribble( + ~STUDYID, ~USUBJID, ~TRTSDTM, ~ASTDT, ~test_temp, + "TEST01", "PAT01", "2014-01-17T23:59:59", "2014-01-18", "test" + ) %>% + mutate( + TRTSDTM = lubridate::as_datetime(TRTSDTM), + ASTDT = lubridate::ymd(ASTDT) + ) + + expected_output <- tibble::tribble( + ~STUDYID, ~USUBJID, ~TRTSDTM, ~ASTDT, ~test_temp, ~ASTDY, + "TEST01", "PAT01", "2014-01-17T23:59:59", "2014-01-18", "test", 2 + ) %>% + mutate( + TRTSDTM = lubridate::as_datetime(TRTSDTM), + ASTDT = lubridate::ymd(ASTDT) + ) + + actual_output <- derive_vars_dy(datain, + reference_date = TRTSDTM, + source_vars = exprs(ASTDT) + ) + + expect_dfs_equal( + expected_output, + actual_output, + keys = c("STUDYID", "USUBJID") + ) +})