blob: 31af7d5dd55cc16139e4e4758256673c424965c8 (
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
81
82
|
#define CATCH_CONFIG_MAIN
#include "rule.h"
#include <catch2/catch.hpp>
using namespace AdblockPlus;
SCENARIO("MatcherRule")
{
GIVEN("options with case sensitive pattern")
{
const 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")
{
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")
{
MatcherRule rule("pattern", opt, 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")
{
MatcherRule rule("pattern", opt, 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 Options opt { .matchcase=true };
const QString patternContains("this string contains the pattern in it");
const QString patternMissing("and this one does not");
WHEN("contains")
{
RegexRule rule("pattern", opt);
REQUIRE(rule.shouldBlock());
THEN("pattern is matched anywhere in the URL")
{
REQUIRE(rule.hasMatch(&patternContains));
REQUIRE(!rule.hasMatch(&patternMissing));
}
}
}
}
|