From 761446e34af7a81d0516e322228616ebd046c9ba Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 15 Apr 2020 11:56:04 +0300 Subject: Fix MatcherRule with DomainMatch --- staging/adblock/test/filterlist.cpp | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'staging/adblock/test/filterlist.cpp') diff --git a/staging/adblock/test/filterlist.cpp b/staging/adblock/test/filterlist.cpp index 6b27904..4366489 100644 --- a/staging/adblock/test/filterlist.cpp +++ b/staging/adblock/test/filterlist.cpp @@ -22,40 +22,44 @@ TEST_CASE("placeholder") TEST_CASE("domain match") { - const std::array, 5> testUrls = { - std::make_pair("http://ads.example.com/foo.gif", true), - std::make_pair("http://server1.ads.example.com/foo.gif", true), - std::make_pair("https://ads.example.com:8000/", true), - std::make_pair("http://ads.example.com.ua/foo.gif", false), - std::make_pair("http://example.com/redirect/http://ads.example.com/", false) - }; + const QString block1 = "http://ads.example.com/foo.gif"; + const QString block2 = "http://server1.ads.example.com/foo.gif"; + const QString block3 = "https://ads.example.com:8000/"; + const QString block4 = "https://ads.example.com"; + + const QString allow1 = "http://ads.example.com.ua/foo.gif"; + const QString allow2 = "http://example.com/redirect/http://ads.example.com/"; auto *rule = FilterList::parseRule("||ads.example.com^"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); - for(const auto &pair : testUrls) { - REQUIRE(rule->hasMatch(&pair.first) == pair.second); - } + REQUIRE(rule->hasMatch(&block1)); + REQUIRE(rule->hasMatch(&block2)); + REQUIRE(rule->hasMatch(&block3)); + REQUIRE(rule->hasMatch(&block4)); + + REQUIRE(!rule->hasMatch(&allow1)); + REQUIRE(!rule->hasMatch(&allow2)); delete rule; } TEST_CASE("string equals") { - const std::array, 3> testUrls = { - std::make_pair("http://example.com/", true), - std::make_pair("http://example.com/foo.gif", false), - std::make_pair("http://example.info/redirect/http://example.com/", false) - }; + const QString block = "http://example.com/"; + + const QString allow1 = "http://example.com/foo.gif"; + const QString allow2 = "http://example.info/redirect/http://example.com/"; auto *rule = FilterList::parseRule("|http://example.com/|"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); - for(const auto &pair : testUrls) { - REQUIRE(rule->hasMatch(&pair.first) == pair.second); - } + REQUIRE(rule->hasMatch(&block)); + + REQUIRE(!rule->hasMatch(&allow1)); + REQUIRE(!rule->hasMatch(&allow2)); delete rule; } -- cgit v1.2.1