mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Add tests for toString(std::tuple<...>)
This commit is contained in:
parent
022a0b4fcb
commit
13cbdf7e7d
@ -6,6 +6,11 @@ project(Catch)
|
|||||||
get_filename_component(CATCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
|
get_filename_component(CATCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
|
||||||
get_filename_component(CATCH_DIR "${CATCH_DIR}" PATH)
|
get_filename_component(CATCH_DIR "${CATCH_DIR}" PATH)
|
||||||
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
||||||
|
if(USE_CPP11)
|
||||||
|
## We can't turn this on by default, since it breaks on travis
|
||||||
|
message(STATUS "Enabling C++11")
|
||||||
|
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# define the sources of the self test
|
# define the sources of the self test
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
@ -25,6 +30,7 @@ set(SOURCES
|
|||||||
${SELF_TEST_DIR}/ToStringPair.cpp
|
${SELF_TEST_DIR}/ToStringPair.cpp
|
||||||
${SELF_TEST_DIR}/ToStringVector.cpp
|
${SELF_TEST_DIR}/ToStringVector.cpp
|
||||||
${SELF_TEST_DIR}/ToStringWhich.cpp
|
${SELF_TEST_DIR}/ToStringWhich.cpp
|
||||||
|
${SELF_TEST_DIR}/ToStringTuple.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# configure the executable
|
# configure the executable
|
||||||
|
48
projects/SelfTest/ToStringTuple.cpp
Normal file
48
projects/SelfTest/ToStringTuple.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#ifdef CATCH_CPP11_OR_GREATER
|
||||||
|
|
||||||
|
TEST_CASE( "tuple<>", "[toString][tuple]" )
|
||||||
|
{
|
||||||
|
typedef std::tuple<> type;
|
||||||
|
CHECK( "{ }" == Catch::toString(type{}) );
|
||||||
|
type value {};
|
||||||
|
CHECK( "{ }" == Catch::toString(value) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "tuple<int>", "[toString][tuple]" )
|
||||||
|
{
|
||||||
|
typedef std::tuple<int> type;
|
||||||
|
CHECK( "{ 0 }" == Catch::toString(type{0}) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
|
||||||
|
{
|
||||||
|
typedef std::tuple<float,int> type;
|
||||||
|
CHECK( "1.2f" == Catch::toString(float(1.2)) );
|
||||||
|
CHECK( "{ 1.2f, 0 }" == Catch::toString(type{1.2,0}) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
|
||||||
|
{
|
||||||
|
typedef std::tuple<std::string,std::string> type;
|
||||||
|
CHECK( "{ \"hello\", \"world\" }" == Catch::toString(type{"hello","world"}) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
|
||||||
|
{
|
||||||
|
typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
|
||||||
|
type value { {42}, {}, 1.2f };
|
||||||
|
CHECK( "{ { 42 }, { }, 1.2f }" == Catch::toString(value) );
|
||||||
|
}
|
||||||
|
|
||||||
|
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::toString(value) );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* #ifdef CATCH_CPP11_OR_GREATER */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user