1 parent
cf48f2f350
commit
4a92d09e63
7 files changed
+571
-64
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#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;
|
||||
}
|
||||
Reference in new issue
Block a user