ToStringTuple.tests.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  2. #include "catch.hpp"
  3. #include <tuple>
  4. TEST_CASE( "tuple<>", "[toString][tuple]" )
  5. {
  6. typedef std::tuple<> type;
  7. CHECK( "{ }" == ::Catch::Detail::stringify(type{}) );
  8. type value {};
  9. CHECK( "{ }" == ::Catch::Detail::stringify(value) );
  10. }
  11. TEST_CASE( "tuple<int>", "[toString][tuple]" )
  12. {
  13. typedef std::tuple<int> type;
  14. CHECK( "{ 0 }" == ::Catch::Detail::stringify(type{0}) );
  15. }
  16. TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
  17. {
  18. typedef std::tuple<float,int> type;
  19. CHECK( "1.2f" == ::Catch::Detail::stringify(float(1.2)) );
  20. CHECK( "{ 1.2f, 0 }" == ::Catch::Detail::stringify(type{1.2f,0}) );
  21. }
  22. TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
  23. {
  24. typedef std::tuple<std::string,std::string> type;
  25. CHECK( "{ \"hello\", \"world\" }" == ::Catch::Detail::stringify(type{"hello","world"}) );
  26. }
  27. TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
  28. {
  29. typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
  30. type value { std::tuple<int>{42}, {}, 1.2f };
  31. CHECK( "{ { 42 }, { }, 1.2f }" == ::Catch::Detail::stringify(value) );
  32. }
  33. TEST_CASE( "tuple<nullptr,int,const char *>", "[toString][tuple]" )
  34. {
  35. typedef std::tuple<std::nullptr_t,int,const char *> type;
  36. type value { nullptr, 42, "Catch me" };
  37. CHECK( "{ nullptr, 42, \"Catch me\" }" == ::Catch::Detail::stringify(value) );
  38. }