ToStringPair.tests.cpp 1.5 KB

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