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