diff options
| author | Phil Nash | 2018-01-04 10:03:08 +0000 |
|---|---|---|
| committer | Phil Nash | 2018-01-04 10:03:08 +0000 |
| commit | e41e8e8384c415a875309180e9d310a8da9972c4 (patch) | |
| tree | ecc6e74d05011003f8749809bd2e9271d989f4bd /projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp | |
| parent | af3f2499bcc89d25f4f9eed4c747366f9ef49ec1 (diff) | |
| download | catch3-e41e8e8384c415a875309180e9d310a8da9972c4.tar.gz | |
Added tests for stringifying map and set
Diffstat (limited to 'projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp')
| -rw-r--r-- | projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp index 743882b1..3c5a3d94 100644 --- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp @@ -5,8 +5,11 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ +#define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER #include "catch.hpp" +#include <map> +#include <set> TEST_CASE( "Character pretty printing" ){ SECTION("Specifically escaped"){ @@ -51,3 +54,49 @@ TEST_CASE( "Capture and info messages" ) { REQUIRE(true); } } + +TEST_CASE( "std::map is convertible string", "[toString]" ) { + + SECTION( "empty" ) { + std::map<std::string, int> emptyMap; + + REQUIRE( Catch::Detail::stringify( emptyMap ) == "{ }" ); + } + + SECTION( "single item" ) { + std::map<std::string, int> map = { { "one", 1 } }; + + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" ); + } + + SECTION( "several items" ) { + std::map<std::string, int> map = { + { "abc", 1 }, + { "def", 2 }, + { "ghi", 3 } + }; + + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" ); + } +} + +TEST_CASE( "std::set is convertible string", "[toString]" ) { + + SECTION( "empty" ) { + std::set<std::string> emptySet; + + REQUIRE( Catch::Detail::stringify( emptySet ) == "{ }" ); + } + + SECTION( "single item" ) { + std::set<std::string> set = { "one" }; + + REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" ); + } + + SECTION( "several items" ) { + std::set<std::string> set = { "abc", "def", "ghi" }; + + REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" ); + } +} |