tests/testthat/test-data_preprocessing.R

test_that("preprocess_text basic lowercasing and punctuation", {
  input <- "I'M so HAPPY!!!"
  output <- preprocess_text(input)
  expect_true(grepl("i am so happy !", output))
})

test_that("preprocess_text handles contractions", {
  input <- "She's not here. He'll come later."
  output <- preprocess_text(input)
  expect_true(grepl("she is not here", output))
  expect_true(grepl("he will come later", output))
})

test_that("preprocess_text handles internet slang and emoticons when use_textclean = TRUE", {
  input <- "2nite I'm happy)"
  output <- preprocess_text(input, use_textclean = TRUE)
  expect_true(grepl("tonight i am happy", output))
  expect_false(grepl(":\\)", output))
})

test_that("preprocess_text respects custom slang", {
  custom <- c("hbu" = "how about you")
  input <- "hbu tbh"
  output <- preprocess_text(input, use_textclean = FALSE, custom_slang = custom)
  expect_true(grepl("how about you to be honest", output))
})

test_that("preprocess_text output is character", {
  input <- "Simple text"
  output <- preprocess_text(input)
  expect_type(output, "character")
})

Try the text2emotion package in your browser

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

text2emotion documentation built on June 8, 2025, 1:04 p.m.