tests/testthat/test-spelling.R

get_result <- function(res, check) res$passed[res$check == check]

test_that("spelling fails when misspelled words exist", {
  gp_res <- gp("bad_spelling", checks = "spelling")
  res <- results(gp_res)
  expect_false(get_result(res, "spelling"))

  pos <- failed_positions(gp_res)$spelling
  words <- vapply(pos, `[[`, "", "line")
  expect_true(any(grepl("incremnet", words)))
})

test_that("spelling passes when no misspellings exist", {
  gp_res <- gp("good", checks = "spelling")
  res <- results(gp_res)
  expect_true(get_result(res, "spelling"))
})

test_that("spelling returns NA when no inst/WORDLIST exists", {
  state <- list(spelling = "no_wordlist")
  result <- CHECKS$spelling$check(state)
  expect_true(is.na(result$status))
  expect_identical(result$positions, list())
})

Try the goodpractice package in your browser

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

goodpractice documentation built on June 5, 2026, 5:06 p.m.