diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-18 18:27:11 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-18 18:27:11 +0200 |
commit | 4fe0a037c82332e84b16a6f0e2847a2f9a0bd5d7 (patch) | |
tree | 1789706873ccc7095414f44b1a85fe64b6e62345 /tests | |
parent | f5dc7e2c85436877606af46a011c2fba112185a9 (diff) |
Matrix: add a proper URI parser instead of regex for opening links. Show related body item image when pressing enter (for showing replied to media)
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; +} |