Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/ToStringWhich.cpp
diff options
context:
space:
mode:
authorPhil Nash2015-03-27 17:54:45 +0000
committerPhil Nash2015-03-27 17:54:45 +0000
commitd9fbc620930136ef9250269d73aa1d1a5f76da31 (patch)
tree891b77187e1168778f11c7a4b7b1d64de548e714 /projects/SelfTest/ToStringWhich.cpp
parentb9ec8a10edd66009c2e79af9a7f789b6547180bc (diff)
parent0ae7578028fe30135015ace15a97009a547f2d46 (diff)
downloadcatch3-d9fbc620930136ef9250269d73aa1d1a5f76da31.tar.gz
Merged from develop
Diffstat (limited to 'projects/SelfTest/ToStringWhich.cpp')
-rw-r--r--projects/SelfTest/ToStringWhich.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/projects/SelfTest/ToStringWhich.cpp b/projects/SelfTest/ToStringWhich.cpp
new file mode 100644
index 00000000..1d4aa892
--- /dev/null
+++ b/projects/SelfTest/ToStringWhich.cpp
@@ -0,0 +1,68 @@
+#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> }" );
+}