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

Removed IEnumInfo (just use EnumInfo directly)

Commit
5a74fcc9c9c4f19c410f38070cefb11576df7386
Author
Phil Nash ·
Parents
9d5d71986831

Files · Download .tar.gz

Changes

 include/internal/catch_enum_values_registry.cpp    | 28 +++++++---------------
 include/internal/catch_enum_values_registry.h      |  4 ++--
 .../catch_interfaces_enum_values_registry.h        | 17 ++++++++-----
 .../SelfTest/UsageTests/EnumToString.tests.cpp     |  4 ++--
 4 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/include/internal/catch_enum_values_registry.cpp b/include/internal/catch_enum_values_registry.cpp
index b94a70e5..9204e047 100644
--- a/include/internal/catch_enum_values_registry.cpp
+++ b/include/internal/catch_enum_values_registry.cpp
@@ -14,7 +14,6 @@
 namespace Catch {
 
     IMutableEnumValuesRegistry::~IMutableEnumValuesRegistry() {}
-    IEnumInfo::~IEnumInfo() {}
 
     namespace Detail {
 
@@ -29,25 +28,17 @@ namespace Catch {
             return parsed;
         }
 
-        struct EnumInfo : IEnumInfo {
-            std::string m_name;
-            std::map<int, std::string> m_values;
-
-            ~EnumInfo();
+        EnumInfo::~EnumInfo() {}
 
-            std::string lookup( int value ) const override {
-                auto it = m_values.find( value );
-                if( it == m_values.end() ) {
-                    ReusableStringStream rss;
-                    rss << "{** unexpected value for " << m_name << ": " << value << "**}";
-                    return rss.str();
-                }
-                return it->second;
+        StringRef EnumInfo::lookup( int value ) const {
+            for( auto const& valueToName : m_values ) {
+                if( valueToName.first == value )
+                    return valueToName.second;
             }
-        };
-        EnumInfo::~EnumInfo() {}
+            return "{** unexpected enum value **}";
+        }
 
-        IEnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
+        EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
             std::unique_ptr<EnumInfo> enumInfo( new EnumInfo );
             enumInfo->m_name = enumName;
 
@@ -55,7 +46,7 @@ namespace Catch {
             assert( valueNames.size() == values.size() );
             std::size_t i = 0;
             for( auto value : values )
-                enumInfo->m_values.insert({ value, valueNames[i++] });
+                enumInfo->m_values.push_back({ value, valueNames[i++] });
 
             EnumInfo* raw = enumInfo.get();
             m_enumInfos.push_back( std::move( enumInfo ) );
@@ -63,6 +54,5 @@ namespace Catch {
         }
 
     } // Detail
-
 } // Catch
 
diff --git a/include/internal/catch_enum_values_registry.h b/include/internal/catch_enum_values_registry.h
index 8103bb9d..b6943ec2 100644
--- a/include/internal/catch_enum_values_registry.h
+++ b/include/internal/catch_enum_values_registry.h
@@ -18,9 +18,9 @@ namespace Catch {
 
         class EnumValuesRegistry : public IMutableEnumValuesRegistry {
 
-            std::vector<std::unique_ptr<IEnumInfo>> m_enumInfos;
+            std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
 
-            IEnumInfo const& registerEnum(StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
+            EnumInfo const& registerEnum(StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
         };
 
         std::vector<std::string> parseEnums( StringRef enums );
diff --git a/include/internal/catch_interfaces_enum_values_registry.h b/include/internal/catch_interfaces_enum_values_registry.h
index b94ee69b..fea6847d 100644
--- a/include/internal/catch_interfaces_enum_values_registry.h
+++ b/include/internal/catch_interfaces_enum_values_registry.h
@@ -14,19 +14,24 @@
 
 namespace Catch {
 
-    struct IEnumInfo {
-        virtual ~IEnumInfo();
+    namespace Detail {
+        struct EnumInfo {
+            StringRef m_name;
+            std::vector<std::pair<int, std::string>> m_values;
 
-        virtual std::string lookup( int value ) const = 0;
-    };
+            ~EnumInfo();
+
+            StringRef lookup( int value ) const;
+        };
+    } // namespace Detail
 
     struct IMutableEnumValuesRegistry {
         virtual ~IMutableEnumValuesRegistry();
 
-        virtual IEnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
+        virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
 
         template<typename E>
-        IEnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
+        Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
             std::vector<int> intValues;
             intValues.reserve( values.size() );
             for( auto enumValue : values )
diff --git a/projects/SelfTest/UsageTests/EnumToString.tests.cpp b/projects/SelfTest/UsageTests/EnumToString.tests.cpp
index bdd36315..f3fd2f6d 100644
--- a/projects/SelfTest/UsageTests/EnumToString.tests.cpp
+++ b/projects/SelfTest/UsageTests/EnumToString.tests.cpp
@@ -75,7 +75,7 @@ TEST_CASE( "STRINGIFY_ENUM" ) {
     REQUIRE( stringify( EnumClass3::Value1 ) == "Value1" );
     REQUIRE( stringify( EnumClass3::Value2 ) == "Value2" );
     REQUIRE( stringify( EnumClass3::Value3 ) == "Value3" );
-    REQUIRE( stringify( EnumClass3::Value4 ) == "{** unexpected value for EnumClass3: 3**}" );
+    REQUIRE( stringify( EnumClass3::Value4 ) == "{** unexpected enum value **}" );
 
     EnumClass3 ec3 = EnumClass3 ::Value2;
     REQUIRE( stringify( ec3 ) == "Value2" );
@@ -91,7 +91,7 @@ TEST_CASE( "EnumInfo" ) {
 
     CHECK( enumInfo.lookup(0) == "Value1" );
     CHECK( enumInfo.lookup(1) == "Value2" );
-    CHECK( enumInfo.lookup(3) == "{** unexpected value for EnumName: 3**}" );
+    CHECK( enumInfo.lookup(3) == "{** unexpected enum value **}" );
 }
 
 #include "internal/catch_enum_values_registry.h"