mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
@@ -19,102 +19,102 @@
|
||||
#include <znc/Utils.h>
|
||||
|
||||
TEST(IRC32, GetMessageTags) {
|
||||
EXPECT_EQ(MCString(), CUtils::GetMessageTags(""));
|
||||
EXPECT_EQ(MCString(), CUtils::GetMessageTags(
|
||||
":nick!ident@host PRIVMSG #chan :hello world"));
|
||||
EXPECT_EQ(MCString(), CUtils::GetMessageTags(""));
|
||||
EXPECT_EQ(MCString(), CUtils::GetMessageTags(
|
||||
":nick!ident@host PRIVMSG #chan :hello world"));
|
||||
|
||||
MCString 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();
|
||||
MCString 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"}, {"znc.in/gh-ij", "klmn,op"}};
|
||||
EXPECT_EQ(exp,
|
||||
CUtils::GetMessageTags("@ab=cdef;znc.in/gh-ij=klmn,op :rest"));
|
||||
exp = {{"ab", "cdef"}, {"znc.in/gh-ij", "klmn,op"}};
|
||||
EXPECT_EQ(exp,
|
||||
CUtils::GetMessageTags("@ab=cdef;znc.in/gh-ij=klmn,op :rest"));
|
||||
|
||||
exp = {{"a", "==b=="}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags("@a===b== :rest"));
|
||||
exp.clear();
|
||||
exp = {{"a", "==b=="}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags("@a===b== :rest"));
|
||||
exp.clear();
|
||||
|
||||
exp = {{"a", ""}, {"b", "c"}, {"d", ""}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags("@a;b=c;d :rest"));
|
||||
exp = {{"a", ""}, {"b", "c"}, {"d", ""}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags("@a;b=c;d :rest"));
|
||||
|
||||
exp = {{"semi-colon", ";"}, {"space", " "}, {"NUL", {'\0'}},
|
||||
{"backslash", "\\"}, {"CR", {'\r'}}, {"LF", {'\n'}}};
|
||||
EXPECT_EQ(
|
||||
exp,
|
||||
CUtils::GetMessageTags(
|
||||
R"(@semi-colon=\:;space=\s;NUL=\0;backslash=\\;CR=\r;LF=\n :rest)"));
|
||||
exp.clear();
|
||||
exp = {{"semi-colon", ";"}, {"space", " "}, {"NUL", {'\0'}},
|
||||
{"backslash", "\\"}, {"CR", {'\r'}}, {"LF", {'\n'}}};
|
||||
EXPECT_EQ(
|
||||
exp,
|
||||
CUtils::GetMessageTags(
|
||||
R"(@semi-colon=\:;space=\s;NUL=\0;backslash=\\;CR=\r;LF=\n :rest)"));
|
||||
exp.clear();
|
||||
|
||||
exp = {{"a", "; \\\r\n"}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags(R"(@a=\:\s\\\r\n :rest)"));
|
||||
exp.clear();
|
||||
exp = {{"a", "; \\\r\n"}};
|
||||
EXPECT_EQ(exp, CUtils::GetMessageTags(R"(@a=\:\s\\\r\n :rest)"));
|
||||
exp.clear();
|
||||
}
|
||||
|
||||
TEST(IRC32, SetMessageTags) {
|
||||
CString sLine;
|
||||
CString sLine;
|
||||
|
||||
sLine = ":rest";
|
||||
CUtils::SetMessageTags(sLine, MCString());
|
||||
EXPECT_EQ(":rest", sLine);
|
||||
sLine = ":rest";
|
||||
CUtils::SetMessageTags(sLine, MCString());
|
||||
EXPECT_EQ(":rest", sLine);
|
||||
|
||||
MCString tags = {{"a", "b"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b :rest", sLine);
|
||||
MCString tags = {{"a", "b"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b :rest", sLine);
|
||||
|
||||
tags = {{"a", "b"}, {"c", "d"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b;c=d :rest", sLine);
|
||||
tags = {{"a", "b"}, {"c", "d"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b;c=d :rest", sLine);
|
||||
|
||||
tags = {{"a", "b"}, {"c", "d"}, {"e", ""}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b;c=d;e :rest", sLine);
|
||||
tags = {{"a", "b"}, {"c", "d"}, {"e", ""}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ("@a=b;c=d;e :rest", sLine);
|
||||
|
||||
tags = {{"semi-colon", ";"}, {"space", " "}, {"NUL", {'\0'}},
|
||||
{"backslash", "\\"}, {"CR", {'\r'}}, {"LF", {'\n'}}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ(
|
||||
R"(@CR=\r;LF=\n;NUL=\0;backslash=\\;semi-colon=\:;space=\s :rest)",
|
||||
sLine);
|
||||
tags = {{"semi-colon", ";"}, {"space", " "}, {"NUL", {'\0'}},
|
||||
{"backslash", "\\"}, {"CR", {'\r'}}, {"LF", {'\n'}}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ(
|
||||
R"(@CR=\r;LF=\n;NUL=\0;backslash=\\;semi-colon=\:;space=\s :rest)",
|
||||
sLine);
|
||||
|
||||
tags = {{"a", "; \\\r\n"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ(R"(@a=\:\s\\\r\n :rest)", sLine);
|
||||
tags = {{"a", "; \\\r\n"}};
|
||||
CUtils::SetMessageTags(sLine, tags);
|
||||
EXPECT_EQ(R"(@a=\:\s\\\r\n :rest)", sLine);
|
||||
}
|
||||
|
||||
TEST(UtilsTest, ServerTime) {
|
||||
char* oldTZ = getenv("TZ");
|
||||
if (oldTZ) oldTZ = strdup(oldTZ);
|
||||
setenv("TZ", "UTC", 1);
|
||||
tzset();
|
||||
char* oldTZ = getenv("TZ");
|
||||
if (oldTZ) oldTZ = strdup(oldTZ);
|
||||
setenv("TZ", "UTC", 1);
|
||||
tzset();
|
||||
|
||||
timeval tv1 = CUtils::ParseServerTime("2011-10-19T16:40:51.620Z");
|
||||
CString str1 = CUtils::FormatServerTime(tv1);
|
||||
EXPECT_EQ("2011-10-19T16:40:51.620Z", str1);
|
||||
timeval tv1 = CUtils::ParseServerTime("2011-10-19T16:40:51.620Z");
|
||||
CString str1 = CUtils::FormatServerTime(tv1);
|
||||
EXPECT_EQ("2011-10-19T16:40:51.620Z", str1);
|
||||
|
||||
timeval now;
|
||||
if (!gettimeofday(&now, nullptr)) {
|
||||
now.tv_sec = time(nullptr);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
timeval now;
|
||||
if (!gettimeofday(&now, nullptr)) {
|
||||
now.tv_sec = time(nullptr);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
|
||||
CString str2 = CUtils::FormatServerTime(now);
|
||||
timeval tv2 = CUtils::ParseServerTime(str2);
|
||||
EXPECT_EQ(now.tv_sec, tv2.tv_sec);
|
||||
EXPECT_EQ(now.tv_usec, tv2.tv_usec);
|
||||
CString str2 = CUtils::FormatServerTime(now);
|
||||
timeval tv2 = CUtils::ParseServerTime(str2);
|
||||
EXPECT_EQ(now.tv_sec, tv2.tv_sec);
|
||||
EXPECT_EQ(now.tv_usec, tv2.tv_usec);
|
||||
|
||||
timeval tv3 = CUtils::ParseServerTime("invalid");
|
||||
CString str3 = CUtils::FormatServerTime(tv3);
|
||||
EXPECT_EQ("1970-01-01T00:00:00.000Z", str3);
|
||||
timeval tv3 = CUtils::ParseServerTime("invalid");
|
||||
CString str3 = CUtils::FormatServerTime(tv3);
|
||||
EXPECT_EQ("1970-01-01T00:00:00.000Z", str3);
|
||||
|
||||
if (oldTZ) {
|
||||
setenv("TZ", oldTZ, 1);
|
||||
free(oldTZ);
|
||||
} else {
|
||||
unsetenv("TZ");
|
||||
}
|
||||
tzset();
|
||||
if (oldTZ) {
|
||||
setenv("TZ", oldTZ, 1);
|
||||
free(oldTZ);
|
||||
} else {
|
||||
unsetenv("TZ");
|
||||
}
|
||||
tzset();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user