catch2/projects/SelfTest/ToStringTuple.cpp

48 lines
1.4 KiB
C++
Raw Normal View History

#define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
#include "catch.hpp"
2017-04-25 13:40:52 +02:00
#include <tuple>
2015-05-19 19:23:52 +02:00
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<>", "[toString][tuple]" )
{
typedef std::tuple<> type;
CHECK( "{ }" == ::Catch::Detail::stringify(type{}) );
type value {};
CHECK( "{ }" == ::Catch::Detail::stringify(value) );
}
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<int>", "[toString][tuple]" )
{
typedef std::tuple<int> type;
CHECK( "{ 0 }" == ::Catch::Detail::stringify(type{0}) );
}
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
{
typedef std::tuple<float,int> type;
CHECK( "1.2f" == ::Catch::Detail::stringify(float(1.2)) );
CHECK( "{ 1.2f, 0 }" == ::Catch::Detail::stringify(type{1.2f,0}) );
}
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
{
typedef std::tuple<std::string,std::string> type;
CHECK( "{ \"hello\", \"world\" }" == ::Catch::Detail::stringify(type{"hello","world"}) );
}
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
{
typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
type value { std::tuple<int>{42}, {}, 1.2f };
CHECK( "{ { 42 }, { }, 1.2f }" == ::Catch::Detail::stringify(value) );
}
2017-07-13 09:52:51 +02:00
TEST_CASE( "tuple<nullptr,int,const char *>", "[toString][tuple]" )
{
typedef std::tuple<std::nullptr_t,int,const char *> type;
type value { nullptr, 42, "Catch me" };
CHECK( "{ nullptr, 42, \"Catch me\" }" == ::Catch::Detail::stringify(value) );
}