| 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_PAIR_STRINGMAKER |
| 10 | #include <catch2/catch_test_macros.hpp> |
| 11 | |
| 12 | TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" ) { |
| 13 | std::pair<int,std::string> value( 34, "xyzzy" ); |
| 14 | REQUIRE( ::Catch::Detail::stringify( value ) == "{ 34, \"xyzzy\" }" ); |
| 15 | } |
| 16 | |
| 17 | TEST_CASE( "std::pair<int,const std::string> -> toString", "[toString][pair]" ) { |
| 18 | std::pair<int,const std::string> value( 34, "xyzzy" ); |
| 19 | REQUIRE( ::Catch::Detail::stringify(value) == "{ 34, \"xyzzy\" }" ); |
| 20 | } |
| 21 | |
| 22 | TEST_CASE( "std::vector<std::pair<std::string,int> > -> toString", "[toString][pair]" ) { |
| 23 | std::vector<std::pair<std::string,int> > pr; |
| 24 | pr.push_back( std::make_pair("green", 55 ) ); |
| 25 | REQUIRE( ::Catch::Detail::stringify( pr ) == "{ { \"green\", 55 } }" ); |
| 26 | } |
| 27 | |
| 28 | // This is pretty contrived - I figure if this works, anything will... |
| 29 | TEST_CASE( "pair<pair<int,const char *,pair<std::string,int> > -> toString", "[toString][pair]" ) { |
| 30 | typedef std::pair<int,const char *> left_t; |
| 31 | typedef std::pair<std::string,int> right_t; |
| 32 | |
| 33 | left_t left( 42, "Arthur" ); |
| 34 | right_t right( "Ford", 24 ); |
| 35 | |
| 36 | std::pair<left_t,right_t> pair( left, right ); |
| 37 | REQUIRE( ::Catch::Detail::stringify( pair ) == "{ { 42, \"Arthur\" }, { \"Ford\", 24 } }" ); |
| 38 | } |