ToStringOptional.tests.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031
  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_OPTIONAL_STRINGMAKER
  7. #include <catch2/catch_test_macros.hpp>
  8. #if defined(CATCH_CONFIG_CPP17_OPTIONAL)
  9. TEST_CASE( "std::optional<int> -> toString", "[toString][optional][approvals]" ) {
  10. using type = std::optional<int>;
  11. REQUIRE( "{ }" == ::Catch::Detail::stringify( type{} ) );
  12. REQUIRE( "0" == ::Catch::Detail::stringify( type{ 0 } ) );
  13. }
  14. TEST_CASE( "std::optional<std::string> -> toString", "[toString][optional][approvals]" ) {
  15. using type = std::optional<std::string>;
  16. REQUIRE( "{ }" == ::Catch::Detail::stringify( type{} ) );
  17. REQUIRE( "\"abc\"" == ::Catch::Detail::stringify( type{ "abc" } ) );
  18. }
  19. TEST_CASE( "std::vector<std::optional<int> > -> toString", "[toString][optional][approvals]" ) {
  20. using type = std::vector<std::optional<int> >;
  21. REQUIRE( "{ 0, { }, 2 }" == ::Catch::Detail::stringify( type{ 0, {}, 2 } ) );
  22. }
  23. #endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL