是否可以在test_that()或expect_XXX()调用中写入否定条件?具体来说,我想测试一个不包含子字符串的字符串,如下所示:
expect_that("Apples, Oranges, Banana", !matches('Onion'))
或
expect_not_match("Apples, Oranges, Banana", 'Onion')
我知道我可以将expect_true()与例如: grep的:
expect_true(length(grep("Onion", "Apples, Oranges, Banana")) == 0)
但这看起来并不太可读。
答案 0 :(得分:4)
testthat::not
怎么样?
expect_that("Apples, Oranges, Banana", not(matches('Onion')))