blob: d1926010e4a2a3906960558067e8f2eb0d5d4fef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#define CATCH_CONFIG_MAIN
#include "rule.h"
#include <catch2/catch.hpp>
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));
}
}
}
}
|