lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 502fedc 01/10: Improve [lr]trim unit test and


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 502fedc 01/10: Improve [lr]trim unit test and documentation
Date: Mon, 6 Feb 2017 04:10:55 +0000 (UTC)

branch: master
commit 502fedcb22fbceb4487bf68d7607310196df7074
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Improve [lr]trim unit test and documentation
    
    Added separate tests for ltrim() and rtrim(), and arguably redundant but
    cheap tests to show that applying them both to an already-trimmed string
    does nothing.
    
    The motivation was not so much to prove that these two functions work
    correctly as to provide simple examples for copying and pasting. The
    best documentation of a function is a "behold" comment on its unit test:
    unlike prose, it's demonstrably correct.
---
 miscellany_test.cpp |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 367545a..5516988 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -224,11 +224,15 @@ void test_trimming()
     BOOST_TEST_EQUAL(s, "a");
 
     s = "a; ;";
-    ltrim(s, superfluous); rtrim(s, superfluous);
+    rtrim(s, superfluous); // Shows what rtrim() does.
+    BOOST_TEST_EQUAL(s, "a");
+    ltrim(s, superfluous); rtrim(s, superfluous); // Does nothing, correctly.
     BOOST_TEST_EQUAL(s, "a");
 
     s = "; ;a";
-    ltrim(s, superfluous); rtrim(s, superfluous);
+    ltrim(s, superfluous); // Shows what ltrim() does.
+    BOOST_TEST_EQUAL(s, "a");
+    ltrim(s, superfluous); rtrim(s, superfluous); // Does nothing, correctly.
     BOOST_TEST_EQUAL(s, "a");
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]