Lexer: Migrated trim(), trimLeft() and trimRight() from text to Lexer

This commit is contained in:
Paul Beckingham
2015-10-30 11:17:23 -04:00
parent 51def4b12b
commit 182b5427cd
13 changed files with 75 additions and 72 deletions

View File

@@ -37,7 +37,7 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int, char**)
{
UnitTest t (1253);
UnitTest t (1274);
std::vector <std::pair <std::string, Lexer::Type>> tokens;
std::string token;
@@ -582,6 +582,33 @@ int main (int, char**)
t.is (Lexer::commify ("1234post"), "1,234post", "Lexer::commify '1234post' -> '1,234post'");
t.is (Lexer::commify ("pre1234post"), "pre1,234post", "Lexer::commify 'pre1234post' -> 'pre1,234post'");
// std::string Lexer::trimLeft (const std::string& in, const std::string& t /*= " "*/)
t.is (Lexer::trimLeft (""), "", "Lexer::trimLeft '' -> ''");
t.is (Lexer::trimLeft (" "), "", "Lexer::trimLeft ' ' -> ''");
t.is (Lexer::trimLeft ("", " \t"), "", "Lexer::trimLeft '' -> ''");
t.is (Lexer::trimLeft ("xxx"), "xxx", "Lexer::trimLeft 'xxx' -> 'xxx'");
t.is (Lexer::trimLeft ("xxx", " \t"), "xxx", "Lexer::trimLeft 'xxx' -> 'xxx'");
t.is (Lexer::trimLeft (" \t xxx \t "), "\t xxx \t ", "Lexer::trimLeft ' \\t xxx \\t ' -> '\\t xxx \\t '");
t.is (Lexer::trimLeft (" \t xxx \t ", " \t"), "xxx \t ", "Lexer::trimLeft ' \\t xxx \\t ' -> 'xxx \\t '");
// std::string Lexer::trimRight (const std::string& in, const std::string& t /*= " "*/)
t.is (Lexer::trimRight (""), "", "Lexer::trimRight '' -> ''");
t.is (Lexer::trimRight (" "), "", "Lexer::trimRight ' ' -> ''");
t.is (Lexer::trimRight ("", " \t"), "", "Lexer::trimRight '' -> ''");
t.is (Lexer::trimRight ("xxx"), "xxx", "Lexer::trimRight 'xxx' -> 'xxx'");
t.is (Lexer::trimRight ("xxx", " \t"), "xxx", "Lexer::trimRight 'xxx' -> 'xxx'");
t.is (Lexer::trimRight (" \t xxx \t "), " \t xxx \t", "Lexer::trimRight ' \\t xxx \\t ' -> ' \\t xxx \\t'");
t.is (Lexer::trimRight (" \t xxx \t ", " \t"), " \t xxx", "Lexer::trimRight ' \\t xxx \\t ' -> ' \\t xxx'");
// std::string Lexer::trim (const std::string& in, const std::string& t /*= " "*/)
t.is (Lexer::trim (""), "", "Lexer::trim '' -> ''");
t.is (Lexer::trim (" "), "", "Lexer::trim ' ' -> ''");
t.is (Lexer::trim ("", " \t"), "", "Lexer::trim '' -> ''");
t.is (Lexer::trim ("xxx"), "xxx", "Lexer::trim 'xxx' -> 'xxx'");
t.is (Lexer::trim ("xxx", " \t"), "xxx", "Lexer::trim 'xxx' -> 'xxx'");
t.is (Lexer::trim (" \t xxx \t "), "\t xxx \t", "Lexer::trim ' \\t xxx \\t ' -> '\\t xxx \\t'");
t.is (Lexer::trim (" \t xxx \t ", " \t"), "xxx", "Lexer::trim ' \\t xxx \\t ' -> 'xxx'");
return 0;
}

View File

@@ -37,7 +37,7 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int, char**)
{
UnitTest t (198);
UnitTest t (177);
// Ensure environment has no influence.
unsetenv ("TASKDATA");
@@ -202,33 +202,6 @@ int main (int, char**)
t.is (joined.length (), (size_t) 5, "join 0 1 2 -> length 5");
t.is (joined, "0-1-2", "join 0 1 2 -> '0-1-2'");
// std::string trimLeft (const std::string& in, const std::string& t /*= " "*/)
t.is (trimLeft (""), "", "trimLeft '' -> ''");
t.is (trimLeft (" "), "", "trimLeft ' ' -> ''");
t.is (trimLeft ("", " \t"), "", "trimLeft '' -> ''");
t.is (trimLeft ("xxx"), "xxx", "trimLeft 'xxx' -> 'xxx'");
t.is (trimLeft ("xxx", " \t"), "xxx", "trimLeft 'xxx' -> 'xxx'");
t.is (trimLeft (" \t xxx \t "), "\t xxx \t ", "trimLeft ' \\t xxx \\t ' -> '\\t xxx \\t '");
t.is (trimLeft (" \t xxx \t ", " \t"), "xxx \t ", "trimLeft ' \\t xxx \\t ' -> 'xxx \\t '");
// std::string trimRight (const std::string& in, const std::string& t /*= " "*/)
t.is (trimRight (""), "", "trimRight '' -> ''");
t.is (trimRight (" "), "", "trimRight ' ' -> ''");
t.is (trimRight ("", " \t"), "", "trimRight '' -> ''");
t.is (trimRight ("xxx"), "xxx", "trimRight 'xxx' -> 'xxx'");
t.is (trimRight ("xxx", " \t"), "xxx", "trimRight 'xxx' -> 'xxx'");
t.is (trimRight (" \t xxx \t "), " \t xxx \t", "trimRight ' \\t xxx \\t ' -> ' \\t xxx \\t'");
t.is (trimRight (" \t xxx \t ", " \t"), " \t xxx", "trimRight ' \\t xxx \\t ' -> ' \\t xxx'");
// std::string trim (const std::string& in, const std::string& t /*= " "*/)
t.is (trim (""), "", "trim '' -> ''");
t.is (trim (" "), "", "trim ' ' -> ''");
t.is (trim ("", " \t"), "", "trim '' -> ''");
t.is (trim ("xxx"), "xxx", "trim 'xxx' -> 'xxx'");
t.is (trim ("xxx", " \t"), "xxx", "trim 'xxx' -> 'xxx'");
t.is (trim (" \t xxx \t "), "\t xxx \t", "trim ' \\t xxx \\t ' -> '\\t xxx \\t'");
t.is (trim (" \t xxx \t ", " \t"), "xxx", "trim ' \\t xxx \\t ' -> 'xxx'");
// std::string unquoteText (const std::string& text)
t.is (unquoteText (""), "", "unquoteText '' -> ''");
t.is (unquoteText ("x"), "x", "unquoteText 'x' -> 'x'");