diff --git a/app/logic/general_utils.R b/app/logic/general_utils.R index 1f5fa47..0b39d69 100644 --- a/app/logic/general_utils.R +++ b/app/logic/general_utils.R @@ -18,7 +18,7 @@ check_text_error <- function( ignore_case = TRUE ) { grepl( - paste(wordlist, collapse = "|"), + paste0("^", wordlist, collapse = "|"), text, ignore.case = ignore_case ) diff --git a/tests/testthat/test-general_utils.R b/tests/testthat/test-general_utils.R index a298404..dd767b2 100644 --- a/tests/testthat/test-general_utils.R +++ b/tests/testthat/test-general_utils.R @@ -34,6 +34,19 @@ describe("check_text_error()", { ) }) + it("handles 'no error' and similar cases gracefully", { + expect_true( + !check_text_error( + "No error detected" + ) + ) + expect_true( + !check_text_error( + "No errors found" + ) + ) + }) + it("returns FALSE for non-error keywords", { expect_true( !check_text_error(