tests/testthat/stringr-imported/test-wrap.R

test_that("wrapping removes spaces", {
  expect_equal(str_wrap(""), "")
  expect_equal(str_wrap(" "), "")
  expect_equal(str_wrap("  a  "), "a")
})

test_that("wrapping with width of 0 puts each word on own line", {
  # charr change: upstream stringr uses magrittr's %>% here. charr does not
  # import or re-export magrittr, so this test uses the native pipe instead.
  n_returns <- letters |>
    str_c(collapse = " ") |>
    str_wrap(0) |>
    str_count("\n")
  expect_equal(n_returns, length(letters) - 1)
})

test_that("wrapping at whitespace break works", {
  expect_equal(str_wrap("a/b", width = 0, whitespace_only = TRUE), "a/b")
  expect_equal(str_wrap("a/b", width = 0, whitespace_only = FALSE), "a/\nb")
})

test_that("str_wrap() preserves names", {
  x <- c(C = "3", B = "2", A = "1")
  expect_equal(names(str_wrap(x)), names(x))
})

Try the charr package in your browser

Any scripts or data that you put into this service are public.

charr documentation built on Nov. 7, 2026, 9:06 a.m.