#include "catch.hpp" #include // vedctor TEST_CASE( "vector -> toString", "[toString][vector]" ) { std::vector vv; REQUIRE( Catch::toString(vv) == "{ }" ); vv.push_back( 42 ); REQUIRE( Catch::toString(vv) == "{ 42 }" ); vv.push_back( 250 ); REQUIRE( Catch::toString(vv) == "{ 42, 250 }" ); } TEST_CASE( "vector -> toString", "[toString][vector]" ) { std::vector vv; REQUIRE( Catch::toString(vv) == "{ }" ); vv.push_back( "hello" ); REQUIRE( Catch::toString(vv) == "{ \"hello\" }" ); vv.push_back( "world" ); REQUIRE( Catch::toString(vv) == "{ \"hello\", \"world\" }" ); } namespace { /* Minimal Allocator */ template struct minimal_allocator { typedef T value_type; typedef std::size_t size_type; T *allocate( size_type n ) { return static_cast( ::operator new( n * sizeof(T) ) ); } void deallocate( T *p, size_type /*n*/ ) { ::operator delete( static_cast(p) ); } template bool operator==( const minimal_allocator& ) const { return true; } template bool operator!=( const minimal_allocator& ) const { return false; } }; } TEST_CASE( "vector -> toString", "[toString][vector,allocator][c++11][.]" ) { std::vector > vv; REQUIRE( Catch::toString(vv) == "{ }" ); vv.push_back( 42 ); REQUIRE( Catch::toString(vv) == "{ 42 }" ); vv.push_back( 250 ); REQUIRE( Catch::toString(vv) == "{ 42, 250 }" ); } TEST_CASE( "vec> -> toString", "[toString][vector,allocator][c++11][.]" ) { typedef std::vector > inner; typedef std::vector vector; vector v; REQUIRE( Catch::toString(v) == "{ }" ); v.push_back( inner { "hello" } ); v.push_back( inner { "world" } ); REQUIRE( Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" ); }