commit
38e86d4a07
23 files changed
+3219
No files matched your search
@@ -0,0 +1,55 @@
|
||||
#include "check.hpp"
|
||||
#include "echoion/protocol/Command.hpp"
|
||||
|
||||
using namespace Echoion::Protocol;
|
||||
|
||||
TEST_CASE(escape_roundtrip)
|
||||
{
|
||||
std::string raw = "hello world|pipe/slash\ttab\nnl\\back";
|
||||
auto esc = tsEscape(raw);
|
||||
// Spaces and specials must be escaped (no raw space/pipe left).
|
||||
CHECK(esc.find(' ') == std::string::npos);
|
||||
CHECK(esc.find('|') == std::string::npos);
|
||||
CHECK_EQ(tsUnescape(esc), raw);
|
||||
}
|
||||
|
||||
TEST_CASE(escape_known)
|
||||
{
|
||||
CHECK_EQ(tsEscape("a b"), std::string("a\\sb"));
|
||||
CHECK_EQ(tsEscape("a|b"), std::string("a\\pb"));
|
||||
CHECK_EQ(tsEscape("a/b"), std::string("a\\/b"));
|
||||
CHECK_EQ(tsUnescape("a\\sb"), std::string("a b"));
|
||||
}
|
||||
|
||||
TEST_CASE(build_command)
|
||||
{
|
||||
CommandParams p;
|
||||
p["client_nickname"] = "My Bot";
|
||||
p["cid"] = "5";
|
||||
auto cmd = buildCommand("clientmove", p);
|
||||
// Params are ordered by key (map): cid before client_nickname.
|
||||
CHECK_EQ(cmd, std::string("clientmove cid=5 client_nickname=My\\sBot"));
|
||||
}
|
||||
|
||||
TEST_CASE(parse_notify)
|
||||
{
|
||||
auto pc = parseCommand(
|
||||
"notifytextmessage targetmode=2 msg=hello\\sworld invokerid=7 "
|
||||
"invokername=Alice");
|
||||
CHECK_EQ(pc.name, std::string("notifytextmessage"));
|
||||
CHECK_EQ(pc.params["targetmode"], std::string("2"));
|
||||
CHECK_EQ(pc.params["msg"], std::string("hello world"));
|
||||
CHECK_EQ(pc.params["invokername"], std::string("Alice"));
|
||||
}
|
||||
|
||||
TEST_CASE(parse_pipe_groups)
|
||||
{
|
||||
auto pc = parseCommand("channellist cid=1 channel_name=Default|cid=2 "
|
||||
"channel_name=Talk");
|
||||
CHECK_EQ(pc.name, std::string("channellist"));
|
||||
CHECK_EQ(pc.groups.size(), size_t(2));
|
||||
CHECK_EQ(pc.groups[0]["cid"], std::string("1"));
|
||||
CHECK_EQ(pc.groups[0]["channel_name"], std::string("Default"));
|
||||
CHECK_EQ(pc.groups[1]["cid"], std::string("2"));
|
||||
CHECK_EQ(pc.groups[1]["channel_name"], std::string("Talk"));
|
||||
}
|
||||
Reference in new issue
Block a user