diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 0bcf6bbb..a61e45be 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -136,18 +136,6 @@ namespace Catch { static std::string convert(wchar_t * str); }; - template - struct is_string_array : std::false_type {}; - - template - struct is_string_array : std::true_type {}; - - template - struct is_string_array : std::true_type {}; - - template - struct is_string_array : std::true_type {}; - template struct StringMaker { static std::string convert(const char* str) { @@ -399,12 +387,20 @@ namespace Catch { } template - struct StringMaker::value && !is_string_array::value>::type> { + struct StringMaker::value && !std::is_array::value>::type> { static std::string convert( R const& range ) { return rangeToString( range ); } }; + template + struct StringMaker { + static std::string convert(T const(&arr)[SZ]) { + return rangeToString(arr); + } + }; + + } // namespace Catch // Separate std::chrono::duration specialization diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index f8c2ba21..68c9e5cf 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -598,6 +598,11 @@ Message from section one Message from section two Matchers.tests.cpp:: failed: testStringForMatching(), StartsWith("This String") for: "this string contains 'abc' as a substring" starts with: "This String" Matchers.tests.cpp:: failed: testStringForMatching(), StartsWith("string", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" starts with: "string" (case insensitive) +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify(singular) == "{ 1 }" for: "{ 1 }" == "{ 1 }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify(arr) == "{ 3, 2, 1 }" for: "{ 3, 2, 1 }" == "{ 3, 2, 1 }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify(arr) == R"({ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } })" for: "{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" +== +"{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" Matchers.tests.cpp:: passed: testStringForMatching(), Contains("string") for: "this string contains 'abc' as a substring" contains: "string" Matchers.tests.cpp:: passed: testStringForMatching(), Contains("string", Catch::CaseSensitive::No) for: "this string contains 'abc' as a substring" contains: "string" (case insensitive) Matchers.tests.cpp:: passed: testStringForMatching(), Contains("abc") for: "this string contains 'abc' as a substring" contains: "abc" diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 79387418..310a3d2e 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1064,6 +1064,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 196 | 145 passed | 47 failed | 4 failed as expected -assertions: 989 | 863 passed | 105 failed | 21 failed as expected +test cases: 197 | 146 passed | 47 failed | 4 failed as expected +assertions: 992 | 866 passed | 105 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 29be3496..11b89a33 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4749,6 +4749,47 @@ with expansion: "this string contains 'abc' as a substring" starts with: "string" (case insensitive) +------------------------------------------------------------------------------- +Static arrays are convertible to string + Single item +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify(singular) == "{ 1 }" ) +with expansion: + "{ 1 }" == "{ 1 }" + +------------------------------------------------------------------------------- +Static arrays are convertible to string + Multiple +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify(arr) == "{ 3, 2, 1 }" ) +with expansion: + "{ 3, 2, 1 }" == "{ 3, 2, 1 }" + +------------------------------------------------------------------------------- +Static arrays are convertible to string + Non-trivial inner items +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify(arr) == R"({ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } })" ) +with expansion: + "{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" + == + "{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" + ------------------------------------------------------------------------------- String matchers ------------------------------------------------------------------------------- @@ -8288,6 +8329,6 @@ Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 196 | 143 passed | 49 failed | 4 failed as expected -assertions: 988 | 859 passed | 108 failed | 21 failed as expected +test cases: 197 | 144 passed | 49 failed | 4 failed as expected +assertions: 991 | 862 passed | 108 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 136f8d38..79d8e6d9 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -538,6 +538,9 @@ Matchers.tests.cpp: Matchers.tests.cpp: + + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index e5759ee8..86557362 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -5477,6 +5477,44 @@ Message from section two + +
+ + + Catch::Detail::stringify(singular) == "{ 1 }" + + + "{ 1 }" == "{ 1 }" + + + +
+
+ + + Catch::Detail::stringify(arr) == "{ 3, 2, 1 }" + + + "{ 3, 2, 1 }" == "{ 3, 2, 1 }" + + + +
+
+ + + Catch::Detail::stringify(arr) == R"({ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } })" + + + "{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" +== +"{ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } }" + + + +
+ +
@@ -9219,7 +9257,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp index 3c5a3d94..8ab33249 100644 --- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp @@ -100,3 +100,18 @@ TEST_CASE( "std::set is convertible string", "[toString]" ) { REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" ); } } + +TEST_CASE("Static arrays are convertible to string", "[toString]") { + SECTION("Single item") { + int singular[1] = { 1 }; + REQUIRE(Catch::Detail::stringify(singular) == "{ 1 }"); + } + SECTION("Multiple") { + int arr[3] = { 3, 2, 1 }; + REQUIRE(Catch::Detail::stringify(arr) == "{ 3, 2, 1 }"); + } + SECTION("Non-trivial inner items") { + std::vector arr[2] = { {"1:1", "1:2", "1:3"}, {"2:1", "2:2"} }; + REQUIRE(Catch::Detail::stringify(arr) == R"({ { "1:1", "1:2", "1:3" }, { "2:1", "2:2" } })"); + } +}