summaryrefslogtreecommitdiff
path: root/test/rssignores.cpp
diff options
context:
space:
mode:
authorGravatar Alexander Batischev <eual.jp@gmail.com> 2024-03-22 22:32:13 +0300
committerGravatar GitHub <noreply@github.com> 2024-03-22 22:32:13 +0300
commit1e4a28928f8e6ef6b6809d30232824b80c787e9b (patch)
tree1d0ac3681e6e84d978448329fb0fc189c49805c4 /test/rssignores.cpp
parent70c0aa54f32ad611bc636430117e12b962449c8c (diff)
parent24724915d44f5d2e72719b96bd7807cc17a43cc2 (diff)
downloadnewsboat-1e4a28928f8e6ef6b6809d30232824b80c787e9b.tar.gz
newsboat-1e4a28928f8e6ef6b6809d30232824b80c787e9b.tar.zst
newsboat-1e4a28928f8e6ef6b6809d30232824b80c787e9b.zip
Merge pull request #2706 from danieloh0714/optimize-rssignores-matches
optimize RssIgnores::matches function
Diffstat (limited to 'test/rssignores.cpp')
-rw-r--r--test/rssignores.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/test/rssignores.cpp b/test/rssignores.cpp
index f9d33583..a58f3c8e 100644
--- a/test/rssignores.cpp
+++ b/test/rssignores.cpp
@@ -1,5 +1,7 @@
#include "rssignores.h"
+#include <set>
+
#include "3rd-party/catch.hpp"
#include "cache.h"
@@ -135,6 +137,7 @@ TEST_CASE("RssIgnores::dump_config() writes out all configured settings "
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"});
+ ignores.handle_action(action, {"regex:^https://.*", "author = \"John Doe\""});
std::vector<std::string> config;
const auto comment =
@@ -143,13 +146,18 @@ TEST_CASE("RssIgnores::dump_config() writes out all configured settings "
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")#");
+ std::set<std::string> config_set(config.begin(), config.end());
+
+ REQUIRE(config.size() == 5); // four actions plus one comment
+ REQUIRE(config_set.count(comment) == 1);
+ REQUIRE(config_set.count(
+ R"#(ignore-article "https://example.com/feed.xml" "author =~ \"Joe\"")#") == 1);
+ REQUIRE(config_set.count(
+ R"#(ignore-article * "title # \"interesting\"")#") == 1);
+ REQUIRE(config_set.count(
+ R"#(ignore-article "https://blog.example.com/joe/posts.xml" "guid # 123")#") == 1);
+ REQUIRE(config_set.count(
+ R"#(ignore-article "regex:^https://.*" "author = \"John Doe\"")#") == 1);
}
SECTION("`always-download`") {
@@ -209,11 +217,14 @@ TEST_CASE("RssIgnores::dump_config() writes out all configured settings "
ignores.dump_config(config);
+ std::set<std::string> config_set(config.begin(), config.end());
+
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_set.count(
+ R"#(ignore-article * "title # \"interesting\"")#") == 1);
+ REQUIRE(config_set.count(
+ R"#(ignore-article "https://blog.example.com/joe/posts.xml" "guid # 123")#") == 1);
REQUIRE(config[3] == R"#(always-download "url1")#");
REQUIRE(config[4] == R"#(always-download "url2")#");
REQUIRE(config[5] == R"#(always-download "url3")#");