diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 1f84ba09..3e506847 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 1765707b..b872265f 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1299,6 +1299,18 @@ PartTracker.tests.cpp:: passed: s1.isComplete() == false for: false PartTracker.tests.cpp:: passed: s1.isComplete() for: true PartTracker.tests.cpp:: passed: testCase.isComplete() == false for: false == false PartTracker.tests.cpp:: passed: testCase.isComplete() for: true +StringManip.tests.cpp:: passed: trim(std::string(no_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:: passed: trim(std::string(leading_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:: passed: trim(std::string(trailing_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:: passed: trim(std::string(whitespace_at_both_ends)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" Exception.tests.cpp:: failed: unexpected exception with message: '3.14' Approx.tests.cpp:: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 ) Approx.tests.cpp:: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 ) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 28fd8eb5..a52bb9a5 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 299 | 225 passed | 70 failed | 4 failed as expected -assertions: 1554 | 1402 passed | 131 failed | 21 failed as expected +test cases: 300 | 226 passed | 70 failed | 4 failed as expected +assertions: 1558 | 1406 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 9885193a..8b03e232 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -9779,6 +9779,40 @@ PartTracker.tests.cpp:: PASSED: with expansion: true +------------------------------------------------------------------------------- +Trim strings +------------------------------------------------------------------------------- +StringManip.tests.cpp: +............................................................................... + +StringManip.tests.cpp:: PASSED: + REQUIRE( trim(std::string(no_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:: PASSED: + REQUIRE( trim(std::string(leading_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:: PASSED: + REQUIRE( trim(std::string(trailing_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:: PASSED: + REQUIRE( trim(std::string(whitespace_at_both_ends)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + ------------------------------------------------------------------------------- Unexpected exceptions can be translated ------------------------------------------------------------------------------- @@ -12421,6 +12455,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 299 | 209 passed | 86 failed | 4 failed as expected -assertions: 1571 | 1402 passed | 148 failed | 21 failed as expected +test cases: 300 | 210 passed | 86 failed | 4 failed as expected +assertions: 1575 | 1406 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 5ad04f55..da7853d3 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -825,6 +825,7 @@ Exception.tests.cpp: + 3.14 diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 177fa01a..9032dd52 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -11813,6 +11813,49 @@ Message from section two + + + + trim(std::string(no_whitespace)) == no_whitespace + + + "There is no extra whitespace here" +== +"There is no extra whitespace here" + + + + + trim(std::string(leading_whitespace)) == no_whitespace + + + "There is no extra whitespace here" +== +"There is no extra whitespace here" + + + + + trim(std::string(trailing_whitespace)) == no_whitespace + + + "There is no extra whitespace here" +== +"There is no extra whitespace here" + + + + + trim(std::string(whitespace_at_both_ends)) == no_whitespace + + + "There is no extra whitespace here" +== +"There is no extra whitespace here" + + + + 3.14 @@ -14778,7 +14821,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp new file mode 100644 index 00000000..31b5c6ce --- /dev/null +++ b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp @@ -0,0 +1,18 @@ +#include "internal/catch_string_manip.h" + +#include "catch.hpp" + +static const char * const no_whitespace = "There is no extra whitespace here"; +static const char * const leading_whitespace = " \r \t\n There is no extra whitespace here"; +static const char * const trailing_whitespace = "There is no extra whitespace here \t \n \r "; +static const char * const whitespace_at_both_ends = " \r\n \t There is no extra whitespace here \t\t\t \n"; + +TEST_CASE("Trim strings", "[string-manip]") { + using Catch::trim; using Catch::StringRef; + static_assert(std::is_same::value, "Trimming std::string should return std::string"); + + REQUIRE(trim(std::string(no_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(leading_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(trailing_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(whitespace_at_both_ends)) == no_whitespace); +}