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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
#include "rssignores.h"
#include "3rd-party/catch.hpp"
#include "cache.h"
#include "confighandlerexception.h"
#include "rssitem.h"
using namespace newsboat;
TEST_CASE(
"RssIgnores::matches_lastmodified() returns true if given url "
"has to always be downloaded",
"[RssIgnores]")
{
RssIgnores ignores;
ignores.handle_action("always-download", {
"http://newsboat.org",
"www.cool-website.com",
"www.example.com"
});
REQUIRE(ignores.matches_lastmodified("www.example.com"));
REQUIRE(ignores.matches_lastmodified("http://newsboat.org"));
REQUIRE(ignores.matches_lastmodified("www.cool-website.com"));
REQUIRE_FALSE(ignores.matches_lastmodified("www.smth.com"));
}
TEST_CASE(
"RssIgnores::matches_resetunread() returns true if given url "
"will always have its unread flag reset on update",
"[RssIgnores]")
{
RssIgnores ignores;
ignores.handle_action("reset-unread-on-update", {
"http://newsboat.org",
"www.cool-website.com",
"www.example.com"
});
REQUIRE(ignores.matches_resetunread("www.example.com"));
REQUIRE(ignores.matches_resetunread("http://newsboat.org"));
REQUIRE(ignores.matches_resetunread("www.cool-website.com"));
REQUIRE_FALSE(ignores.matches_resetunread("www.smth.com"));
}
TEST_CASE("RssIgnores::handle_action() handles `ignore-article`",
"[RssIgnores]")
{
RssIgnores ignores;
const std::string action = "ignore-article";
SECTION("Throws ConfigHandlerException if less than 2 parameters") {
REQUIRE_THROWS_AS(ignores.handle_action(action, {}), ConfigHandlerException);
REQUIRE_THROWS_AS(ignores.handle_action(action, {"param"}),
ConfigHandlerException);
}
SECTION("Throws ConfigHandlerException if second param can't be parsed as filter expression") {
REQUIRE_THROWS_AS(ignores.handle_action(action, {"url", "!?"}),
ConfigHandlerException);
}
SECTION("Doesn't throw on two or more params") {
REQUIRE_NOTHROW(ignores.handle_action(action, {"url", "expression = 1", "more"}));
REQUIRE_NOTHROW(ignores.handle_action(action, {"url", "expression = 1", "way", "more different", "parameters"}));
}
}
TEST_CASE("RssIgnores::handle_action() handles `always-download`",
"[RssIgnores]")
{
RssIgnores ignores;
const std::string action = "always-download";
SECTION("Throws ConfigHandlerException if given zero parameters") {
REQUIRE_THROWS_AS(ignores.handle_action(action, {}), ConfigHandlerException);
}
SECTION("Doesn't trow if given one or more parameters") {
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1"}));
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1", "url2"}));
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1", "url2", "url3", "url4", "url5"}));
}
}
TEST_CASE("RssIgnores::handle_action() handles `reset-unread-on-update`",
"[RssIgnores]")
{
RssIgnores ignores;
const std::string action = "reset-unread-on-update";
SECTION("Throws ConfigHandlerException if given zero parameters") {
REQUIRE_THROWS_AS(ignores.handle_action(action, {}), ConfigHandlerException);
}
SECTION("Doesn't throw if given one or more parameters") {
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1"}));
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1", "url2"}));
REQUIRE_NOTHROW(ignores.handle_action(action, {"url1", "url2", "url3", "url4", "url5"}));
}
}
TEST_CASE("RssIgnores::handle_action() throws ConfigHandlerException "
"on unknown command",
"[RssIgnores]")
{
RssIgnores ignores;
REQUIRE_THROWS_AS(ignores.handle_action("bind-key", {"ESC", "quit"}),
ConfigHandlerException);
REQUIRE_THROWS_AS(ignores.handle_action("auto-reload", {"yes"}),
ConfigHandlerException);
REQUIRE_THROWS_AS(ignores.handle_action("color", {"listnormal", "blue", "black"}),
ConfigHandlerException);
}
TEST_CASE("RssIgnores::dump_config() writes out all configured settings "
"to the provided vector",
"[RssIgnores]")
{
RssIgnores ignores;
SECTION("`ignore-article`") {
const std::string action = "ignore-article";
ignores.handle_action(action, {"https://example.com/feed.xml", "author =~ \"Joe\""});
ignores.handle_action(action, {"*", "title # \"interesting\""});
ignores.handle_action(action, {"https://blog.example.com/joe/posts.xml", "guid # 123"});
std::vector<std::string> config;
const auto comment =
"# Comment to check that RssIgnores::dump_config() doesn't clear the vector";
config.push_back(comment);
ignores.dump_config(config);
REQUIRE(config.size() == 4); // three actions plus one comment
REQUIRE(config[0] == comment);
REQUIRE(config[1] ==
R"#(ignore-article "https://example.com/feed.xml" "author =~ \"Joe\"")#");
REQUIRE(config[2] == R"#(ignore-article * "title # \"interesting\"")#");
REQUIRE(config[3] ==
R"#(ignore-article "https://blog.example.com/joe/posts.xml" "guid # 123")#");
}
SECTION("`always-download`") {
const std::string action = "always-download";
ignores.handle_action(action, {"url1"});
ignores.handle_action(action, {"url2", "url3", "url4"});
std::vector<std::string> config;
const auto comment =
"# Comment to check that RssIgnores::dump_config() doesn't clear the vector";
config.push_back(comment);
ignores.dump_config(config);
REQUIRE(config.size() == 5); // four URLs plus one comment
REQUIRE(config[0] == comment);
REQUIRE(config[1] == R"#(always-download "url1")#");
REQUIRE(config[2] == R"#(always-download "url2")#");
REQUIRE(config[3] == R"#(always-download "url3")#");
REQUIRE(config[4] == R"#(always-download "url4")#");
}
SECTION("`reset-unread-on-update`") {
const std::string action = "reset-unread-on-update";
ignores.handle_action(action, {"url1"});
ignores.handle_action(action, {"url2", "url3", "url4"});
std::vector<std::string> config;
const auto comment =
"# Comment to check that RssIgnores::dump_config() doesn't clear the vector";
config.push_back(comment);
ignores.dump_config(config);
REQUIRE(config.size() == 5); // four URLs plus one comment
REQUIRE(config[0] == comment);
REQUIRE(config[1] == R"#(reset-unread-on-update "url1")#");
REQUIRE(config[2] == R"#(reset-unread-on-update "url2")#");
REQUIRE(config[3] == R"#(reset-unread-on-update "url3")#");
REQUIRE(config[4] == R"#(reset-unread-on-update "url4")#");
}
SECTION("Mix of all supported commands") {
ignores.handle_action("reset-unread-on-update", {"url1"});
ignores.handle_action("ignore-article", {"*", "title # \"interesting\""});
ignores.handle_action("always-download", {"url1"});
ignores.handle_action("ignore-article", {"https://blog.example.com/joe/posts.xml", "guid # 123"});
ignores.handle_action("reset-unread-on-update", {"url2", "url3"});
ignores.handle_action("always-download", {"url2", "url3", "url4"});
std::vector<std::string> config;
const auto comment =
"# Comment to check that RssIgnores::dump_config() doesn't clear the vector";
config.push_back(comment);
ignores.dump_config(config);
REQUIRE(config.size() == 10);
REQUIRE(config[0] == comment);
REQUIRE(config[1] == R"#(ignore-article * "title # \"interesting\"")#");
REQUIRE(config[2] ==
R"#(ignore-article "https://blog.example.com/joe/posts.xml" "guid # 123")#");
REQUIRE(config[3] == R"#(always-download "url1")#");
REQUIRE(config[4] == R"#(always-download "url2")#");
REQUIRE(config[5] == R"#(always-download "url3")#");
REQUIRE(config[6] == R"#(always-download "url4")#");
REQUIRE(config[7] == R"#(reset-unread-on-update "url1")#");
REQUIRE(config[8] == R"#(reset-unread-on-update "url2")#");
REQUIRE(config[9] == R"#(reset-unread-on-update "url3")#");
}
}
TEST_CASE("RssIgnores::matches() returns true if given RssItem matches any "
"of ignore-article rules, otherwise false",
"[RssIgnores]")
{
RssIgnores ignores;
ConfigContainer cfg;
Cache rsscache(":memory:", &cfg);
RssItem item(&rsscache);
const auto feedurl = "https://example.com/feed.xml";
item.set_title("Updates");
item.set_author("John Doe");
item.set_feedurl(feedurl);
SECTION("Only rules associated with item's feed URL are applied") {
SECTION("No rules for this feed") {
ignores.handle_action("ignore-article", {"https://example.org/anotherfeed.xml", "title =~ \".*\""});
REQUIRE_FALSE(ignores.matches(&item));
}
SECTION("One rule for feed, but doesn't match item") {
ignores.handle_action("ignore-article", {feedurl, "title = \"news\""});
REQUIRE_FALSE(ignores.matches(&item));
}
SECTION("A rule matches both the feed and the item") {
ignores.handle_action("ignore-article", {feedurl, "title = \"Updates\""});
REQUIRE(ignores.matches(&item));
}
SECTION("Multiple rules that match both the feed and the item") {
ignores.handle_action("ignore-article", {feedurl, "title = \"Updates\""});
ignores.handle_action("ignore-article", {feedurl, "author = \"John Doe\""});
REQUIRE(ignores.matches(&item));
}
}
SECTION("Rules with URL of \"*\" match any feed") {
ignores.handle_action("ignore-article", {"*", "author = \"John Doe\""});
REQUIRE(ignores.matches(&item));
}
}
|