diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..38dd534 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,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; +} |