#include "jvalidate/regex.h" #include "gtest/gtest.h" #include #include using testing::IsEmpty; using testing::Not; template class RegexEngineTest : public testing::Test {}; using RegexEngines = testing::Types; TYPED_TEST_SUITE(RegexEngineTest, RegexEngines); TYPED_TEST(RegexEngineTest, HasEngineName) { EXPECT_THAT(TypeParam::engine_name(), Not(IsEmpty())); } TYPED_TEST(RegexEngineTest, IsRegexIsNoexceptOnBadRegex) { EXPECT_NO_THROW(TypeParam::is_regex("(ABC){1,2")); EXPECT_FALSE(TypeParam::is_regex("(ABC){1,2")); } TYPED_TEST(RegexEngineTest, IsRegexIsNoexceptOnGoodRegex) { EXPECT_NO_THROW(TypeParam::is_regex("(ABC){1,2}")); EXPECT_TRUE(TypeParam::is_regex("(ABC){1,2}")); } TYPED_TEST(RegexEngineTest, SearchCanMatchSubstring) { EXPECT_NO_THROW(TypeParam().search("\\d", "10 dollars")); EXPECT_TRUE(TypeParam().search("\\d", "10 dollars")); } TYPED_TEST(RegexEngineTest, SearchCanSetBoundaries) { EXPECT_NO_THROW(TypeParam().search("^\\d$", "10 dollars")); EXPECT_FALSE(TypeParam().search("^\\d$", "10 dollars")); } TYPED_TEST(RegexEngineTest, SearchIsNoexceptOnBadRegex) { EXPECT_NO_THROW(TypeParam().search("(ABC){1,2", "ABC")); EXPECT_FALSE(TypeParam().search("(ABC){1,2", "ABC")); } #if !defined(JVALIDATE_MONOTEST) int main(int argc, char ** argv) { testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); } #endif