diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-06-22 20:38:13 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-06-24 21:02:03 +0200 |
commit | b1cf12700d6c928e0550d97a9c1da7b188f81dc1 (patch) | |
tree | a923ed6fd2b5634693f97a449446f35745d84d3c /tests/unit/plugins | |
parent | 8ea1ee06e5ac18a000788851f807cb4fad3e076c (diff) | |
download | weechat-b1cf12700d6c928e0550d97a9c1da7b188f81dc1.zip |
irc: add keys/values with tags in output of irc_message_parse_to_hashtable (issue #1654)
Key is "tag_xxx" (where "xxx" is the name of tag) and value is the unescaped
tag value.
Diffstat (limited to 'tests/unit/plugins')
-rw-r--r-- | tests/unit/plugins/irc/test-irc-message.cpp | 18 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-tag.cpp | 38 |
2 files changed, 38 insertions, 18 deletions
diff --git a/tests/unit/plugins/irc/test-irc-message.cpp b/tests/unit/plugins/irc/test-irc-message.cpp index d94d440c5..accd26186 100644 --- a/tests/unit/plugins/irc/test-irc-message.cpp +++ b/tests/unit/plugins/irc/test-irc-message.cpp @@ -521,12 +521,16 @@ TEST(IrcMessage, ParseToHashtable) hashtable = irc_message_parse_to_hashtable ( NULL, - "@time=2019-08-03T12:13:00.000Z :nick!user@host PRIVMSG #channel " - ":the message"); + "@time=2019-08-03T12:13:00.000Z;tag2=value\\sspace " + ":nick!user@host PRIVMSG #channel :the message"); CHECK(hashtable); - STRCMP_EQUAL("time=2019-08-03T12:13:00.000Z", + STRCMP_EQUAL("time=2019-08-03T12:13:00.000Z;tag2=value\\sspace", (const char *)hashtable_get (hashtable, "tags")); + STRCMP_EQUAL("2019-08-03T12:13:00.000Z", + (const char *)hashtable_get (hashtable, "tag_time")); + STRCMP_EQUAL("value space", + (const char *)hashtable_get (hashtable, "tag_tag2")); STRCMP_EQUAL(":nick!user@host PRIVMSG #channel :the message", (const char *)hashtable_get (hashtable, "message_without_tags")); STRCMP_EQUAL("nick", @@ -541,13 +545,13 @@ TEST(IrcMessage, ParseToHashtable) (const char *)hashtable_get (hashtable, "arguments")); STRCMP_EQUAL("the message", (const char *)hashtable_get (hashtable, "text")); - STRCMP_EQUAL("47", + STRCMP_EQUAL("65", (const char *)hashtable_get (hashtable, "pos_command")); - STRCMP_EQUAL("55", + STRCMP_EQUAL("73", (const char *)hashtable_get (hashtable, "pos_arguments")); - STRCMP_EQUAL("55", + STRCMP_EQUAL("73", (const char *)hashtable_get (hashtable, "pos_channel")); - STRCMP_EQUAL("65", + STRCMP_EQUAL("83", (const char *)hashtable_get (hashtable, "pos_text")); hashtable_free (hashtable); diff --git a/tests/unit/plugins/irc/test-irc-tag.cpp b/tests/unit/plugins/irc/test-irc-tag.cpp index 50796ac37..2d00473e7 100644 --- a/tests/unit/plugins/irc/test-irc-tag.cpp +++ b/tests/unit/plugins/irc/test-irc-tag.cpp @@ -27,6 +27,7 @@ extern "C" #include "src/core/wee-hashtable.h" #include "src/core/wee-hook.h" #include "src/plugins/irc/irc-tag.h" +#include "src/plugins/plugin.h" } #define WEE_CHECK_ESCAPE_VALUE(__result, __string) \ @@ -122,26 +123,41 @@ TEST(IrcTag, Parse) { struct t_hashtable *hashtable; - POINTERS_EQUAL(NULL, irc_tag_parse (NULL)); - POINTERS_EQUAL(NULL, irc_tag_parse ("")); + hashtable = hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); - hashtable = irc_tag_parse ("abc"); - CHECK(hashtable); + LONGS_EQUAL(0, irc_tag_parse (NULL, hashtable, NULL)); + LONGS_EQUAL(0, irc_tag_parse ("", hashtable, NULL)); + + hashtable_remove_all (hashtable); + LONGS_EQUAL(1, irc_tag_parse ("abc", hashtable, NULL)); LONGS_EQUAL(1, hashtable->items_count); POINTERS_EQUAL(NULL, (const char *)hashtable_get (hashtable, "abc")); - hashtable_free (hashtable); - hashtable = irc_tag_parse ("abc=def"); - CHECK(hashtable); + hashtable_remove_all (hashtable); + LONGS_EQUAL(1, irc_tag_parse ("abc=def", hashtable, NULL)); LONGS_EQUAL(1, hashtable->items_count); STRCMP_EQUAL("def", (const char *)hashtable_get (hashtable, "abc")); - hashtable_free (hashtable); - hashtable = irc_tag_parse ("aaa=bbb;ccc;example.com/ddd=eee"); - CHECK(hashtable); + hashtable_remove_all (hashtable); + LONGS_EQUAL(3, irc_tag_parse ("aaa=bbb;ccc;example.com/ddd=value\\sspace", + hashtable, NULL)); LONGS_EQUAL(3, hashtable->items_count); STRCMP_EQUAL("bbb", (const char *)hashtable_get (hashtable, "aaa")); POINTERS_EQUAL(NULL, (const char *)hashtable_get (hashtable, "ccc")); - STRCMP_EQUAL("eee", (const char *)hashtable_get (hashtable, "example.com/ddd")); + STRCMP_EQUAL("value space", + (const char *)hashtable_get (hashtable, "example.com/ddd")); + + hashtable_remove_all (hashtable); + LONGS_EQUAL(3, irc_tag_parse ("aaa=bbb;ccc;example.com/ddd=value\\sspace", + hashtable, "tag_")); + LONGS_EQUAL(3, hashtable->items_count); + STRCMP_EQUAL("bbb", (const char *)hashtable_get (hashtable, "tag_aaa")); + POINTERS_EQUAL(NULL, (const char *)hashtable_get (hashtable, "tag_ccc")); + STRCMP_EQUAL("value space", + (const char *)hashtable_get (hashtable, "tag_example.com/ddd")); + hashtable_free (hashtable); } |