mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Added special handling for vector<bool> when stringifying
This commit is contained in:
parent
e41e8e8384
commit
702cfdaf6e
@ -233,7 +233,6 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct EnumStringMaker {
|
||||
static std::string convert(const T& t) {
|
||||
@ -355,10 +354,32 @@ namespace Catch {
|
||||
!std::is_same<decltype(end(std::declval<T>())), not_this_one>::value;
|
||||
};
|
||||
|
||||
template<typename Range>
|
||||
std::string rangeToString( Range const& range ) {
|
||||
return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
|
||||
}
|
||||
|
||||
// Handle vector<bool> specially
|
||||
template<typename Allocator>
|
||||
std::string rangeToString( std::vector<bool, Allocator> const& v ) {
|
||||
ReusableStringStream rss;
|
||||
rss << "{ ";
|
||||
bool first = true;
|
||||
for( bool b : v ) {
|
||||
if( first )
|
||||
first = false;
|
||||
else
|
||||
rss << ", ";
|
||||
rss << ::Catch::Detail::stringify( b );
|
||||
}
|
||||
rss << " }";
|
||||
return rss.str();
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
struct StringMaker<R, typename std::enable_if<is_range<R>::value>::type> {
|
||||
static std::string convert( R const& range ) {
|
||||
return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
|
||||
return rangeToString( range );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -66,3 +66,13 @@ TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator]"
|
||||
v.push_back( inner { "world" } );
|
||||
REQUIRE( ::Catch::Detail::stringify(v) == "{ { \"hello\" }, { \"world\" } }" );
|
||||
}
|
||||
|
||||
// Based on PR by mat-so: https://github.com/catchorg/Catch2/pull/606/files#diff-43562f40f8c6dcfe2c54557316e0f852
|
||||
TEST_CASE( "vector<bool> -> toString", "[toString][containers][vector]" ) {
|
||||
std::vector<bool> bools;
|
||||
REQUIRE( ::Catch::Detail::stringify(bools) == "{ }");
|
||||
bools.push_back(true);
|
||||
REQUIRE( ::Catch::Detail::stringify(bools) == "{ true }");
|
||||
bools.push_back(false);
|
||||
REQUIRE( ::Catch::Detail::stringify(bools) == "{ true, false }");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user