mirror of https://github.com/catchorg/Catch2.git
Added Equals matcher for NSString
This commit is contained in:
parent
78d95a0854
commit
db837a157f
|
@ -196,6 +196,22 @@ namespace Catch
|
||||||
NSString* m_substr;
|
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
|
struct Contains : StringHolder
|
||||||
{
|
{
|
||||||
Contains( NSString* substr ) : StringHolder( substr ){}
|
Contains( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
@ -246,10 +262,15 @@ namespace Catch
|
||||||
} // namespace NSStringMatchers
|
} // namespace NSStringMatchers
|
||||||
} // namespace Impl
|
} // namespace Impl
|
||||||
|
|
||||||
|
inline Impl::NSStringMatchers::Equals
|
||||||
|
Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
|
||||||
|
|
||||||
inline Impl::NSStringMatchers::Contains
|
inline Impl::NSStringMatchers::Contains
|
||||||
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
|
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
|
||||||
|
|
||||||
inline Impl::NSStringMatchers::StartsWith
|
inline Impl::NSStringMatchers::StartsWith
|
||||||
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
|
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
|
||||||
|
|
||||||
inline Impl::NSStringMatchers::EndsWith
|
inline Impl::NSStringMatchers::EndsWith
|
||||||
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
|
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ OC_TEST_CASE( "OCTest/test2", "This is another test case" )
|
||||||
using namespace Catch::Matchers;
|
using namespace Catch::Matchers;
|
||||||
OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)" )
|
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", Contains( @"is a" ) );
|
||||||
REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
|
REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
|
||||||
REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
|
REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
|
||||||
|
|
Loading…
Reference in New Issue