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
|
#include <stdio.h>
#include "../include/NetUtils.hpp"
#define assert_fail(str) do { fprintf(stderr, "Assert failed on line %d, reason: %s\n", __LINE__, (str)); exit(1); } while(0)
#define assert_equals(a, b) do { if((a) != (b)) { fprintf(stderr, "Assert failed on line %d, %s == %s\n", __LINE__, #a, #b); exit(1); } } while(0)
int main() {
std::vector<std::string> urls;
urls.clear();
QuickMedia::extract_urls("example.com", urls);
assert_equals(urls.size(), 1);
assert_equals(urls[0], "example.com");
urls.clear();
QuickMedia::extract_urls("example.com, is where I like to go", urls);
assert_equals(urls.size(), 1);
assert_equals(urls[0], "example.com");
urls.clear();
QuickMedia::extract_urls("The website I like to go to is example.com", urls);
assert_equals(urls.size(), 1);
assert_equals(urls[0], "example.com");
urls.clear();
QuickMedia::extract_urls("example.com. Is also a website", urls);
assert_equals(urls.size(), 1);
assert_equals(urls[0], "example.com");
urls.clear();
QuickMedia::extract_urls("these. are. not. websites.", urls);
assert_equals(urls.size(), 0);
urls.clear();
QuickMedia::extract_urls("This is not an url: example.", urls);
assert_equals(urls.size(), 0);
urls.clear();
QuickMedia::extract_urls("the.se/~#423-_/2f.no/3df a.re considered sub.websit.es", urls);
assert_equals(urls.size(), 3);
assert_equals(urls[0], "the.se/~#423-_/2f.no/3df");
assert_equals(urls[1], "a.re");
assert_equals(urls[2], "sub.websit.es");
urls.clear();
QuickMedia::extract_urls("(see https://emojipedia.org/emoji/%23%EF%B8%8F%E2%83%A3/)", urls);
assert_equals(urls.size(), 1);
assert_equals(urls[0], "https://emojipedia.org/emoji/%23%EF%B8%8F%E2%83%A3/");
return 0;
}
|