Lexer: Migrated commify, ucFirst and lowerCase from text to Lexer

This commit is contained in:
Paul Beckingham 2015-10-30 10:57:14 -04:00
parent 7119c42780
commit 51def4b12b
15 changed files with 169 additions and 163 deletions

View file

@ -37,7 +37,7 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int, char**)
{
UnitTest t (1226);
UnitTest t (1253);
std::vector <std::pair <std::string, Lexer::Type>> tokens;
std::string token;
@ -551,6 +551,37 @@ int main (int, char**)
t.is (Lexer::typeName (Lexer::Type::date), "date", "Lexer::typeName (Lexer::Type::date)");
t.is (Lexer::typeName (Lexer::Type::duration), "duration", "Lexer::typeName (Lexer::Type::duration)");
// std::string Lexer::lowerCase (const std::string& input)
t.is (Lexer::lowerCase (""), "", "Lexer::lowerCase '' -> ''");
t.is (Lexer::lowerCase ("pre01_:POST"), "pre01_:post", "Lexer::lowerCase 'pre01_:POST' -> 'pre01_:post'");
// std::string Lexer::commify (const std::string& data)
t.is (Lexer::commify (""), "", "Lexer::commify '' -> ''");
t.is (Lexer::commify ("1"), "1", "Lexer::commify '1' -> '1'");
t.is (Lexer::commify ("12"), "12", "Lexer::commify '12' -> '12'");
t.is (Lexer::commify ("123"), "123", "Lexer::commify '123' -> '123'");
t.is (Lexer::commify ("1234"), "1,234", "Lexer::commify '1234' -> '1,234'");
t.is (Lexer::commify ("12345"), "12,345", "Lexer::commify '12345' -> '12,345'");
t.is (Lexer::commify ("123456"), "123,456", "Lexer::commify '123456' -> '123,456'");
t.is (Lexer::commify ("1234567"), "1,234,567", "Lexer::commify '1234567' -> '1,234,567'");
t.is (Lexer::commify ("12345678"), "12,345,678", "Lexer::commify '12345678' -> '12,345,678'");
t.is (Lexer::commify ("123456789"), "123,456,789", "Lexer::commify '123456789' -> '123,456,789'");
t.is (Lexer::commify ("1234567890"), "1,234,567,890", "Lexer::commify '1234567890' -> '1,234,567,890'");
t.is (Lexer::commify ("1.0"), "1.0", "Lexer::commify '1.0' -> '1.0'");
t.is (Lexer::commify ("12.0"), "12.0", "Lexer::commify '12.0' -> '12.0'");
t.is (Lexer::commify ("123.0"), "123.0", "Lexer::commify '123.0' -> '123.0'");
t.is (Lexer::commify ("1234.0"), "1,234.0", "Lexer::commify '1234.0' -> '1,234.0'");
t.is (Lexer::commify ("12345.0"), "12,345.0", "Lexer::commify '12345.0' -> '12,345.0'");
t.is (Lexer::commify ("123456.0"), "123,456.0", "Lexer::commify '123456.0' -> '123,456.0'");
t.is (Lexer::commify ("1234567.0"), "1,234,567.0", "Lexer::commify '1234567.0' -> '1,234,567.0'");
t.is (Lexer::commify ("12345678.0"), "12,345,678.0", "Lexer::commify '12345678.0' -> '12,345,678.0'");
t.is (Lexer::commify ("123456789.0"), "123,456,789.0", "Lexer::commify '123456789.0' -> '123,456,789.0'");
t.is (Lexer::commify ("1234567890.0"), "1,234,567,890.0", "Lexer::commify '1234567890.0' -> '1,234,567,890.0'");
t.is (Lexer::commify ("pre"), "pre", "Lexer::commify 'pre' -> 'pre'");
t.is (Lexer::commify ("pre1234"), "pre1,234", "Lexer::commify 'pre1234' -> 'pre1,234'");
t.is (Lexer::commify ("1234post"), "1,234post", "Lexer::commify '1234post' -> '1,234post'");
t.is (Lexer::commify ("pre1234post"), "pre1,234post", "Lexer::commify 'pre1234post' -> 'pre1,234post'");
return 0;
}

View file

@ -37,7 +37,7 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int, char**)
{
UnitTest t (225);
UnitTest t (198);
// Ensure environment has no influence.
unsetenv ("TASKDATA");
@ -258,37 +258,6 @@ int main (int, char**)
t.is (longestLine ("one\ntwo three four"), 14, "longestLine (one\\ntwo three four) --> 14");
t.is (longestLine ("one\ntwo\nthree\nfour"), 5, "longestLine (one\\ntwo\\nthree\\nfour) --> 5");
// std::string commify (const std::string& data)
t.is (commify (""), "", "commify '' -> ''");
t.is (commify ("1"), "1", "commify '1' -> '1'");
t.is (commify ("12"), "12", "commify '12' -> '12'");
t.is (commify ("123"), "123", "commify '123' -> '123'");
t.is (commify ("1234"), "1,234", "commify '1234' -> '1,234'");
t.is (commify ("12345"), "12,345", "commify '12345' -> '12,345'");
t.is (commify ("123456"), "123,456", "commify '123456' -> '123,456'");
t.is (commify ("1234567"), "1,234,567", "commify '1234567' -> '1,234,567'");
t.is (commify ("12345678"), "12,345,678", "commify '12345678' -> '12,345,678'");
t.is (commify ("123456789"), "123,456,789", "commify '123456789' -> '123,456,789'");
t.is (commify ("1234567890"), "1,234,567,890", "commify '1234567890' -> '1,234,567,890'");
t.is (commify ("1.0"), "1.0", "commify '1.0' -> '1.0'");
t.is (commify ("12.0"), "12.0", "commify '12.0' -> '12.0'");
t.is (commify ("123.0"), "123.0", "commify '123.0' -> '123.0'");
t.is (commify ("1234.0"), "1,234.0", "commify '1234.0' -> '1,234.0'");
t.is (commify ("12345.0"), "12,345.0", "commify '12345.0' -> '12,345.0'");
t.is (commify ("123456.0"), "123,456.0", "commify '123456.0' -> '123,456.0'");
t.is (commify ("1234567.0"), "1,234,567.0", "commify '1234567.0' -> '1,234,567.0'");
t.is (commify ("12345678.0"), "12,345,678.0", "commify '12345678.0' -> '12,345,678.0'");
t.is (commify ("123456789.0"), "123,456,789.0", "commify '123456789.0' -> '123,456,789.0'");
t.is (commify ("1234567890.0"), "1,234,567,890.0", "commify '1234567890.0' -> '1,234,567,890.0'");
t.is (commify ("pre"), "pre", "commify 'pre' -> 'pre'");
t.is (commify ("pre1234"), "pre1,234", "commify 'pre1234' -> 'pre1,234'");
t.is (commify ("1234post"), "1,234post", "commify '1234post' -> '1,234post'");
t.is (commify ("pre1234post"), "pre1,234post", "commify 'pre1234post' -> 'pre1,234post'");
// std::string lowerCase (const std::string& input)
t.is (lowerCase (""), "", "lowerCase '' -> ''");
t.is (lowerCase ("pre01_:POST"), "pre01_:post", "lowerCase 'pre01_:POST' -> 'pre01_:post'");
// bool nontrivial (const std::string&);
t.notok (nontrivial (""), "nontrivial '' -> false");
t.notok (nontrivial (" "), "nontrivial ' ' -> false");