blob: 15be3f54bb8cd0087aea8956e1751f8912dc5e95 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include "rttt.hpp"
#include "rttt/config.hpp"
SCENARIO("We can parse a path correctly") {
auto p = rttt::parse_path("/hn/news");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::HN);
REQUIRE(p.name == "/hn/news");
p = rttt::parse_path("/hn/top");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::HN);
REQUIRE(p.basename == "/hn/top");
REQUIRE(p.name == "/hn/top");
p = rttt::parse_path("/hn/news/comments/x1");
REQUIRE(p.mode == rttt::list_mode::comment);
REQUIRE(p.type == rttt::SiteType::HN);
REQUIRE(p.basename == "/hn/news");
REQUIRE(p.name == "/hn/news/comments/x1");
REQUIRE(p.id == "x1");
p = rttt::parse_path("/r/news");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::Reddit);
REQUIRE(p.name == "/r/news");
p = rttt::parse_path("r/news");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::Reddit);
REQUIRE(p.name == "/r/news");
p = rttt::parse_path("/r/news/comments/x1");
REQUIRE(p.mode == rttt::list_mode::comment);
REQUIRE(p.type == rttt::SiteType::Reddit);
REQUIRE(p.name == "/r/news/comments/x1");
REQUIRE(p.basename == "/r/news");
REQUIRE(p.id == "x1");
p = rttt::parse_path("/rss/front");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::RSS);
REQUIRE(p.name == "/rss");
REQUIRE(p.basename == "/rss");
p = rttt::parse_path("/rss");
REQUIRE(p.mode == rttt::list_mode::story);
REQUIRE(p.type == rttt::SiteType::RSS);
REQUIRE(p.name == "/rss");
REQUIRE(p.basename == "/rss");
p = rttt::parse_path("/rss/x1");
REQUIRE(p.mode == rttt::list_mode::feed);
REQUIRE(p.type == rttt::SiteType::RSS);
REQUIRE(p.name == "/rss/x1");
REQUIRE(p.basename == "/rss");
REQUIRE(p.id == "x1");
}
SCENARIO("We can extract urls from text") {
std::vector<std::string> v;
REQUIRE(rttt::extractURL("") == v);
v = {"https://tiny1.com"};
std::string str = "Some text followed by an url https://tiny1.com. And another sentence";
REQUIRE(rttt::extractURL(str) == v);
REQUIRE(str == std::string("Some text followed by an url https://tiny1.com. And another sentence"));
v = {"https://tiny2.com", "http://second.com/bla-old"};
REQUIRE(rttt::extractURL("Some text followed by an url https://tiny2.com. And another http://second.com/bla-old sentence") == v);
std::string url = "https://news.ycombinator.com/item?id=29665129";
v = {url};
REQUIRE(rttt::extractURL(url) == v);
v = {"https://en.wikipedia.org/wiki/Lignum_vitae"};
REQUIRE(rttt::extractURL("https://en.wikipedia.org/wiki/Lignum_vitae),") == v);
str = "The text https://github.com/MarcoLucidi01/ytcast#ytcast";
v = {"https://github.com/MarcoLucidi01/ytcast#ytcast"};
REQUIRE(rttt::extractURL(str) == v);
str = "[https://tiny3.com](https://tiny3.com)";
v = {"https://tiny3.com", "https://tiny3.com"};
REQUIRE(rttt::extractURL(str) == v);
}
// Disabled by default, does not work on ci, where there is no file
// access
SCENARIO("We can find a config file", "[.]") {
auto config = rttt::config::load();
REQUIRE(config.contains("reddit"));
}
|