From 201bf5ad211de752d6a7ed417d6f3b9b44d36e8f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 16:46:20 -0500 Subject: [PATCH] Tests: Added ::leftJustify, ::rightJustify tests --- test/text.t.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/text.t.cpp b/test/text.t.cpp index 6653b894..715799ab 100644 --- a/test/text.t.cpp +++ b/test/text.t.cpp @@ -31,7 +31,7 @@ //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest t (62); + UnitTest t (76); // void wrapText (std::vector & lines, const std::string& text, const int width, bool hyphenate) std::string text = "This is a test of the line wrapping code."; @@ -99,7 +99,6 @@ int main (int, char**) t.is (line, "AAAAAAAAA-", "extractLine hyphenated unbreakable line"); t.diag (line); - // void split (std::vector& results, const std::string& input, const char delimiter) std::string unsplit = ""; std::vector items = split (unsplit, '-'); @@ -164,6 +163,28 @@ int main (int, char**) t.is (format (1.23456789, 8, 8), "1.2345679", "format (1.23456789, 8, 8) -> 1.2345679"); t.is (format (2444238.56789, 12, 11), "2444238.5679", "format (2444238.56789, 12, 11) -> 2444238.5679"); + // std::string leftJustify (const std::string&, const int); + t.is (leftJustify (123, 3), "123", "leftJustify 123,3 -> '123'"); + t.is (leftJustify (123, 4), "123 ", "leftJustify 123,4 -> '123 '"); + t.is (leftJustify (123, 5), "123 ", "leftJustify 123,5 -> '123 '"); + + // std::string leftJustify (const std::string&, const int); + t.is (leftJustify ("foo", 3), "foo", "leftJustify foo,3 -> 'foo'"); + t.is (leftJustify ("foo", 4), "foo ", "leftJustify foo,4 -> '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 '"); + + // std::string rightJustify (const std::string&, const int); + t.is (rightJustify (123, 3), "123", "rightJustify 123,3 -> '123'"); + t.is (rightJustify (123, 4), " 123", "rightJustify 123,4 -> ' 123'"); + t.is (rightJustify (123, 5), " 123", "rightJustify 123,5 -> ' 123'"); + + // std::string rightJustify (const std::string&, const int); + t.is (rightJustify ("foo", 3), "foo", "rightJustify foo,3 -> 'foo'"); + t.is (rightJustify ("foo", 4), " foo", "rightJustify foo,4 -> ' foo'"); + t.is (rightJustify ("foo", 5), " foo", "rightJustify foo,5 -> ' foo'"); + t.is (rightJustify ("föo", 5), " föo", "rightJustify föo,5 -> ' föo'"); + return 0; }