From df2fe0bc4bf6240e47abf26ff88ffdfc9373f481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 16 Aug 2020 15:51:47 +0200 Subject: Fix the parsing of IRC messages, especially with trailing spaces --- .../end_to_end/scenarios/multiple_channels_join.py | 4 ++ tests/irc.cpp | 43 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/irc.cpp (limited to 'tests') diff --git a/tests/end_to_end/scenarios/multiple_channels_join.py b/tests/end_to_end/scenarios/multiple_channels_join.py index 839909f..281a902 100644 --- a/tests/end_to_end/scenarios/multiple_channels_join.py +++ b/tests/end_to_end/scenarios/multiple_channels_join.py @@ -14,5 +14,9 @@ scenario = ( expect_self_join_presence(jid='{jid_one}/{resource_one}', chan="#foo", nick="{nick_one}"), expect_self_join_presence(jid='{jid_one}/{resource_one}', chan="#bar", nick="{nick_one}"), expect_self_join_presence(jid='{jid_one}/{resource_one}', chan="#baz", nick="{nick_one}"), + + send_stanza("Le topic"), + expect_stanza("/message"), + ) diff --git a/tests/irc.cpp b/tests/irc.cpp new file mode 100644 index 0000000..0f30f15 --- /dev/null +++ b/tests/irc.cpp @@ -0,0 +1,43 @@ +#include "catch.hpp" + +#include + +TEST_CASE("Basic IRC message parsing") +{ + IrcMessage m(":prefix COMMAND un deux trois"); + CHECK(m.prefix == "prefix"); + CHECK(m.command == "COMMAND"); + CHECK(m.arguments.size() == 3); + CHECK(m.arguments[0] == "un"); + CHECK(m.arguments[1] == "deux"); + CHECK(m.arguments[2] == "trois"); +} + +TEST_CASE("Trailing space") +{ + IrcMessage m(":prefix COMMAND un deux trois "); + CHECK(m.prefix == "prefix"); + CHECK(m.arguments.size() == 3); + CHECK(m.arguments[0] == "un"); + CHECK(m.arguments[1] == "deux"); + CHECK(m.arguments[2] == "trois"); +} + +TEST_CASE("Message with :") +{ + IrcMessage m(":prefix COMMAND un :coucou les amis "); + CHECK(m.prefix == "prefix"); + CHECK(m.arguments.size() == 2); + CHECK(m.arguments[0] == "un"); + CHECK(m.arguments[1] == "coucou les amis "); +} + +TEST_CASE("Message with empty :") +{ + IrcMessage m("COMMAND un deux :"); + CHECK(m.prefix == ""); + CHECK(m.arguments.size() == 3); + CHECK(m.arguments[0] == "un"); + CHECK(m.arguments[1] == "deux"); + CHECK(m.arguments[2] == ""); +} -- cgit v1.2.3