Tests: Added extractLine tests

This commit is contained in:
Paul Beckingham 2016-02-23 21:11:22 -05:00
parent f1785c6da9
commit 7efbfe29e4

View file

@ -37,11 +37,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int, char**) int main (int, char**)
{ {
UnitTest t (177); UnitTest t (180);
// Ensure environment has no influence.
unsetenv ("TASKDATA");
unsetenv ("TASKRC");
// void wrapText (std::vector <std::string>& lines, const std::string& text, const int width, bool hyphenate) // void wrapText (std::vector <std::string>& lines, const std::string& text, const int width, bool hyphenate)
std::string text = "This is a test of the line wrapping code."; std::string text = "This is a test of the line wrapping code.";
@ -106,8 +102,18 @@ int main (int, char**)
text = "AAAAAAAAAABBBBBBBBBB"; text = "AAAAAAAAAABBBBBBBBBB";
offset = 0; offset = 0;
extractLine (line, text, 10, true, offset); extractLine (line, text, 10, true, offset);
t.is (line, "AAAAAAAAA-", "extractLine hyphenated unbreakable line"); t.is (line, "AAAAAAAAA-", "extractLine hyphenated unbreakable line 'AAAAAAAAAABBBBBBBBBB'/10 -> 'AAAAAAAAA-'");
t.diag (line);
extractLine (line, text, 10, true, offset);
t.is (line, "ABBBBBBBB-", "extractLine hyphenated unbreakable line 'AAAAAAAAAABBBBBBBBBB'/10 -> 'ABBBBBBBB-'");
extractLine (line, text, 10, true, offset);
t.is (line, "BB", "extractLine hyphenated unbreakable line 'AAAAAAAAAABBBBBBBBBB'/10 -> 'BB'");
text = "4444 333 ";
offset = 0;
while (extractLine (line, text, 9, true, offset))
std::cout << "# line '" << line << "' offset " << offset << "\n";
// void split (std::vector<std::string>& results, const std::string& input, const char delimiter) // void split (std::vector<std::string>& results, const std::string& input, const char delimiter)
std::vector <std::string> items; std::vector <std::string> items;
@ -347,6 +353,9 @@ int main (int, char**)
t.is (leftJustify ("foo", 5), "foo ", "leftJustify foo,5 -> 'foo '"); t.is (leftJustify ("foo", 5), "foo ", "leftJustify foo,5 -> 'foo '");
t.is (leftJustify ("föo", 5), "föo ", "leftJustify föo,5 -> 'föo '"); t.is (leftJustify ("föo", 5), "föo ", "leftJustify föo,5 -> 'föo '");
// When a string doesn't fit in the space necessary‥
t.is (leftJustify ("foo", 2), "fo", "leftJustify foo,2 -→ 'fo'");
// std::string rightJustify (const std::string&, const int); // std::string rightJustify (const std::string&, const int);
t.is (rightJustify (123, 3), "123", "rightJustify 123,3 -> '123'"); t.is (rightJustify (123, 3), "123", "rightJustify 123,3 -> '123'");
t.is (rightJustify (123, 4), " 123", "rightJustify 123,4 -> ' 123'"); t.is (rightJustify (123, 4), " 123", "rightJustify 123,4 -> ' 123'");