diff options
| author | Phil Nash | 2014-09-03 19:19:05 +0100 |
|---|---|---|
| committer | Phil Nash | 2014-09-03 19:19:05 +0100 |
| commit | ee5e7ed2c99d0f8a49efe4d491ccb4b7941431cf (patch) | |
| tree | 49b3e884cf4a579f01eb01c787020d9fde8559da /projects/SelfTest/ToStringWhich.cpp | |
| parent | dd22431fea6d92a9f518eb0227c1cf450fb1b22b (diff) | |
| parent | a9d14c8f7cca4b67576c5b4fa6f5179f3fe5a266 (diff) | |
| download | catch3-ee5e7ed2c99d0f8a49efe4d491ccb4b7941431cf.tar.gz | |
Merge branch 'develop' of github.com:philsquared/Catch into develop
# By Andy Sawyer
# Via Andy Sawyer (1) and Phil Nash (1)
* 'develop' of github.com:philsquared/Catch:
Updated CMakeLists.txt for toString work
A bunch of Catch::toString tests
Diffstat (limited to 'projects/SelfTest/ToStringWhich.cpp')
| -rw-r--r-- | projects/SelfTest/ToStringWhich.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/projects/SelfTest/ToStringWhich.cpp b/projects/SelfTest/ToStringWhich.cpp new file mode 100644 index 00000000..785c65b7 --- /dev/null +++ b/projects/SelfTest/ToStringWhich.cpp @@ -0,0 +1,74 @@ +#include "catch.hpp" +/* + Demonstrate which version of toString/StringMaker is being used + for various types +*/ + + +struct has_toString { }; +struct has_maker {}; +struct has_maker_and_toString {}; + +namespace Catch { + inline std::string toString( const has_toString& ) { + return "toString( has_toString )"; + } + inline std::string toString( const has_maker_and_toString& ) { + return "toString( has_maker_and_toString )"; + } + template<> + struct StringMaker<has_maker> { + static std::string convert( const has_maker& ) { + return "StringMaker<has_maker>"; + } + }; + template<> + struct StringMaker<has_maker_and_toString> { + static std::string convert( const has_maker_and_toString& ) { + return "StringMaker<has_maker_and_toString>"; + } + }; +} + +// Call the overload +TEST_CASE( "toString( has_toString )", "[toString]" ) +{ + has_toString item; + REQUIRE( Catch::toString( item ) == "toString( has_toString )" ); +} + +// Call the overload +TEST_CASE( "toString( has_maker )", "[toString]" ) +{ + has_maker item; + REQUIRE( Catch::toString( item ) == "StringMaker<has_maker>" ); +} + +// Call the overload +TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) +{ + has_maker_and_toString item; + REQUIRE( Catch::toString( item ) == "toString( has_maker_and_toString )" ); +} + +// Vectors... +TEST_CASE( "toString( vectors<has_toString )", "[toString]" ) +{ + std::vector<has_toString> v(1); + // This invokes template<T> toString which actually gives us '{ ? }' + REQUIRE( Catch::toString( v ) == "{ {?} }" ); +} + +TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) +{ + std::vector<has_maker> v(1); + REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker> }" ); +} + + +TEST_CASE( "toString( vectors<has_maker_and_toString )", "[toString]" ) +{ + std::vector<has_maker_and_toString> v(1); + // Note: This invokes the template<T> toString -> StringMaker + REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" ); +} |