Skip to content

Commit

Permalink
Add more test cases for text formatting functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkbeyer committed Jun 25, 2017
1 parent 3fbf1bb commit 356bf84
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/TextFormatting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,99 @@ TEST_CASE("longHexWidthShorter", "[TextFormatting]")
auto HexStr = toString(0x123456L, 4, '0', std::ios::hex);
REQUIRE(HexStr == "123456");
}

TEST_CASE("toLower", "[TextFormatting]")
{
string s = "TestUpperLower";
s = toLower(s);
REQUIRE( string("testupperlower") == s);

s = toLower("test UPper");
REQUIRE(string("test upper") == s);

// Can't use german words here, locale isn't correct in this environment.
//s = toLower( u8"Überhaupt ß" );
//REQUIRE( string(u8"überhaupt ß") == s);
}

TEST_CASE("toString", "[TextFormatting]")
{
auto s = toString(5);
REQUIRE(string("5") == s);

s = toString(15, 0, ' ', std::ios::hex);
REQUIRE(string("f") == s);

s = toString(15, -1, ' ', std::ios::hex);
REQUIRE(string("f") == s);

s = toString(0x25, 3, ' ', std::ios::hex);
REQUIRE(string(" 25") == s);
s = toString(0xAF, 4, '0', std::ios::hex);
REQUIRE(string("00af") == s);
s = toString(1.25f);
REQUIRE(string("1.25") == s);
s = toString(3.425);
REQUIRE(string("3.425") == s);
std::uint8_t b = 33;
s = toString(b, -1, ' ', std::ios::hex);
REQUIRE(string("21") == s);
}

TEST_CASE("trimLeft", "[TextFormatting]")
{
string s = trim_left_inplace(" test ");
REQUIRE(string("test ") == s);
s = trim_left_inplace("\t test ");
REQUIRE(string("test ") == s);
s = trim_left_inplace("\t test foo");
REQUIRE(string("test foo") == s);
s = trim_left_inplace("\r \t test foo", "\t\r ");
REQUIRE(string("test foo") == s);
}
TEST_CASE("trimRight", "[TextFormatting]")
{
string s = trim_right_inplace(" test ");
REQUIRE(string(" test") == s);
s = trim_right_inplace("test\t ");
REQUIRE(string("test") == s);
s = trim_right_inplace("test foo");
REQUIRE(string("test foo") == s);
s = trim_right_inplace("test foo \t \r", "\t\r ");
REQUIRE(string("test foo") == s);
s = trim_right_inplace("test foo \r \t ", "\t\r ");
REQUIRE(string("test foo") == s);
}

TEST_CASE("trim", "[TextFormatting]")
{
string s = trim(" test ");
REQUIRE(string("test") == s);
s = trim("test\t ");
REQUIRE(string("test") == s);
s = trim(" test foo ");
REQUIRE(string("test foo") == s);
s = trim("\ttest foo \t \r", "\t\r ");
REQUIRE(string("test foo") == s);
s = trim(" \r test foo \r \t ", "\t\r ");
REQUIRE(string("test foo") == s);
}

TEST_CASE("ieq", "[TextFormatting]")
{
string s1 = "Foo";
string s2 = "Bar";
REQUIRE(ieq(s1, s2) == false);

s1 = "Foo";
s2 = "Foo";
REQUIRE(ieq(s1, s2) == true);

s1 = "Foo";
s2 = " Foo";
REQUIRE(ieq(s1, s2) == false);

s1 = "Foo";
s2 = "foo";
REQUIRE(ieq(s1, s2) == true);
}

0 comments on commit 356bf84

Please sign in to comment.