feat(string_util): Custom stringstream

This commit is contained in:
Michael Carlberg
2017-01-13 11:09:56 +01:00
parent 6fb48c8e6f
commit e1dbd98c40
7 changed files with 73 additions and 28 deletions

View File

@ -72,13 +72,6 @@ int main() {
expect(string_util::find_nth("foobarfoobar", 0, "o", 3) == size_t{7});
};
"from_stream"_test = [] {
auto result =
string_util::from_stream(std::stringstream() << std::setw(6) << std::setfill('z') << "foo"
<< "bar");
expect(result == "zzzfoobar");
};
"hash"_test = [] {
unsigned long hashA1{string_util::hash("foo")};
unsigned long hashA2{string_util::hash("foo")};
@ -106,4 +99,20 @@ int main() {
expect(string_util::filesize_gb(3 * 1024 * 1024 + 800 * 1024) == "4 GB");
expect(string_util::filesize(3 * 1024 * 1024) == "3 GB");
};
"stringstream"_test = [] {
string s;
expect((s = (stringstream() << "test")) == "test"s);
expect((s = (stringstream() << std::setprecision(2) << std::fixed << 1.25)).erase(0, 2) == "25"s);
};
"operators"_test = [] {
string foo = "foobar";
expect(foo - "bar" == "foo");
string baz = "bazbaz";
expect(baz - "ba" == "bazbaz");
expect(baz - "bazbz" == "bazbaz");
string aaa = "aaa";
expect(aaa - "aaaaa" == "aaa");
};
}