diff options
| author | Martin Hořeňovský | 2017-05-02 23:51:03 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-05-02 23:51:03 +0200 |
| commit | 33ed1773f40b406dbf3b7201bf52694bd86b1503 (patch) | |
| tree | 57aa3b7d82e3fcc2b8b99222515ec2d26b22a66a /projects/SelfTest/ToStringWhich.cpp | |
| parent | 40130e59b4b13f9e4c9962a8ffb19448c94b7c0f (diff) | |
| download | catch3-33ed1773f40b406dbf3b7201bf52694bd86b1503.tar.gz | |
Reworked stringification layer, removed Catch::toString
Now the order of stringification checks is
1) StringMaker specialization
2) operator<<
toString overloads and specializations have been removed.
Diffstat (limited to 'projects/SelfTest/ToStringWhich.cpp')
| -rw-r--r-- | projects/SelfTest/ToStringWhich.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/projects/SelfTest/ToStringWhich.cpp b/projects/SelfTest/ToStringWhich.cpp index a1d2a609..8bd1b6f9 100644 --- a/projects/SelfTest/ToStringWhich.cpp +++ b/projects/SelfTest/ToStringWhich.cpp @@ -5,67 +5,69 @@ */ -struct has_toString { }; +struct has_operator { }; struct has_maker {}; -struct has_maker_and_toString {}; +struct has_maker_and_operator {}; + +std::ostream& operator<<(std::ostream& os, const has_operator&) { + os << "operator<<( has_operator )"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const has_maker_and_operator&) { + os << "operator<<( has_maker_and_operator )"; + return os; +} 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& ) { + std::string operator()( 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>"; + struct StringMaker<has_maker_and_operator> { + std::string operator()( const has_maker_and_operator& ) { + return "StringMaker<has_maker_and_operator>"; } }; } -// Call the overload -TEST_CASE( "toString( has_toString )", "[toString]" ) { - has_toString item; - REQUIRE( Catch::toString( item ) == "toString( has_toString )" ); +// Call the operator +TEST_CASE( "stringify( has_operator )", "[toString]" ) { + has_operator item; + REQUIRE( ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" ); } -// Call the overload -TEST_CASE( "toString( has_maker )", "toString]" ) { +// Call the stringmaker +TEST_CASE( "stringify( has_maker )", "[toString]" ) { has_maker item; - REQUIRE( Catch::toString( item ) == "StringMaker<has_maker>" ); + REQUIRE( ::Catch::Detail::stringify( 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 )" ); +// Call the stringmaker +TEST_CASE( "stringify( has_maker_and_toString )", "[.][toString]" ) { + has_maker_and_operator item; + REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker_and_operator>" ); } // Vectors... // Don't run this in approval tests as it is sensitive to two phase lookup differences TEST_CASE( "toString( vectors<has_toString )", "[.][toString][!nonportable]" ) { - std::vector<has_toString> v(1); - // This invokes template<T> toString which actually gives us '{ ? }' - REQUIRE( Catch::toString( v ) == "{ {?} }" ); + std::vector<has_operator> v(1); + REQUIRE( ::Catch::Detail::stringify( v ) == "{ operator<<( has_operator ) }" ); } TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) { std::vector<has_maker> v(1); - REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker> }" ); + REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" ); } // Don't run this in approval tests as it is sensitive to two phase lookup differences TEST_CASE( "toString( vectors<has_maker_and_toString )", "[.][toString][!nonportable]" ) { - 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> }" ); + std::vector<has_maker_and_operator> v(1); + REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker_and_toString> }" ); } |