Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/compiled/String.cpp

Issue 29712634: Noissue - add SplitString and TrimSpaces helpers (Closed) Base URL: github.com:adblockplus/adblockpluscore
Patch Set: Created March 1, 2018, 2:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« compiled/String.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/compiled/String.cpp
diff --git a/test/compiled/String.cpp b/test/compiled/String.cpp
index 0067f26b4536240044354d05db87170cc7b49a0e..c81363f1b0227091eb92c70d30ba23dbaf5d78d0 100644
--- a/test/compiled/String.cpp
+++ b/test/compiled/String.cpp
@@ -48,3 +48,66 @@ TEST(TestString, constructInvalidOwnedString)
EXPECT_FALSE(s4.is_invalid());
}
+TEST(TestStringTrimSpaces, zeroLengthString)
+{
+ EXPECT_EQ(u""_str, TrimSpaces(DependentString()));
+ EXPECT_EQ(u""_str, TrimSpaces(OwnedString()));
+ EXPECT_EQ(u""_str, TrimSpaces(u""_str));
+}
+
+TEST(TestStringTrimSpaces, spacesAreRemoved)
+{
+ for (uint16_t leftSpaces = 0; leftSpaces < 5; ++leftSpaces)
+ {
+ for (uint16_t rightSpaces = 0; rightSpaces < 5; ++rightSpaces)
+ {
+ for (uint16_t nonSpaces = 0; nonSpaces < 5; ++nonSpaces)
+ {
+ OwnedString str;
+ std::string leftSpacesStdString(leftSpaces, ' ');
+ str.append(leftSpacesStdString.c_str(), leftSpacesStdString.length());
+ std::string stdString(nonSpaces, 'a');
+ OwnedString trimmedString;
+ trimmedString.append(stdString.c_str(), stdString.length());
+ str.append(trimmedString);
+ std::string rightSpacesStdString(rightSpaces, ' ');
+ str.append(rightSpacesStdString.c_str(), rightSpacesStdString.length());
+ EXPECT_EQ(trimmedString, TrimSpaces(str));
+ }
+ }
+ }
+}
+
+TEST(TestStringSplitString, test)
+{
+ {
+ auto str = u"123:abc"_str;
+ auto split = SplitString(str, 3);
+ EXPECT_EQ(u"123"_str, split.first);
+ EXPECT_EQ(u"abc"_str, split.second);
+ }
+ {
+ auto str = u"123:abc"_str;
+ auto split = SplitString(str, 0);
+ EXPECT_EQ(u""_str, split.first);
+ EXPECT_EQ(u"23:abc"_str, split.second);
+ }
+ {
+ auto str = u"123:abc"_str;
+ auto split = SplitString(str, 6);
+ EXPECT_EQ(u"123:ab"_str, split.first);
+ EXPECT_EQ(u""_str, split.second);
+ }
+ {
+ auto str = u"123:abc"_str;
+ auto split = SplitString(str, 7);
+ EXPECT_EQ(u"123:abc"_str, split.first);
+ EXPECT_EQ(u""_str, split.second);
+ }
+ {
+ auto str = u"123:abc"_str;
+ auto split = SplitString(str, 10);
+ EXPECT_EQ(u"123:abc"_str, split.first);
+ EXPECT_EQ(u""_str, split.second);
+ }
+}
« compiled/String.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld