Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add op+(StringRef, StringRef) -> std::string

Commit
317145514fad8266edbce1145391524b4e948f32
Author
Martin Hořeňovský ·
Parents
f2b95080815c

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_stringref.cpp            |  8 +++++++
 src/catch2/internal/catch_stringref.hpp            |  1 +
 tests/SelfTest/Baselines/compact.sw.approved.txt   |  4 ++++
 tests/SelfTest/Baselines/console.std.approved.txt  |  2 +-
 tests/SelfTest/Baselines/console.sw.approved.txt   | 28 +++++++++++++++++++++-
 tests/SelfTest/Baselines/junit.sw.approved.txt     |  4 +++-
 tests/SelfTest/Baselines/sonarqube.sw.approved.txt |  2 ++
 tests/SelfTest/Baselines/tap.sw.approved.txt       |  6 ++++-
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 28 ++++++++++++++++++++--
 tests/SelfTest/IntrospectiveTests/String.tests.cpp | 13 +++++++++-
 10 files changed, 89 insertions(+), 7 deletions(-)

diff --git a/src/catch2/internal/catch_stringref.cpp b/src/catch2/internal/catch_stringref.cpp
index 4b0bbae6..df375eba 100644
--- a/src/catch2/internal/catch_stringref.cpp
+++ b/src/catch2/internal/catch_stringref.cpp
@@ -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;
diff --git a/src/catch2/internal/catch_stringref.hpp b/src/catch2/internal/catch_stringref.hpp
index 1e07b6ad..773d6d33 100644
--- a/src/catch2/internal/catch_stringref.hpp
+++ b/src/catch2/internal/catch_stringref.hpp
@@ -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);
     };
 
 
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index d7a756f4..977837ea 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -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'
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index ee6710d3..b20e5353 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -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
 
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 450d8025..bc46d209 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -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
 
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index 839cf6e6..a0bfb944 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -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}"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index 2809f95b..03be4906 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -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>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index d03b250e..e2f5e004 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -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
 
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 45d444c1..4d39e14d 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -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>
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
index 8c57e583..3832a2bf 100644
--- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -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]") {