aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
blob: ca09d4c7b9b052bb8b572df23ae5646f58fe031d (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
#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;
    const char *str;

    str = "example.com";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "example.com, is where I like to go";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "The website I like to go to is example.com";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "example.com. Is also a website";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "example.com: the best test website";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "is it example.com? or not?";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

    str = "these. are. not. websites.";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 0);

    str = "This is not an url: example.";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 0);

    str = "the.se/~#423-_/2f.no/3df a.re considered sub.websit.es, this.is.not";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    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");

    str = "(see https://emojipedia.org/emoji/%23%EF%B8%8F%E2%83%A3/)";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "https://emojipedia.org/emoji/%23%EF%B8%8F%E2%83%A3/");

    str = "[sneed](https://sneedville.com)";
    urls = QuickMedia::ranges_get_strings(str, QuickMedia::extract_urls(str));
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "https://sneedville.com");
    return 0;
}