aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp114
1 files changed, 2 insertions, 112 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index b18626c..1b9231c 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,5 +1,5 @@
-#include "../include/MessageComposer.hpp"
#include "../include/DynamicImage.hpp"
+#include <dchat/MessageComposer.hpp>
#include <stdio.h>
#include <vector>
#include <string.h>
@@ -26,7 +26,7 @@ static void applyRichText(Gtk::TextView *textView, const Glib::ustring &text)
buffer->set_text("");
Gtk::TextIter iter = buffer->get_iter_at_offset(0);
- dchat::compose(text, [textView, &text, &iter, &buffer](dchat::MessagePart messagePart)
+ dchat::compose(text.data(), text.bytes(), [textView, &text, &iter, &buffer](dchat::MessagePart messagePart)
{
switch(messagePart.type)
{
@@ -76,115 +76,5 @@ static int testVisual(int argc, char **argv)
int main(int argc, char **argv)
{
- std::vector<dchat::MessagePart> expect =
- {
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 0, 4 } },
- dchat::MessagePart { dchat::MessagePart::Type::EMOJI, dchat::Range{ 12, 16 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 17, 21 } }
- };
-
- std::vector<const char*> expectText =
- {
- "abc ",
- "cool",
- " def"
- };
-
- int index = 0;
- const char *str = "abc [emoji](cool) def";
-
- auto compareFunc = [&str, &index, &expect, &expectText](dchat::MessagePart messagePart)
- {
- REQUIRE(index < expect.size());
- REQUIRE_EQUAL((int)messagePart.type, (int)expect[index].type);
- REQUIRE_EQUAL(messagePart.textRange.start, expect[index].textRange.start);
- REQUIRE_EQUAL(messagePart.textRange.end, expect[index].textRange.end);
- int length = messagePart.textRange.end - messagePart.textRange.start;
- if(strncmp(str + messagePart.textRange.start, expectText[index], length) != 0)
- {
- fprintf(stderr, "Assert failed: |%.*s| == |%.*s|\n", length, str + messagePart.textRange.start, length, expectText[index]);
- exit(EXIT_FAILURE);
- }
- ++index;
- };
-
- dchat::compose(str, compareFunc);
-
- {
- expect =
- {
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 0, 4 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 4, 20 } }
- };
-
- expectText =
- {
- "abc ",
- "[emoji](cool def"
- };
-
- index = 0;
- str = "abc [emoji](cool def";
- dchat::compose(str, compareFunc);
- }
-
- {
- expect =
- {
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 0, 4 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 4, 11 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 11, 22 } }
- };
-
- expectText =
- {
- "abc ",
- "[emoji]",
- " (cool def)"
- };
-
- index = 0;
- str = "abc [emoji] (cool def)";
- dchat::compose(str, compareFunc);
- }
-
- {
- expect =
- {
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 0, 4 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 4, 20 } },
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 20, 24 } }
- };
-
- expectText =
- {
- "abc ",
- "[notemoji](cool)",
- " def"
- };
-
- index = 0;
- str = "abc [notemoji](cool) def";
- dchat::compose(str, compareFunc);
- }
-
- {
- expect =
- {
- dchat::MessagePart { dchat::MessagePart::Type::TEXT, dchat::Range{ 0, 12 } },
- dchat::MessagePart { dchat::MessagePart::Type::EMOJI, dchat::Range{ 20, 71 } }
- };
-
- expectText =
- {
- "Hello world ",
- "https://discordemoji.com/assets/emoji/PeepoHide.png"
- };
-
- index = 0;
- str = "Hello world [emoji](https://discordemoji.com/assets/emoji/PeepoHide.png)";
- dchat::compose(str, compareFunc);
- }
-
return testVisual(argc, argv);
}