mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
d0f817a60b
* Add basic benchmark * Add basic documentation for how to run and add tests/benchmarks * Update benchmark example output * Add changelog entry Co-authored-by: zneix <zneix@zneix.eu>
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
#include "providers/emoji/Emojis.hpp"
|
|
|
|
#include <benchmark/benchmark.h>
|
|
#include <QDebug>
|
|
#include <QString>
|
|
|
|
using namespace chatterino;
|
|
|
|
static void BM_ShortcodeParsing(benchmark::State &state)
|
|
{
|
|
Emojis emojis;
|
|
|
|
emojis.load();
|
|
|
|
struct TestCase {
|
|
QString input;
|
|
QString expectedOutput;
|
|
};
|
|
|
|
std::vector<TestCase> tests{
|
|
{
|
|
// input
|
|
"foo :penguin: bar",
|
|
// expected output
|
|
"foo 🐧 bar",
|
|
},
|
|
{
|
|
// input
|
|
"foo :nonexistantcode: bar",
|
|
// expected output
|
|
"foo :nonexistantcode: bar",
|
|
},
|
|
{
|
|
// input
|
|
":male-doctor:",
|
|
// expected output
|
|
"👨⚕️",
|
|
},
|
|
};
|
|
|
|
for (auto _ : state)
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_ShortcodeParsing);
|