diff options
| author | Martin Jeřábek | 2023-08-30 13:16:30 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-08-30 16:21:02 +0200 |
| commit | 3a5cde55b7a27a6d94ce994a8362b2425211bd5e (patch) | |
| tree | 310470491e8dbd48a20e0cd3360b031c5599538b | |
| parent | 2a19ae16b87547f152f262e05a55c7b2b969807b (diff) | |
| download | catch3-3a5cde55b7a27a6d94ce994a8362b2425211bd5e.tar.gz | |
implement stringify for std::nullopt_t
| -rw-r--r-- | src/catch2/catch_tostring.hpp | 6 | ||||
| -rw-r--r-- | tests/SelfTest/UsageTests/ToStringOptional.tests.cpp | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp index 788d824c..f3fb0beb 100644 --- a/src/catch2/catch_tostring.hpp +++ b/src/catch2/catch_tostring.hpp @@ -398,6 +398,12 @@ namespace Catch { } } }; + template <> + struct StringMaker<std::nullopt_t> { + static std::string convert(const std::nullopt_t&) { + return "{ }"; + } + }; } #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER diff --git a/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp b/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp index 9fd9d6b4..3671771a 100644 --- a/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp +++ b/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp @@ -28,4 +28,8 @@ TEST_CASE( "std::vector<std::optional<int> > -> toString", "[toString][optional] REQUIRE( "{ 0, { }, 2 }" == ::Catch::Detail::stringify( type{ 0, {}, 2 } ) ); } +TEST_CASE( "std::nullopt -> toString", "[toString][optional][approvals]" ) { + REQUIRE( "{ }" == ::Catch::Detail::stringify( std::nullopt ) ); +} + #endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL |