Skip to content
Browse files

Fix message tags parser and add test of it

  • Loading branch information...
1 parent 0696a6e commit 5237e89bc318355bdae02a3672ee89e31dc0ff9e @DarthGandalf DarthGandalf committed Mar 3, 2014
Showing with 60 additions and 2 deletions.
  1. +1 −1 Makefile.in
  2. +1 −1 src/Utils.cpp
  3. +58 −0 test/UtilsTest.cpp
View
2 Makefile.in
@@ -47,7 +47,7 @@ LIB_SRCS := $(addprefix src/,$(LIB_SRCS))
BIN_SRCS := src/main.cpp
LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS))
BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS))
-TESTS := StringTest ConfigTest
+TESTS := StringTest ConfigTest UtilsTest
TESTS := $(addprefix test/,$(addsuffix .o,$(TESTS)))
CLEAN := znc src/*.o test/*.o core core.* .version_extra .depend modules/.depend unittest
DISTCLEAN := Makefile config.log config.status znc-buildmod \
View
2 src/Utils.cpp
@@ -466,7 +466,7 @@ MCString CUtils::GetMessageTags(const CString& sLine) {
MCString mssTags;
for (VCString::const_iterator it = vsTags.begin(); it != vsTags.end(); ++it) {
- mssTags[it->Token(0, false, "=")] = it->Token(1, true, "=");
+ mssTags[it->Token(0, false, "=", true)] = it->Token(1, true, "=", true);
}
return mssTags;
}
View
58 test/UtilsTest.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2004-2014 ZNC, see the NOTICE file for details.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <znc/FileUtils.h>
+#include <znc/Utils.h>
+
+TEST(IRC32, GetMessageTags) {
+ EXPECT_EQ(MCString(), CUtils::GetMessageTags(""));
+ EXPECT_EQ(MCString(), CUtils::GetMessageTags(":nick!ident@host PRIVMSG #chan :hello world"));
+
+ MCString exp;
+ exp["a"] = "b";
+ EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b"));
+ EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b :nick!ident@host PRIVMSG #chan :hello world"));
+ EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b :rest"));
+ exp.clear();
+
+ exp["ab"] = "cdef";
+ exp["znc.in/gh-ij"] = "klmn,op";
+ EXPECT_EQ(exp, CUtils::GetMessageTags("@ab=cdef;znc.in/gh-ij=klmn,op :rest"));
+ exp.clear();
+
+ exp["a"] = "==b==";
+ EXPECT_EQ(exp, CUtils::GetMessageTags("@a===b== :rest"));
+ exp.clear();
+}
+
+TEST(IRC32, SetMessageTags) {
+ CString sLine;
+
+ sLine = ":rest";
+ CUtils::SetMessageTags(sLine, MCString());
+ EXPECT_EQ(":rest", sLine);
+
+ MCString tags;
+ tags["a"] = "b";
+ CUtils::SetMessageTags(sLine, tags);
+ EXPECT_EQ("@a=b :rest", sLine);
+
+ tags["c"] = "d";
+ CUtils::SetMessageTags(sLine, tags);
+ EXPECT_EQ("@a=b;c=d :rest", sLine);
+}
+

0 comments on commit 5237e89

Please sign in to comment.
Something went wrong with that request. Please try again.