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

Remove the ill-considered StringRef::numberOfCharacters

It never counted characters, only codepoints. If you think these
are interchangeable, you should not touch non-ascii text.
Commit
fe967b1f4122a67ae1b31febf26cf1751917a0eb
Author
Martin Hořeňovský ·
Parents
f2c2711bdcc5

Files · Download .tar.gz

Changes

 include/internal/catch_stringref.cpp               | 22 ---------------
 include/internal/catch_stringref.h                 |  1 -
 include/reporters/catch_reporter_console.cpp       |  3 +--
 .../SelfTest/Baselines/compact.sw.approved.txt     |  3 ---
 .../SelfTest/Baselines/console.std.approved.txt    |  2 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 24 +----------------
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 +--
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 31 ++--------------------
 .../SelfTest/IntrospectiveTests/String.tests.cpp   | 12 ---------
 9 files changed, 6 insertions(+), 95 deletions(-)

diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index 90a320c9..8e6741b1 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -17,12 +17,6 @@
 #include <cstring>
 #include <cstdint>
 
-namespace {
-    const uint32_t byte_2_lead = 0xC0;
-    const uint32_t byte_3_lead = 0xE0;
-    const uint32_t byte_4_lead = 0xF0;
-}
-
 namespace Catch {
     StringRef::StringRef( char const* rawChars ) noexcept
     : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
@@ -82,22 +76,6 @@ namespace Catch {
         return m_start[index];
     }
 
-    auto StringRef::numberOfCharacters() const noexcept -> size_type {
-        size_type noChars = m_size;
-        // Make adjustments for uft encodings
-        for( size_type i=0; i < m_size; ++i ) {
-            char c = m_start[i];
-            if( ( c & byte_2_lead ) == byte_2_lead ) {
-                noChars--;
-                if (( c & byte_3_lead ) == byte_3_lead )
-                    noChars--;
-                if( ( c & byte_4_lead ) == byte_4_lead )
-                    noChars--;
-            }
-        }
-        return noChars;
-    }
-
     auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string {
         std::string str;
         str.reserve( lhs.size() + rhs.size() );
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index 64f595b3..f7e4a360 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -96,7 +96,6 @@ namespace Catch {
             return m_size;
         }
 
-        auto numberOfCharacters() const noexcept -> size_type;
         auto c_str() const -> char const*;
 
     public: // substrings and searches
diff --git a/include/reporters/catch_reporter_console.cpp b/include/reporters/catch_reporter_console.cpp
index ff3953e4..12092907 100644
--- a/include/reporters/catch_reporter_console.cpp
+++ b/include/reporters/catch_reporter_console.cpp
@@ -321,8 +321,7 @@ public:
 
     friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) {
         auto colStr = tp.m_oss.str();
-        // This takes account of utf8 encodings
-        auto strSize = Catch::StringRef(colStr).numberOfCharacters();
+        const auto strSize = colStr.size();
         tp.m_oss.str("");
         tp.open();
         if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) {
diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index e6d28f39..20fade32 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -1045,9 +1045,6 @@ 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: ascii.numberOfCharacters() == ascii.size() for: 39 == 39
-String.tests.cpp:<line number>: passed: simpleu8.numberOfCharacters() == 30 for: 30 == 30
-String.tests.cpp:<line number>: passed: emojis.numberOfCharacters() == 9 for: 9 == 9
 ToStringChrono.tests.cpp:<line number>: passed: minute == seconds for: 1 m == 60 s
 ToStringChrono.tests.cpp:<line number>: passed: hour != seconds for: 1 h != 60 s
 ToStringChrono.tests.cpp:<line number>: passed: micro != milli for: 1 us != 1 ms
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index 756ea25e..59ea0426 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1381,5 +1381,5 @@ due to unexpected exception with message:
 
 ===============================================================================
 test cases:  300 |  226 passed |  70 failed |  4 failed as expected
-assertions: 1562 | 1410 passed | 131 failed | 21 failed as expected
+assertions: 1559 | 1407 passed | 131 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 8e5501f7..11eedbb4 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -7837,28 +7837,6 @@ String.tests.cpp:<line number>: PASSED:
 with expansion:
   11 == 11
 
--------------------------------------------------------------------------------
-StringRef
-  Counting utf-8 codepoints
--------------------------------------------------------------------------------
-String.tests.cpp:<line number>
-...............................................................................
-
-String.tests.cpp:<line number>: PASSED:
-  REQUIRE( ascii.numberOfCharacters() == ascii.size() )
-with expansion:
-  39 == 39
-
-String.tests.cpp:<line number>: PASSED:
-  REQUIRE( simpleu8.numberOfCharacters() == 30 )
-with expansion:
-  30 == 30
-
-String.tests.cpp:<line number>: PASSED:
-  REQUIRE( emojis.numberOfCharacters() == 9 )
-with expansion:
-  9 == 9
-
 -------------------------------------------------------------------------------
 Stringifying std::chrono::duration helpers
 -------------------------------------------------------------------------------
@@ -12484,5 +12462,5 @@ Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
 test cases:  300 |  210 passed |  86 failed |  4 failed as expected
-assertions: 1579 | 1410 passed | 148 failed | 21 failed as expected
+assertions: 1576 | 1407 passed | 148 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index d0e54846..11930e67 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/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="1580" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="132" tests="1577" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
       <property name="random-seed" value="1"/>
@@ -729,7 +729,6 @@ Matchers.tests.cpp:<line number>
     <testcase classname="<exe-name>.global" name="StringRef/to std::string/implicitly constructed" 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/Counting utf-8 codepoints" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration with weird ratios" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Stringifying std::chrono::time_point&lt;system_clock>" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index d848e615..03c11cde 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -9667,33 +9667,6 @@ Message from section two
         </Section>
         <OverallResults successes="2" failures="0" expectedFailures="0"/>
       </Section>
-      <Section name="Counting utf-8 codepoints" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
-          <Original>
-            ascii.numberOfCharacters() == ascii.size()
-          </Original>
-          <Expanded>
-            39 == 39
-          </Expanded>
-        </Expression>
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
-          <Original>
-            simpleu8.numberOfCharacters() == 30
-          </Original>
-          <Expanded>
-            30 == 30
-          </Expanded>
-        </Expression>
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" >
-          <Original>
-            emojis.numberOfCharacters() == 9
-          </Original>
-          <Expanded>
-            9 == 9
-          </Expanded>
-        </Expression>
-        <OverallResults successes="3" failures="0" expectedFailures="0"/>
-      </Section>
       <OverallResult success="true"/>
     </TestCase>
     <TestCase name="Stringifying std::chrono::duration helpers" tags="[chrono][toString]" filename="projects/<exe-name>/UsageTests/ToStringChrono.tests.cpp" >
@@ -14861,7 +14834,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1410" failures="149" expectedFailures="21"/>
+    <OverallResults successes="1407" failures="149" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="1410" failures="148" expectedFailures="21"/>
+  <OverallResults successes="1407" failures="148" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
index 876d4a09..aedd2f38 100644
--- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -159,18 +159,6 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
             REQUIRE( stdStr.size() == sr.size() );
         }
     }
-
-    SECTION( "Counting utf-8 codepoints" ) {
-        StringRef ascii = "just a plain old boring ascii string...";
-        REQUIRE(ascii.numberOfCharacters() == ascii.size());
-
-        StringRef simpleu8 = u8"Trocha češtiny nikoho nezabila";
-        REQUIRE(simpleu8.numberOfCharacters() == 30);
-
-        StringRef emojis = u8"Here be 👾";
-        REQUIRE(emojis.numberOfCharacters() == 9);
-    }
-
 }
 
 TEST_CASE( "replaceInPlace", "[Strings][StringManip]" ) {