commit 05ecf617127db02bd9d3ecfc886b7f7239a95956
parent 47eac115940fe8a59c760ef512ad334135757c0e
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date: Fri, 26 Feb 2016 21:30:29 -0500
Testing error checking.
Diffstat:
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tests/testthat/test_patternapply.R b/tests/testthat/test_patternapply.R
@@ -12,6 +12,17 @@ test_that("Simple call returned correct results", {
expect_equal(patternapplyResultVector, as.list(c(letters[1:9], 10:26)))
expect_equal(class(patternapplyResult), "replacement_list")
expect_equal(attr(patternapplyResult, "col_names"), "match_1")
- expect_equal(attr(patternapplyResult, "match_index"),
+ expect_equal(attr(patternapplyResult, "match_index"),
c(rep(2, 9), rep(1, 26-9)))
})
+
+test_that("Bad inputs raise errors", {
+ expect_error(patternapply(letters, 1, list("a")),
+ "'patterns' must be a character vector")
+ expect_error(patternapply(letters, "a", "a"),
+ "'replacements' must be a list")
+ expect_error(patternapply(letters, c("a", "b"), list(1, "a")),
+ "'replacements' can only contain character vectors")
+ expect_error(patternapply(letters, c("a", "b"), list("c")),
+ "'patterns' and 'replacements' must have the same length")
+})