From 4fe0a037c82332e84b16a6f0e2847a2f9a0bd5d7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 18 Oct 2020 18:27:11 +0200 Subject: 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) --- tests/main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/main.cpp (limited to 'tests') 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 +#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 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; +} -- cgit v1.2.3