ToStringTuple.tests.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. #define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  7. #include <catch2/catch_test_macros.hpp>
  8. #include <tuple>
  9. TEST_CASE( "tuple<>", "[toString][tuple]" )
  10. {
  11. typedef std::tuple<> type;
  12. CHECK( "{ }" == ::Catch::Detail::stringify(type{}) );
  13. type value {};
  14. CHECK( "{ }" == ::Catch::Detail::stringify(value) );
  15. }
  16. TEST_CASE( "tuple<int>", "[toString][tuple]" )
  17. {
  18. typedef std::tuple<int> type;
  19. CHECK( "{ 0 }" == ::Catch::Detail::stringify(type{0}) );
  20. }
  21. TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
  22. {
  23. typedef std::tuple<float,int> type;
  24. CHECK( "1.2f" == ::Catch::Detail::stringify(float(1.2)) );
  25. CHECK( "{ 1.2f, 0 }" == ::Catch::Detail::stringify(type{1.2f,0}) );
  26. }
  27. TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
  28. {
  29. typedef std::tuple<std::string,std::string> type;
  30. CHECK( "{ \"hello\", \"world\" }" == ::Catch::Detail::stringify(type{"hello","world"}) );
  31. }
  32. TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
  33. {
  34. typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
  35. type value { std::tuple<int>{42}, {}, 1.2f };
  36. CHECK( "{ { 42 }, { }, 1.2f }" == ::Catch::Detail::stringify(value) );
  37. }
  38. TEST_CASE( "tuple<nullptr,int,const char *>", "[approvals][toString][tuple]" ) {
  39. typedef std::tuple<std::nullptr_t,int,const char *> type;
  40. type value { nullptr, 42, "Catch me" };
  41. CHECK( "{ nullptr, 42, \"Catch me\" }" == ::Catch::Detail::stringify(value) );
  42. }