Files
EchoionStandalone/tests/test_message_chunker.cpp
faumaray 4a92d09e63 New arch
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-11 16:30:05 +03:00

42 lines
1.2 KiB
C++

#include "echoion/standalone/MessageChunker.hpp"
#include <iostream>
#include <string>
namespace
{
bool check(bool condition, const char* message)
{
if (!condition) {
std::cerr << "FAILED: " << message << '\n';
}
return condition;
}
}
int main()
{
using Echoion::Standalone::chunkMessage;
bool passed = true;
const std::string header = "# Help\n\n> [!TIP] Prefix is `!`\n\n";
const std::string details =
":::details ▶ Play — commands\n\n" + std::string(1100, 'x') +
"\n\n`!play` query\n> description\n:::\n\n";
const auto helpChunks = chunkMessage(header + details, 900);
passed &= check(helpChunks.size() == 2,
"help header and details block should be separate messages");
passed &= check(helpChunks.size() > 1 &&
helpChunks[1] == details.substr(0, details.size() - 1),
"details container must remain complete even above the limit");
const std::string utf8Line = std::string(899, 'a') + "я" + "tail";
const auto utf8Chunks = chunkMessage(utf8Line, 900);
passed &= check(utf8Chunks.size() == 2,
"long ordinary line should be split");
passed &= check(!utf8Chunks.empty() && utf8Chunks.front().size() == 899,
"UTF-8 sequence should not be split in the middle");
return passed ? 0 : 1;
}