mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Start adding tests for string manip functions
This commit is contained in:
parent
4038ee6bc6
commit
b77ab74b72
@ -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
|
||||
|
@ -1299,6 +1299,18 @@ PartTracker.tests.cpp:<line number>: passed: s1.isComplete() == false for: false
|
||||
PartTracker.tests.cpp:<line number>: passed: s1.isComplete() for: true
|
||||
PartTracker.tests.cpp:<line number>: passed: testCase.isComplete() == false for: false == false
|
||||
PartTracker.tests.cpp:<line number>: passed: testCase.isComplete() for: true
|
||||
StringManip.tests.cpp:<line number>: passed: trim(std::string(no_whitespace)) == no_whitespace for: "There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
StringManip.tests.cpp:<line number>: passed: trim(std::string(leading_whitespace)) == no_whitespace for: "There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
StringManip.tests.cpp:<line number>: passed: trim(std::string(trailing_whitespace)) == no_whitespace for: "There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
StringManip.tests.cpp:<line number>: 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:<line number>: failed: unexpected exception with message: '3.14'
|
||||
Approx.tests.cpp:<line number>: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 )
|
||||
Approx.tests.cpp:<line number>: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 )
|
||||
|
@ -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
|
||||
|
||||
|
@ -9779,6 +9779,40 @@ PartTracker.tests.cpp:<line number>: PASSED:
|
||||
with expansion:
|
||||
true
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Trim strings
|
||||
-------------------------------------------------------------------------------
|
||||
StringManip.tests.cpp:<line number>
|
||||
...............................................................................
|
||||
|
||||
StringManip.tests.cpp:<line number>: 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:<line number>: 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:<line number>: 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:<line number>: 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:<line number>
|
||||
Misc.tests.cpp:<line number>: 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
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1572" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="132" tests="1576" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
|
||||
<property name="random-seed" value="1"/>
|
||||
@ -825,6 +825,7 @@ Exception.tests.cpp:<line number>
|
||||
<testcase classname="<exe-name>.global" name="Tracker/successfully close one section, then find another/Re-enter - skips S1 and enters S2/Successfully close S2" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Tracker/successfully close one section, then find another/Re-enter - skips S1 and enters S2/fail S2" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Tracker/open a nested section" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Trim strings" time="{duration}"/>
|
||||
<testcase classname="<exe-name>.global" name="Unexpected exceptions can be translated" time="{duration}">
|
||||
<error type="TEST_CASE">
|
||||
3.14
|
||||
|
@ -11813,6 +11813,49 @@ Message from section two
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Trim strings" tags="[string-manip]" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" >
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" >
|
||||
<Original>
|
||||
trim(std::string(no_whitespace)) == no_whitespace
|
||||
</Original>
|
||||
<Expanded>
|
||||
"There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" >
|
||||
<Original>
|
||||
trim(std::string(leading_whitespace)) == no_whitespace
|
||||
</Original>
|
||||
<Expanded>
|
||||
"There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" >
|
||||
<Original>
|
||||
trim(std::string(trailing_whitespace)) == no_whitespace
|
||||
</Original>
|
||||
<Expanded>
|
||||
"There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" >
|
||||
<Original>
|
||||
trim(std::string(whitespace_at_both_ends)) == no_whitespace
|
||||
</Original>
|
||||
<Expanded>
|
||||
"There is no extra whitespace here"
|
||||
==
|
||||
"There is no extra whitespace here"
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<TestCase name="Unexpected exceptions can be translated" tags="[!throws][.][failing]" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
|
||||
<Exception filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" >
|
||||
3.14
|
||||
@ -14778,7 +14821,7 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="1402" failures="149" expectedFailures="21"/>
|
||||
<OverallResults successes="1406" failures="149" expectedFailures="21"/>
|
||||
</Group>
|
||||
<OverallResults successes="1402" failures="148" expectedFailures="21"/>
|
||||
<OverallResults successes="1406" failures="148" expectedFailures="21"/>
|
||||
</Catch>
|
||||
|
18
projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp
Normal file
18
projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp
Normal file
@ -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<std::string, decltype(trim(std::string{}))>::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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user