tests/testthat/helpers.R

expect_n_sentences <- function(lorem, n) {
  x <- format(lorem)
  paras <- unlist(strsplit(x, "\n\n"))
  sentences <- strsplit(paras, " ")

  for (i in seq_along(sentences)) {
    words <- sentences[[i]]
    n_sentences <- sum(grepl("[.!?]", words))
    n_expected <- as.integer(n[[i]])
    expect_equal(n_sentences, n_expected)
  }

  invisible(lorem)
}
gadenbuie/lorem documentation built on March 18, 2023, 9:19 a.m.