#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 { static std::string convert( const has_maker& ) { return "StringMaker"; } }; template<> struct StringMaker { static std::string convert( const has_maker_and_toString& ) { return "StringMaker"; } }; } // 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" ); } // 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... // Don't run this in approval tests as it is sensitive to two phase lookup differences TEST_CASE( "toString( vectors v(1); // This invokes template toString which actually gives us '{ ? }' REQUIRE( Catch::toString( v ) == "{ {?} }" ); } TEST_CASE( "toString( vectors v(1); REQUIRE( Catch::toString( v ) == "{ StringMaker }" ); } // Don't run this in approval tests as it is sensitive to two phase lookup differences TEST_CASE( "toString( vectors v(1); // Note: This invokes the template toString -> StringMaker REQUIRE( Catch::toString( v ) == "{ StringMaker }" ); }