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

test_that("word extraction", {
  expect_equal("walk", word("walk the moon"))
  expect_equal("walk", word("walk the moon", 1))
  expect_equal("moon", word("walk the moon", 3))
  expect_equal("the moon", word("walk the moon", 2, 3))
})

test_that("words past end return NA", {
  expect_equal(word("a b c", 4), NA_character_)
})

test_that("negative parameters", {
  expect_equal("moon", word("walk the moon", -1, -1))
  expect_equal("walk the moon", word("walk the moon", -3, -1))
  expect_equal("walk the moon", word("walk the moon", -5, -1))
})

test_that("word() preserves names", {
  x <- c(C = "3", B = "2", A = "1")
  expect_equal(names(word(x, 1)), 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.