2014-09-01 19:09:37 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
/*
|
|
|
|
Demonstrate which version of toString/StringMaker is being used
|
|
|
|
for various types
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-05-02 23:51:03 +02:00
|
|
|
struct has_operator { };
|
2014-09-01 19:09:37 +02:00
|
|
|
struct has_maker {};
|
2017-05-02 23:51:03 +02:00
|
|
|
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;
|
|
|
|
}
|
2014-09-01 19:09:37 +02:00
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
template<>
|
|
|
|
struct StringMaker<has_maker> {
|
2017-05-21 23:40:05 +02:00
|
|
|
static std::string convert( const has_maker& ) {
|
2014-09-01 19:09:37 +02:00
|
|
|
return "StringMaker<has_maker>";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<>
|
2017-05-02 23:51:03 +02:00
|
|
|
struct StringMaker<has_maker_and_operator> {
|
2017-05-21 23:40:05 +02:00
|
|
|
static std::string convert( const has_maker_and_operator& ) {
|
2017-05-02 23:51:03 +02:00
|
|
|
return "StringMaker<has_maker_and_operator>";
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-02 23:51:03 +02:00
|
|
|
// Call the operator
|
|
|
|
TEST_CASE( "stringify( has_operator )", "[toString]" ) {
|
|
|
|
has_operator item;
|
|
|
|
REQUIRE( ::Catch::Detail::stringify( item ) == "operator<<( has_operator )" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 23:51:03 +02:00
|
|
|
// Call the stringmaker
|
|
|
|
TEST_CASE( "stringify( has_maker )", "[toString]" ) {
|
2014-09-01 19:09:37 +02:00
|
|
|
has_maker item;
|
2017-05-02 23:51:03 +02:00
|
|
|
REQUIRE( ::Catch::Detail::stringify( item ) == "StringMaker<has_maker>" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 23:51:03 +02:00
|
|
|
// 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>" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Vectors...
|
2017-01-23 18:47:58 +01:00
|
|
|
|
|
|
|
// Don't run this in approval tests as it is sensitive to two phase lookup differences
|
|
|
|
TEST_CASE( "toString( vectors<has_toString )", "[.][toString][!nonportable]" ) {
|
2017-05-02 23:51:03 +02:00
|
|
|
std::vector<has_operator> v(1);
|
|
|
|
REQUIRE( ::Catch::Detail::stringify( v ) == "{ operator<<( has_operator ) }" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
|
2014-09-04 08:27:09 +02:00
|
|
|
TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) {
|
2014-09-01 19:09:37 +02:00
|
|
|
std::vector<has_maker> v(1);
|
2017-05-02 23:51:03 +02:00
|
|
|
REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker> }" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-23 18:47:58 +01:00
|
|
|
// 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]" ) {
|
2017-05-02 23:51:03 +02:00
|
|
|
std::vector<has_maker_and_operator> v(1);
|
|
|
|
REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker_and_toString> }" );
|
2014-09-01 19:09:37 +02:00
|
|
|
}
|