diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-15 11:56:04 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-21 20:14:56 +0300 |
commit | 761446e34af7a81d0516e322228616ebd046c9ba (patch) | |
tree | 6a232c099e061960be812a579b174d3ca5d50ea3 /staging/adblock/test/filterlist.cpp | |
parent | Add some FilterList tests (diff) | |
download | smolbote-761446e34af7a81d0516e322228616ebd046c9ba.tar.xz |
Fix MatcherRule with DomainMatch
Diffstat (limited to 'staging/adblock/test/filterlist.cpp')
-rw-r--r-- | staging/adblock/test/filterlist.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
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<std::pair<QString, bool>, 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<std::pair<QString, bool>, 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; } |