From 1ea9d8f4c2514c1e4c0764fed4ae704739ef5775 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 29 Oct 2024 11:33:29 +0100 Subject: [PATCH] write tests for [.teal_data --- tests/testthat/test-extract.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/testthat/test-extract.R diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R new file mode 100644 index 000000000..21506c4f0 --- /dev/null +++ b/tests/testthat/test-extract.R @@ -0,0 +1,16 @@ +testthat::test_that("`[.` returns empty teal_data for improper names", { + data <- teal_data(x = 1, a = 2) + testthat::expect_equal(data["y"], teal_data()) +}) + +testthat::test_that("`[.` returns limited join_keys", { + data <- teal_data(a = 1, b = 2) + + join_keys(data) <- join_keys(join_key("a", "b", "x")) + empty_join_keys <- join_keys() + attr(empty_join_keys, "names") <- character(0) + testthat::expect_equal( + join_keys(data["a"]), # By default named list || names() is character(0) + empty_join_keys # By default unnamed list || names() is NULL + ) +})