|
| 1 | +test_that("keep_names preserves names when pattern is missing", { |
| 2 | + x <- c(A = "a", B = "b") |
| 3 | + |
| 4 | + # vector output |
| 5 | + out_vec <- c("x", "y") |
| 6 | + res_vec <- keep_names(out_vec, x) |
| 7 | + expect_equal(names(res_vec), names(x)) |
| 8 | + |
| 9 | + # matrix output |
| 10 | + out_mat <- matrix(c("x", "y"), nrow = 2) |
| 11 | + res_mat <- keep_names(out_mat, x) |
| 12 | + expect_equal(rownames(res_mat), names(x)) |
| 13 | +}) |
| 14 | + |
| 15 | +test_that("keep_names preserves names when pattern has length 1", { |
| 16 | + x <- c(A = "a", B = "b") |
| 17 | + pattern <- "p" |
| 18 | + |
| 19 | + # vector output |
| 20 | + out_vec <- c("x", "y") |
| 21 | + res_vec <- keep_names(out_vec, x, pattern) |
| 22 | + expect_equal(names(res_vec), names(x)) |
| 23 | + |
| 24 | + # matrix output |
| 25 | + out_mat <- matrix(c("x", "y"), nrow = 2) |
| 26 | + res_mat <- keep_names(out_mat, x, pattern) |
| 27 | + expect_equal(rownames(res_mat), names(x)) |
| 28 | +}) |
| 29 | + |
| 30 | +test_that("keep_names preserves names when pattern matches string length", { |
| 31 | + x <- c(A = "a", B = "b") |
| 32 | + pattern <- c("p1", "p2") |
| 33 | + |
| 34 | + # vector output |
| 35 | + out_vec <- c("x", "y") |
| 36 | + res_vec <- keep_names(out_vec, x, pattern) |
| 37 | + expect_equal(names(res_vec), names(x)) |
| 38 | + |
| 39 | + # matrix output |
| 40 | + out_mat <- matrix(c("x", "y"), nrow = 2) |
| 41 | + res_mat <- keep_names(out_mat, x, pattern) |
| 42 | + expect_equal(rownames(res_mat), names(x)) |
| 43 | +}) |
| 44 | + |
0 commit comments