Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/testthat/test-flatten.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,43 @@ test_that("str_flatten_oxford removes comma iif necessary", {
expect_equal(str_flatten_comma(letters[1:3], " or "), "a, b or c")
expect_equal(str_flatten_comma(letters[1:3]), "a, b, c")
})

test_that("str_flatten handles empty input with last", {
expect_equal(str_flatten(character(), ", ", " and "), "")
expect_equal(str_flatten(character(), "-"), "")
})

test_that("str_flatten handles single element with last", {
expect_equal(str_flatten("a", ", ", " and "), "a")
expect_equal(str_flatten("a", "-"), "a")
})

test_that("str_flatten handles all-NA input with na.rm", {
expect_equal(str_flatten(c(NA, NA), na.rm = TRUE), "")
expect_equal(str_flatten(NA_character_, na.rm = TRUE), "")
})

test_that("str_flatten_comma handles empty input with last", {
expect_equal(str_flatten_comma(character(), ", or "), "")
expect_equal(str_flatten_comma(character()), "")
})

test_that("str_flatten_comma handles single element with last", {
expect_equal(str_flatten_comma("a", ", or "), "a")
expect_equal(str_flatten_comma("a"), "a")
})

test_that("str_flatten_comma handles NA with last and na.rm", {
expect_equal(
str_flatten_comma(c("a", NA, "b"), ", or ", na.rm = TRUE),
"a, or b"
)
expect_equal(
str_flatten_comma(c(NA, "a", "b"), ", or ", na.rm = TRUE),
"a, or b"
)
expect_equal(
str_flatten_comma(c("a", "b", NA), ", or ", na.rm = TRUE),
"a, or b"
)
})
Loading