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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include "catch.hpp"
#include <regexmanager.h>
#include <exceptions.h>
using namespace newsboat;
TEST_CASE("RegexManager throws on invalid `highlight' definition",
"[regexmanager]")
{
regexmanager rxman;
std::vector<std::string> params;
SECTION("on `highlight' without parameters") {
REQUIRE_THROWS_AS(rxman.handle_action("highlight", params),
confighandlerexception);
}
SECTION("on invalid location") {
params = {"invalidloc", "foo", "blue", "red"};
REQUIRE_THROWS_AS(rxman.handle_action("highlight", params),
confighandlerexception);
}
SECTION("on invalid regex") {
params = {"feedlist", "*", "blue", "red"};
REQUIRE_THROWS_AS(rxman.handle_action("highlight", params),
confighandlerexception);
}
SECTION("on invalid command") {
REQUIRE_THROWS_AS(rxman.handle_action("an-invalid-command", params),
confighandlerexception);
}
}
TEST_CASE("RegexManager doesn't throw on valid `highlight' definition",
"[regexmanager]")
{
regexmanager rxman;
std::vector<std::string> params;
params = {"articlelist", "foo", "blue", "red"};
REQUIRE_NOTHROW(rxman.handle_action("highlight", params));
params = {"feedlist", "foo", "blue", "red"};
REQUIRE_NOTHROW(rxman.handle_action("highlight", params));
params = {"feedlist", "fbo", "blue", "red", "bold", "underline"};
REQUIRE_NOTHROW(rxman.handle_action("highlight", params));
params = {"all", "fba", "blue", "red", "bold", "underline"};
REQUIRE_NOTHROW(rxman.handle_action("highlight", params));
}
TEST_CASE("RegexManager highlights according to definition",
"[regexmanager]")
{
regexmanager rxman;
std::string input;
rxman.handle_action("highlight", {"articlelist", "foo", "blue", "red"});
input = "xfoox";
rxman.quote_and_highlight(input, "articlelist");
REQUIRE(input == "x<0>foo</>x");
rxman.handle_action("highlight", {"feedlist", "foo", "blue", "red"});
input = "yfooy";
rxman.quote_and_highlight(input, "feedlist");
REQUIRE(input == "y<0>foo</>y");
}
TEST_CASE("RegexManager preserves text when there's nothing to highlight",
"[regexmanager]")
{
regexmanager rxman;
std::string input = "xbarx";
rxman.quote_and_highlight(input, "feedlist");
REQUIRE(input == "xbarx");
input = "<";
rxman.quote_and_highlight(input, "feedlist");
REQUIRE(input == "<");
input = "a<b>";
rxman.quote_and_highlight(input, "feedlist");
REQUIRE(input == "a<b>");
}
TEST_CASE("`highlight all` adds rules for all locations", "[regexmanager]") {
regexmanager rxman;
std::vector<std::string> params = {"all", "foo", "red"};
REQUIRE_NOTHROW(rxman.handle_action("highlight", params));
std::string input = "xxfooyy";
for (auto location : {"article", "articlelist", "feedlist"}) {
SECTION(location) {
rxman.quote_and_highlight(input, location);
REQUIRE(input == "xx<0>foo</>yy");
}
}
}
|