From fa3535e95e79ffc9776cc0b43248a108b173b323 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 14 Aug 2017 08:50:44 +0100 Subject: [PATCH] Added << ostream overload to StringRef --- include/internal/catch_stringref.cpp | 2 +- include/internal/catch_stringref.h | 5 +- .../Baselines/console.sw.approved.txt | 61 ++++++---------- .../SelfTest/Baselines/junit.sw.approved.txt | 8 ++- .../SelfTest/Baselines/xml.sw.approved.txt | 70 ++++++------------- 5 files changed, 54 insertions(+), 92 deletions(-) diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 9a1eaf4c..7d117018 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -173,7 +173,7 @@ namespace Catch { return StringRef( lhs ) + rhs; } - std::ostream& operator << ( std::ostream& os, StringRef const& str ) { + auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { return os << str.c_str(); } diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h index cde0667a..1f8412de 100644 --- a/include/internal/catch_stringref.h +++ b/include/internal/catch_stringref.h @@ -9,6 +9,7 @@ #include #include +#include namespace Catch { @@ -76,7 +77,9 @@ namespace Catch { auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> String; auto operator + ( StringRef const& lhs, char const* rhs ) -> String; auto operator + ( char const* lhs, StringRef const& rhs ) -> String; - + + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + } // namespace Catch #endif // CATCH_STRINGREF_H_INCLUDED diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index f3d8d63d..3cc191a6 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4378,7 +4378,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s == "hello" ) with expansion: - {?} == "hello" + hello == "hello" StringBuilder.tests.cpp:: PASSED: @@ -4397,7 +4397,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s == "hello world" ) with expansion: - {?} == "hello world" + hello world == "hello world" ------------------------------------------------------------------------------- StringBuilder @@ -4410,7 +4410,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s == "hello world" ) with expansion: - {?} == "hello world" + hello world == "hello world" ------------------------------------------------------------------------------- StringBuilder @@ -4435,7 +4435,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s == "hello world" ) with expansion: - {?} == "hello world" + hello world == "hello world" ------------------------------------------------------------------------------- StringBuilder @@ -4449,7 +4449,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s2 == s ) with expansion: - {?} == {?} + hello == hello StringBuilder.tests.cpp:: PASSED: @@ -4469,7 +4469,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s2 == "hello" ) with expansion: - {?} == "hello" + hello == "hello" StringBuilder.tests.cpp:: PASSED: @@ -4489,7 +4489,7 @@ StringBuilder.tests.cpp:: PASSED: REQUIRE( s2 == "hello" ) with expansion: - {?} == "hello" + hello == "hello" StringBuilder.tests.cpp:: PASSED: @@ -4589,32 +4589,11 @@ StringRef.tests.cpp: StringRef.tests.cpp:: PASSED: REQUIRE( original == "original" ) -with expansion: - {?} == "original" -StringRef.tests.cpp:: -PASSED: +StringRef.tests.cpp:: FAILED: REQUIRE( isSubstring( original ) ) with expansion: - true - -StringRef.tests.cpp:: -PASSED: - REQUIRE( isOwned( original ) == false ) -with expansion: - false == false - -StringRef.tests.cpp:: -PASSED: - REQUIRE( isSubstring( original ) == false ) -with expansion: - false == false - -StringRef.tests.cpp:: -PASSED: - REQUIRE( isOwned( original ) ) -with expansion: - true + false ------------------------------------------------------------------------------- StringRef @@ -4646,7 +4625,7 @@ StringRef.tests.cpp:: PASSED: REQUIRE( ss == "hello" ) with expansion: - {?} == "hello" + hello == "hello" ------------------------------------------------------------------------------- StringRef @@ -4757,13 +4736,13 @@ StringRef.tests.cpp:: PASSED: REQUIRE( StringRef("hello") == StringRef("hello") ) with expansion: - {?} == {?} + hello == hello StringRef.tests.cpp:: PASSED: REQUIRE( StringRef("hello") != StringRef("cello") ) with expansion: - {?} != {?} + hello != cello ------------------------------------------------------------------------------- StringRef @@ -4777,13 +4756,13 @@ StringRef.tests.cpp:: PASSED: REQUIRE( copied == "hot potato" ) with expansion: - {?} == "hot potato" + hot potato == "hot potato" StringRef.tests.cpp:: PASSED: REQUIRE( str == "hot potato" ) with expansion: - {?} == "hot potato" + hot potato == "hot potato" StringRef.tests.cpp:: PASSED: @@ -4809,7 +4788,7 @@ StringRef.tests.cpp:: PASSED: REQUIRE( copied == "hot potato" ) with expansion: - {?} == "hot potato" + hot potato == "hot potato" StringRef.tests.cpp:: PASSED: @@ -4841,7 +4820,7 @@ StringRef.tests.cpp:: PASSED: REQUIRE( sr == "a standard string" ) with expansion: - {?} == "a standard string" + a standard string == "a standard string" StringRef.tests.cpp:: PASSED: @@ -4861,7 +4840,7 @@ StringRef.tests.cpp:: PASSED: REQUIRE( sr == "a standard string" ) with expansion: - {?} == "a standard string" + a standard string == "a standard string" StringRef.tests.cpp:: PASSED: @@ -4881,7 +4860,7 @@ StringRef.tests.cpp:: PASSED: REQUIRE( sr == "a standard string" ) with expansion: - {?} == "a standard string" + a standard string == "a standard string" StringRef.tests.cpp:: PASSED: @@ -7758,6 +7737,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 183 | 130 passed | 49 failed | 4 failed as expected -assertions: 913 | 791 passed | 101 failed | 21 failed as expected +test cases: 183 | 129 passed | 50 failed | 4 failed as expected +assertions: 910 | 787 passed | 102 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 390e7297..8cd10426 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -518,7 +518,11 @@ MatchersTests.cpp: - + + +StringRef.tests.cpp: + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 7ad54363..324fbf6b 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4999,7 +4999,7 @@ Message from section two s == "hello" - {?} == "hello" + hello == "hello" @@ -5018,7 +5018,7 @@ Message from section two s == "hello world" - {?} == "hello world" + hello world == "hello world" @@ -5029,7 +5029,7 @@ Message from section two s == "hello world" - {?} == "hello world" + hello world == "hello world" @@ -5056,7 +5056,7 @@ Message from section two s == "hello world" - {?} == "hello world" + hello world == "hello world" @@ -5068,7 +5068,7 @@ Message from section two s2 == s - {?} == {?} + hello == hello @@ -5090,7 +5090,7 @@ Message from section two s2 == "hello" - {?} == "hello" + hello == "hello" @@ -5112,7 +5112,7 @@ Message from section two s2 == "hello" - {?} == "hello" + hello == "hello" @@ -5225,42 +5225,18 @@ Message from section two original == "original" - {?} == "original" + original == "original" - + isSubstring( original ) - true + false - - - isOwned( original ) == false - - - false == false - - - - - isSubstring( original ) == false - - - false == false - - - - - isOwned( original ) - - - true - - - +
@@ -5293,7 +5269,7 @@ Message from section two ss == "hello" - {?} == "hello" + hello == "hello" @@ -5418,7 +5394,7 @@ Message from section two StringRef("hello") == StringRef("hello") - {?} == {?} + hello == hello @@ -5426,7 +5402,7 @@ Message from section two StringRef("hello") != StringRef("cello") - {?} != {?} + hello != cello @@ -5438,7 +5414,7 @@ Message from section two copied == "hot potato" - {?} == "hot potato" + hot potato == "hot potato" @@ -5446,7 +5422,7 @@ Message from section two str == "hot potato" - {?} == "hot potato" + hot potato == "hot potato" @@ -5476,7 +5452,7 @@ Message from section two copied == "hot potato" - {?} == "hot potato" + hot potato == "hot potato" @@ -5514,7 +5490,7 @@ Message from section two sr == "a standard string" - {?} == "a standard string" + a standard string == "a standard string" @@ -5536,7 +5512,7 @@ Message from section two sr == "a standard string" - {?} == "a standard string" + a standard string == "a standard string" @@ -5558,7 +5534,7 @@ Message from section two sr == "a standard string" - {?} == "a standard string" + a standard string == "a standard string" @@ -5639,7 +5615,7 @@ Message from section two
- +
@@ -8592,7 +8568,7 @@ loose text artifact - + - +