2021-02-13 19:17:22 +01:00
|
|
|
#include "providers/emoji/Emojis.hpp"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
|
|
|
|
TEST(Emojis, ShortcodeParsing)
|
|
|
|
{
|
|
|
|
Emojis emojis;
|
|
|
|
|
|
|
|
emojis.load();
|
|
|
|
|
|
|
|
struct TestCase {
|
|
|
|
QString input;
|
|
|
|
QString expectedOutput;
|
|
|
|
};
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
const std::vector<TestCase> tests{
|
2021-02-13 19:17:22 +01:00
|
|
|
{
|
2021-02-14 12:59:29 +01:00
|
|
|
// input
|
|
|
|
"foo :penguin: bar",
|
|
|
|
// expected output
|
|
|
|
"foo 🐧 bar",
|
2021-02-13 19:17:22 +01:00
|
|
|
},
|
|
|
|
{
|
2021-02-14 12:59:29 +01:00
|
|
|
// input
|
|
|
|
"foo :nonexistantcode: bar",
|
|
|
|
// expected output
|
|
|
|
"foo :nonexistantcode: bar",
|
2021-02-13 19:17:22 +01:00
|
|
|
},
|
|
|
|
{
|
2021-02-14 12:59:29 +01:00
|
|
|
// input
|
|
|
|
":male-doctor:",
|
|
|
|
// expected output
|
|
|
|
"👨⚕️",
|
2021-02-13 19:17:22 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &test : tests)
|
|
|
|
{
|
|
|
|
auto output = emojis.replaceShortCodes(test.input);
|
|
|
|
|
|
|
|
auto matches = output == test.expectedOutput;
|
|
|
|
if (!matches && !output.endsWith(QChar(0xFE0F)))
|
|
|
|
{
|
|
|
|
// Try to append 0xFE0F if needed
|
|
|
|
output = output.append(QChar(0xFE0F));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(output, test.expectedOutput)
|
|
|
|
<< "Input " << test.input.toStdString() << " failed";
|
|
|
|
}
|
|
|
|
}
|