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

Added Equals matcher for NSString

Commit
db837a157f710c5f6f7910bf40d7fcee3f68efeb
Author
Phil Nash ·
Parents
78d95a085440

Files · Download .tar.gz

Changes

 include/internal/catch_objc.hpp                  | 21 +++++++++++++++++++++
 projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm |  1 +
 2 files changed, 22 insertions(+)

diff --git a/include/internal/catch_objc.hpp b/include/internal/catch_objc.hpp
index a36d9555..f8044a0c 100644
--- a/include/internal/catch_objc.hpp
+++ b/include/internal/catch_objc.hpp
@@ -196,6 +196,22 @@ namespace Catch
                 NSString* m_substr;            
             };
             
+            struct Equals : StringHolder
+            {
+                Equals( NSString* substr ) : StringHolder( substr ){}
+                
+                bool operator()( NSString* str ) const
+                {
+                    return [str isEqualToString:m_substr];
+                }
+                
+                friend std::ostream& operator<<( std::ostream& os, const Equals& matcher )
+                {
+                    os << "equals string: " << Catch::toString( matcher.m_substr );
+                    return os;
+                }
+            };
+            
             struct Contains : StringHolder
             {
                 Contains( NSString* substr ) : StringHolder( substr ){}
@@ -246,10 +262,15 @@ namespace Catch
         } // namespace NSStringMatchers
         } // namespace Impl
         
+        inline Impl::NSStringMatchers::Equals
+            Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
+        
         inline Impl::NSStringMatchers::Contains
             Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
+        
         inline Impl::NSStringMatchers::StartsWith
             StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
+        
         inline Impl::NSStringMatchers::EndsWith
             EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
         
diff --git a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
index 189903b2..008ac875 100644
--- a/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
+++ b/projects/XCode4/OCTest/OCTest/CatchOCTestCase.mm
@@ -45,6 +45,7 @@ OC_TEST_CASE( "OCTest/test2", "This is another test case" )
 using namespace Catch::Matchers;
 OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)" )
 {
+    REQUIRE_THAT( @"This is a string", Equals( @"This is a string" ) );
     REQUIRE_THAT( @"This is a string", Contains( @"is a" ) );
     REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
     REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );