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

refactored toLower

Commit
6ba2057abd69beb47f74625b3cc28fb77a32c9af
Author
Phil Nash ·
Parents
f4254b8622eb

Files · Download .tar.gz

Changes

 include/internal/catch_common.h           | 7 ++++++-
 include/internal/catch_tags.hpp           | 8 ++------
 include/internal/catch_test_case_info.hpp | 3 ++-
 include/internal/catch_test_spec.h        | 6 ++----
 projects/SelfTest/TestMain.cpp            | 1 +
 5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index e06796b8..630277f2 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -80,9 +80,14 @@ namespace Catch {
     inline bool contains( const std::string& s, const std::string& infix ) {
         return s.find( infix ) != std::string::npos;
     }
-    inline void toLower( std::string& s ) {
+    inline void toLowerInPlace( std::string& s ) {
         std::transform( s.begin(), s.end(), s.begin(), ::tolower );
     }
+    inline std::string toLower( std::string const& s ) {
+        std::string lc = s;
+        toLowerInPlace( lc );
+        return lc;
+    }
 
     struct pluralise {
         pluralise( std::size_t count, const std::string& label )
diff --git a/include/internal/catch_tags.hpp b/include/internal/catch_tags.hpp
index 15c3c3d8..74d6ee4e 100644
--- a/include/internal/catch_tags.hpp
+++ b/include/internal/catch_tags.hpp
@@ -70,9 +70,7 @@ namespace Catch {
 
     private:
         virtual void acceptTag( const std::string& tag ) {
-            std::string lcTag = tag;
-            toLower( lcTag );
-            m_tags.insert( lcTag );
+            m_tags.insert( toLower( tag ) );
         }
         virtual void acceptChar( char c ) {
             m_remainder += c;
@@ -115,9 +113,7 @@ namespace Catch {
         typedef std::map<std::string, Tag> TagMap;
     public:
         void add( const Tag& tag ) {
-            std::string tagName = tag.getName();
-            toLower( tagName );
-            m_tags.insert( std::make_pair( tagName, tag ) );
+            m_tags.insert( std::make_pair( toLower( tag.getName() ), tag ) );
         }
 
         bool empty() const {
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 6795047d..376a54fa 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -11,6 +11,7 @@
 #include "catch_tags.hpp"
 #include "catch_test_case_info.h"
 #include "catch_interfaces_testcase.h"
+#include "catch_common.h"
 
 namespace Catch {
 
@@ -76,7 +77,7 @@ namespace Catch {
     }
 
     bool TestCase::hasTag( const std::string& tag ) const {
-        return tags.find( tag ) != tags.end();
+        return tags.find( toLower( tag ) ) != tags.end();
     }
     bool TestCase::matchesTags( const std::string& tagPattern ) const {
         TagExpression exp;
diff --git a/include/internal/catch_test_spec.h b/include/internal/catch_test_spec.h
index fa60ce73..4250637b 100644
--- a/include/internal/catch_test_spec.h
+++ b/include/internal/catch_test_spec.h
@@ -33,12 +33,10 @@ namespace Catch {
         
     public:
         TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
-        :   m_stringToMatch( testSpec ),
+        :   m_stringToMatch( toLower( testSpec ) ),
             m_filterType( matchBehaviour ),
             m_wildcardPosition( NoWildcard )
         {
-            toLower( m_stringToMatch );
-
             if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
                 if( startsWith( m_stringToMatch, "exclude:" ) ) {
                     m_stringToMatch = m_stringToMatch.substr( 8 );
@@ -79,7 +77,7 @@ namespace Catch {
 
         bool isMatch( const TestCase& testCase ) const {
             std::string name = testCase.getTestCaseInfo().name;
-            toLower( name );
+            toLowerInPlace( name );
 
             switch( m_wildcardPosition ) {
                 case NoWildcard:
diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp
index 2b0a9bf7..e6c3830b 100644
--- a/projects/SelfTest/TestMain.cpp
+++ b/projects/SelfTest/TestMain.cpp
@@ -383,6 +383,7 @@ TEST_CASE( "selftest/tags", "" ) {
         CHECK( twoTags.getTestCaseInfo().description == "" );
         CHECK( twoTags.hasTag( "one" ) );
         CHECK( twoTags.hasTag( "two" ) );
+        CHECK( twoTags.hasTag( "Two" ) );
         CHECK( twoTags.hasTag( "three" ) == false );
         CHECK( twoTags.getTags().size() == 2 );