aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
blob: 38dd534e74f67c4b595f2b8db16d272ae7d25880 (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
#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 = QuickMedia::extract_urls("example.com");
    assert_equals(urls.size(), 1);
    assert_equals(urls[0], "example.com");

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

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

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

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

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

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