diff options
| author | Phil Nash | 2015-11-05 18:46:00 +0000 |
|---|---|---|
| committer | Phil Nash | 2015-11-05 18:46:00 +0000 |
| commit | 054e3c5b4319ee21b7160736d0bdde2df438ad5f (patch) | |
| tree | 1c8a103499355ec45b79cf3158b293bdb0616b1c /projects/SelfTest/MiscTests.cpp | |
| parent | f3e7722cc604793f6d07eee1afa912f3e095a6f7 (diff) | |
| download | catch3-054e3c5b4319ee21b7160736d0bdde2df438ad5f.tar.gz | |
Added &&, || and ! operator overloads for matchers
(syntactic sugar for AllOf, AnyOf and Not compositional matchers, respectively)
Diffstat (limited to 'projects/SelfTest/MiscTests.cpp')
| -rw-r--r-- | projects/SelfTest/MiscTests.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index 8bd271c4..c2a7784c 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -208,6 +208,11 @@ inline const char* testStringForMatching() { return "this string contains 'abc' as a substring"; } +inline const char* testStringForMatching2() +{ + return "some completely different text that contains one common word"; +} + using namespace Catch::Matchers; TEST_CASE("String matchers", "[matchers]" ) @@ -257,6 +262,42 @@ TEST_CASE("Equals", "[matchers]") CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); } +TEST_CASE("Matchers can be (AllOf) composed with the + operator", "[matchers][operators][operator+]") +{ + CHECK_THAT( testStringForMatching(), + Contains( "string" ) && + Contains( "abc" ) && + Contains( "substring" ) && + Contains( "contains" ) ); +} + +TEST_CASE("Matchers can be (AnyOf) composed with the | operator", "[matchers][operators][operator|]") +{ + CHECK_THAT( testStringForMatching(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ); + CHECK_THAT( testStringForMatching2(), Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ); +} + +TEST_CASE("Matchers can be composed with both + and |", "[matchers][operators][operator|][operator+]") +{ + CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) ); +} + +TEST_CASE("Matchers can be composed with both + and | - failing", "[matchers][operators][operator|][operator+][.failing]") +{ + CHECK_THAT( testStringForMatching(), ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ); +} + +TEST_CASE("Matchers can be negated (Not) with the ! operator", "[matchers][operators][not]") +{ + CHECK_THAT( testStringForMatching(), !Contains( "different" ) ); +} + +TEST_CASE("Matchers can be negated (Not) with the ! operator - failing", "[matchers][operators][not][.failing]") +{ + CHECK_THAT( testStringForMatching(), !Contains( "substring" ) ); +} + + inline unsigned int Factorial( unsigned int number ) { // return number <= 1 ? number : Factorial(number-1)*number; |