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

Small improvements for StringRef

* `operator[]` is constexpr
* `operator<<` and `operator+=` are hidden friends
Commit
895d0a06960d9f48190dde7c7aa4a56d614946fc
Author
Martin Hořeňovský ·
Parents
094d840efe51

Files · Download .tar.gz

Changes

 src/catch2/catch_stringref.hpp                     | 8 +++++---
 tests/SelfTest/Baselines/compact.sw.approved.txt   | 1 +
 tests/SelfTest/Baselines/console.std.approved.txt  | 2 +-
 tests/SelfTest/Baselines/console.sw.approved.txt   | 6 +++++-
 tests/SelfTest/Baselines/junit.sw.approved.txt     | 2 +-
 tests/SelfTest/Baselines/tap.sw.approved.txt       | 4 +++-
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 6 +++---
 tests/SelfTest/IntrospectiveTests/String.tests.cpp | 3 +--
 8 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/catch2/catch_stringref.hpp b/src/catch2/catch_stringref.hpp
index 8ed1e731..1e07b6ad 100644
--- a/src/catch2/catch_stringref.hpp
+++ b/src/catch2/catch_stringref.hpp
@@ -53,7 +53,7 @@ namespace Catch {
             return !(*this == other);
         }
 
-        auto operator[] ( size_type index ) const noexcept -> char {
+        constexpr auto operator[] ( size_type index ) const noexcept -> char {
             assert(index < m_size);
             return m_start[index];
         }
@@ -97,10 +97,12 @@ namespace Catch {
     public: // iterators
         constexpr const_iterator begin() const { return m_start; }
         constexpr const_iterator end() const { return m_start + m_size; }
+
+
+        friend std::string& operator += (std::string& lhs, StringRef const& sr);
+        friend std::ostream& operator << (std::ostream& os, StringRef const& sr);
     };
 
-    auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
-    auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
 
     constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
         return StringRef( rawChars, size );
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index dc97d4d6..4d2fcbe2 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1298,6 +1298,7 @@ String.tests.cpp:<line number>: passed: with 1 message: 'stringref.begin() == ab
 String.tests.cpp:<line number>: passed: with 1 message: 'stringref.begin() != stringref.end()'
 String.tests.cpp:<line number>: passed: with 1 message: 'stringref.substr(10, 0).empty()'
 String.tests.cpp:<line number>: passed: with 1 message: 'stringref.substr(2, 1).data() == abc + 2'
+String.tests.cpp:<line number>: passed: with 1 message: 'stringref[1] == 'b''
 String.tests.cpp:<line number>: passed: with 1 message: 'shortened.size() == 2'
 String.tests.cpp:<line number>: passed: with 1 message: 'shortened.data() == abc'
 String.tests.cpp:<line number>: passed: with 1 message: 'shortened.begin() != shortened.end()'
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index c5aca7e9..f92173e5 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:  334 |  260 passed |  70 failed |  4 failed as expected
-assertions: 1895 | 1743 passed | 131 failed | 21 failed as expected
+assertions: 1896 | 1744 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 efdfab53..4123232c 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -9492,6 +9492,10 @@ String.tests.cpp:<line number>: PASSED:
 with message:
   stringref.substr(2, 1).data() == abc + 2
 
+String.tests.cpp:<line number>: PASSED:
+with message:
+  stringref[1] == 'b'
+
 String.tests.cpp:<line number>: PASSED:
 with message:
   shortened.size() == 2
@@ -14789,5 +14793,5 @@ Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
 test cases:  334 |  244 passed |  86 failed |  4 failed as expected
-assertions: 1912 | 1743 passed | 148 failed | 21 failed as expected
+assertions: 1913 | 1744 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 4ae272ba..9c4dd7cb 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="1913" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="132" tests="1914" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
       <property name="random-seed" value="1"/>
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index d31e82ff..b28c70d4 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2510,6 +2510,8 @@ ok {test-number} - with 1 message: 'stringref.substr(10, 0).empty()'
 # StringRef at compilation time
 ok {test-number} - with 1 message: 'stringref.substr(2, 1).data() == abc + 2'
 # StringRef at compilation time
+ok {test-number} - with 1 message: 'stringref[1] == 'b''
+# StringRef at compilation time
 ok {test-number} - with 1 message: 'shortened.size() == 2'
 # StringRef at compilation time
 ok {test-number} - with 1 message: 'shortened.data() == abc'
@@ -3816,5 +3818,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..1904
+1..1905
 
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 340e1931..10d7f304 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -11728,7 +11728,7 @@ Message from section two
     </TestCase>
     <TestCase name="StringRef at compilation time" tags="[constexpr][StringRef][Strings]" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
       <Section name="Simple constructors" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
-        <OverallResults successes="14" failures="0" expectedFailures="0"/>
+        <OverallResults successes="15" failures="0" expectedFailures="0"/>
       </Section>
       <Section name="UDL construction" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
         <OverallResults successes="6" failures="0" expectedFailures="0"/>
@@ -17756,7 +17756,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1743" failures="149" expectedFailures="21"/>
+    <OverallResults successes="1744" failures="149" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="1743" failures="148" expectedFailures="21"/>
+  <OverallResults successes="1744" failures="148" expectedFailures="21"/>
 </Catch>
diff --git a/tests/SelfTest/IntrospectiveTests/String.tests.cpp b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
index ae1cc817..e616801c 100644
--- a/tests/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -126,8 +126,6 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
 }
 
 TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
-    //TODO:
-    //  * substr
     using Catch::StringRef;
     SECTION("Simple constructors") {
         constexpr StringRef empty{};
@@ -144,6 +142,7 @@ TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
         STATIC_REQUIRE(stringref.begin() != stringref.end());
         STATIC_REQUIRE(stringref.substr(10, 0).empty());
         STATIC_REQUIRE(stringref.substr(2, 1).data() == abc + 2);
+        STATIC_REQUIRE(stringref[1] == 'b');
 
 
         constexpr StringRef shortened(abc, 2);