mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Add op+(StringRef, StringRef) -> std::string
This commit is contained in:
		| @@ -39,6 +39,14 @@ namespace Catch { | ||||
|         return os.write(str.data(), str.size()); | ||||
|     } | ||||
|  | ||||
|     std::string operator+(StringRef lhs, StringRef rhs) { | ||||
|         std::string ret; | ||||
|         ret.reserve(lhs.size() + rhs.size()); | ||||
|         ret += lhs; | ||||
|         ret += rhs; | ||||
|         return ret; | ||||
|     } | ||||
|  | ||||
|     auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { | ||||
|         lhs.append(rhs.data(), rhs.size()); | ||||
|         return lhs; | ||||
|   | ||||
| @@ -101,6 +101,7 @@ namespace Catch { | ||||
|  | ||||
|         friend std::string& operator += (std::string& lhs, StringRef const& sr); | ||||
|         friend std::ostream& operator << (std::ostream& os, StringRef const& sr); | ||||
|         friend std::string operator+(StringRef lhs, StringRef rhs); | ||||
|     }; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1289,6 +1289,10 @@ String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringre | ||||
| String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11 | ||||
| String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringref" == "a stringref" | ||||
| String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11 | ||||
| String.tests.cpp:<line number>: passed: lhs == "some string += the stringref contents" for: "some string += the stringref contents" | ||||
| == | ||||
| "some string += the stringref contents" | ||||
| String.tests.cpp:<line number>: passed: together == "abrakadabra" for: "abrakadabra" == "abrakadabra" | ||||
| String.tests.cpp:<line number>: passed: with 1 message: 'empty.size() == 0' | ||||
| String.tests.cpp:<line number>: passed: with 1 message: 'empty.begin() == empty.end()' | ||||
| String.tests.cpp:<line number>: passed: with 1 message: 'stringref.size() == 3' | ||||
|   | ||||
| @@ -1381,5 +1381,5 @@ due to unexpected exception with message: | ||||
|  | ||||
| =============================================================================== | ||||
| test cases:  337 |  263 passed |  70 failed |  4 failed as expected | ||||
| assertions: 1924 | 1772 passed | 131 failed | 21 failed as expected | ||||
| assertions: 1926 | 1774 passed | 131 failed | 21 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -9449,6 +9449,32 @@ String.tests.cpp:<line number>: PASSED: | ||||
| with expansion: | ||||
|   11 == 11 | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| StringRef | ||||
|   std::string += StringRef | ||||
| ------------------------------------------------------------------------------- | ||||
| String.tests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| String.tests.cpp:<line number>: PASSED: | ||||
|   REQUIRE( lhs == "some string += the stringref contents" ) | ||||
| with expansion: | ||||
|   "some string += the stringref contents" | ||||
|   == | ||||
|   "some string += the stringref contents" | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| StringRef | ||||
|   StringRef + StringRef | ||||
| ------------------------------------------------------------------------------- | ||||
| String.tests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| String.tests.cpp:<line number>: PASSED: | ||||
|   REQUIRE( together == "abrakadabra" ) | ||||
| with expansion: | ||||
|   "abrakadabra" == "abrakadabra" | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| StringRef at compilation time | ||||
|   Simple constructors | ||||
| @@ -15033,5 +15059,5 @@ Misc.tests.cpp:<line number>: PASSED: | ||||
|  | ||||
| =============================================================================== | ||||
| test cases:  337 |  247 passed |  86 failed |  4 failed as expected | ||||
| assertions: 1941 | 1772 passed | 148 failed | 21 failed as expected | ||||
| assertions: 1943 | 1774 passed | 148 failed | 21 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <testsuitesloose text artifact | ||||
| > | ||||
|   <testsuite name="<exe-name>" errors="17" failures="132" tests="1942" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|   <testsuite name="<exe-name>" errors="17" failures="132" tests="1944" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|     <properties> | ||||
|       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> | ||||
|       <property name="random-seed" value="1"/> | ||||
| @@ -1145,6 +1145,8 @@ Matchers.tests.cpp:<line number> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef/from std::string/assigned" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef/to std::string/explicitly constructed" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef/to std::string/assigned" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef/std::string += StringRef" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef/StringRef + StringRef" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef at compilation time/Simple constructors" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="StringRef at compilation time/UDL construction" time="{duration}"/> | ||||
|     <testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/> | ||||
|   | ||||
| @@ -155,6 +155,8 @@ | ||||
|     <testCase name="StringRef/from std::string/assigned" duration="{duration}"/> | ||||
|     <testCase name="StringRef/to std::string/explicitly constructed" duration="{duration}"/> | ||||
|     <testCase name="StringRef/to std::string/assigned" duration="{duration}"/> | ||||
|     <testCase name="StringRef/std::string += StringRef" duration="{duration}"/> | ||||
|     <testCase name="StringRef/StringRef + StringRef" duration="{duration}"/> | ||||
|     <testCase name="StringRef at compilation time/Simple constructors" duration="{duration}"/> | ||||
|     <testCase name="StringRef at compilation time/UDL construction" duration="{duration}"/> | ||||
|   </file> | ||||
|   | ||||
| @@ -2491,6 +2491,10 @@ ok {test-number} - stdStr.size() == sr.size() for: 11 == 11 | ||||
| ok {test-number} - stdStr == "a stringref" for: "a stringref" == "a stringref" | ||||
| # StringRef | ||||
| ok {test-number} - stdStr.size() == sr.size() for: 11 == 11 | ||||
| # StringRef | ||||
| ok {test-number} - lhs == "some string += the stringref contents" for: "some string += the stringref contents" == "some string += the stringref contents" | ||||
| # StringRef | ||||
| ok {test-number} - together == "abrakadabra" for: "abrakadabra" == "abrakadabra" | ||||
| # StringRef at compilation time | ||||
| ok {test-number} - with 1 message: 'empty.size() == 0' | ||||
| # StringRef at compilation time | ||||
| @@ -3874,5 +3878,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 | ||||
| ok {test-number} - | ||||
| # xmlentitycheck | ||||
| ok {test-number} - | ||||
| 1..1933 | ||||
| 1..1935 | ||||
|  | ||||
|   | ||||
| @@ -11724,6 +11724,30 @@ Message from section two | ||||
|         </Section> | ||||
|         <OverallResults successes="2" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <Section name="std::string += StringRef" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" > | ||||
|         <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" > | ||||
|           <Original> | ||||
|             lhs == "some string += the stringref contents" | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             "some string += the stringref contents" | ||||
| == | ||||
| "some string += the stringref contents" | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <OverallResults successes="1" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <Section name="StringRef + StringRef" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" > | ||||
|         <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" > | ||||
|           <Original> | ||||
|             together == "abrakadabra" | ||||
|           </Original> | ||||
|           <Expanded> | ||||
|             "abrakadabra" == "abrakadabra" | ||||
|           </Expanded> | ||||
|         </Expression> | ||||
|         <OverallResults successes="1" failures="0" expectedFailures="0"/> | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="StringRef at compilation time" tags="[constexpr][StringRef][Strings]" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" > | ||||
| @@ -18031,7 +18055,7 @@ loose text artifact | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <OverallResults successes="1772" failures="149" expectedFailures="21"/> | ||||
|     <OverallResults successes="1774" failures="149" expectedFailures="21"/> | ||||
|   </Group> | ||||
|   <OverallResults successes="1772" failures="148" expectedFailures="21"/> | ||||
|   <OverallResults successes="1774" failures="148" expectedFailures="21"/> | ||||
| </Catch> | ||||
|   | ||||
| @@ -4,7 +4,6 @@ | ||||
| #include <cstring> | ||||
|  | ||||
| TEST_CASE( "StringRef", "[Strings][StringRef]" ) { | ||||
|  | ||||
|     using Catch::StringRef; | ||||
|  | ||||
|     SECTION( "Empty string" ) { | ||||
| @@ -123,6 +122,18 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { | ||||
|             REQUIRE( stdStr.size() == sr.size() ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     SECTION("std::string += StringRef") { | ||||
|         StringRef sr = "the stringref contents"; | ||||
|         std::string lhs("some string += "); | ||||
|         lhs += sr; | ||||
|         REQUIRE(lhs == "some string += the stringref contents"); | ||||
|     } | ||||
|     SECTION("StringRef + StringRef") { | ||||
|         StringRef sr1 = "abraka", sr2 = "dabra"; | ||||
|         std::string together = sr1 + sr2; | ||||
|         REQUIRE(together == "abrakadabra"); | ||||
|     } | ||||
| } | ||||
|  | ||||
| TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský