#define CATCH_CONFIG_MAIN #include "rule.h" #include SCENARIO("MatcherRule") { GIVEN("options with case sensitive pattern") { const AdblockPlus::Options opt { .matchcase=true }; const QString patternContains("this string contains the pattern in it"); const QString patternBegins("pattern starts this string"); const QString patternEnds("this string ends with pattern"); const QString patternMissing("and this one does not"); WHEN("contains") { AdblockPlus::MatcherRule rule("pattern", opt); REQUIRE(rule.shouldBlock()); THEN("pattern is matched anywhere in the URL") { REQUIRE(rule.hasMatch(&patternContains)); REQUIRE(rule.hasMatch(&patternBegins)); REQUIRE(rule.hasMatch(&patternEnds)); REQUIRE(!rule.hasMatch(&patternMissing)); } } WHEN("startsWith") { AdblockPlus::MatcherRule rule("pattern", opt, AdblockPlus::MatcherRule::UrlStartsWith); REQUIRE(rule.shouldBlock()); THEN("pattern is matched if at the start of the URL") { REQUIRE(!rule.hasMatch(&patternContains)); REQUIRE(rule.hasMatch(&patternBegins)); REQUIRE(!rule.hasMatch(&patternEnds)); REQUIRE(!rule.hasMatch(&patternMissing)); } } WHEN("endsWith") { AdblockPlus::MatcherRule rule("pattern", opt, AdblockPlus::MatcherRule::UrlEndsWith); REQUIRE(rule.shouldBlock()); THEN("pattern is matched if at the end of the URL") { REQUIRE(!rule.hasMatch(&patternContains)); REQUIRE(!rule.hasMatch(&patternBegins)); REQUIRE(rule.hasMatch(&patternEnds)); REQUIRE(!rule.hasMatch(&patternMissing)); } } } } SCENARIO("RegexRule") { GIVEN("options with case sensitive pattern") { const AdblockPlus::Options opt { .matchcase=true }; const QString patternContains("this string contains the pattern in it"); const QString patternMissing("and this one does not"); WHEN("contains") { AdblockPlus::RegexRule rule("pattern", opt); REQUIRE(rule.shouldBlock()); THEN("pattern is matched anywhere in the URL") { REQUIRE(rule.hasMatch(&patternContains)); REQUIRE(!rule.hasMatch(&patternMissing)); } } } }