diff --git a/R/replace_contraction.R b/R/replace_contraction.R index 93cfca3..156d682 100644 --- a/R/replace_contraction.R +++ b/R/replace_contraction.R @@ -26,7 +26,7 @@ function(x, contraction.key = lexicon::key_contractions, ignore.case=TRUE, ...) { mgsub(x, contraction.key[[1]], contraction.key[[2]], - fixed = FALSE, ignore.case=TRUE) + fixed = FALSE, ignore.case = ignore.case) } diff --git a/tests/testthat/test-replace_contraction.R b/tests/testthat/test-replace_contraction.R new file mode 100755 index 0000000..3513d10 --- /dev/null +++ b/tests/testthat/test-replace_contraction.R @@ -0,0 +1,15 @@ +context("Checking replace_contraction") + +test_that("replace_contraction replaces contractions with ignore.case=TRUE (default)", { + x <- c("Mr. Jones isn't going.", "She's here but didn't go.", "It ISN'T here") + result <- replace_contraction(x) + expect_true(grepl("is not", result[1])) + expect_true(grepl("did not", result[2])) + expect_true(grepl("is not", result[2])) +}) + +test_that("replace_contraction respects ignore.case=FALSE", { + x <- c("ISN'T going", "isn't going") + expect_equal(replace_contraction(x, ignore.case = FALSE)[1], "ISN'T going") + expect_true(grepl("is not", replace_contraction(x, ignore.case = FALSE)[2])) +}) \ No newline at end of file