mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Merged Matcher changes to Objective-C bindings
This commit is contained in:
parent
7455c449ad
commit
a8c6543bcc
@ -144,7 +144,7 @@ namespace Catch {
|
|||||||
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0;
|
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0;
|
||||||
virtual std::string argsSynopsis() const = 0;
|
virtual std::string argsSynopsis() const = 0;
|
||||||
virtual std::string optionSummary() const = 0;
|
virtual std::string optionSummary() const = 0;
|
||||||
virtual std::string optionDescription() const { return ""; };
|
virtual std::string optionDescription() const { return ""; }
|
||||||
|
|
||||||
std::string optionNames() const {
|
std::string optionNames() const {
|
||||||
std::string names;
|
std::string names;
|
||||||
|
@ -15,6 +15,8 @@ namespace Matchers {
|
|||||||
template<typename ExpressionT>
|
template<typename ExpressionT>
|
||||||
struct Matcher : SharedImpl<IShared>
|
struct Matcher : SharedImpl<IShared>
|
||||||
{
|
{
|
||||||
|
typedef ExpressionT ExpressionType;
|
||||||
|
|
||||||
virtual ~Matcher() {}
|
virtual ~Matcher() {}
|
||||||
virtual Ptr<Matcher> clone() const = 0;
|
virtual Ptr<Matcher> clone() const = 0;
|
||||||
virtual bool match( const ExpressionT& expr ) const = 0;
|
virtual bool match( const ExpressionT& expr ) const = 0;
|
||||||
|
@ -108,8 +108,10 @@ namespace Catch {
|
|||||||
namespace Impl {
|
namespace Impl {
|
||||||
namespace NSStringMatchers {
|
namespace NSStringMatchers {
|
||||||
|
|
||||||
struct StringHolder {
|
template<typename MatcherT>
|
||||||
|
struct StringHolder : MatcherImpl<MatcherT, NSString*>{
|
||||||
StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
|
StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
|
||||||
|
StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
|
||||||
StringHolder() {
|
StringHolder() {
|
||||||
arcSafeRelease( m_substr );
|
arcSafeRelease( m_substr );
|
||||||
}
|
}
|
||||||
@ -117,54 +119,50 @@ namespace Catch {
|
|||||||
NSString* m_substr;
|
NSString* m_substr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Equals : StringHolder {
|
struct Equals : StringHolder<Equals> {
|
||||||
Equals( NSString* substr ) : StringHolder( substr ){}
|
Equals( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str isEqualToString:m_substr];
|
return [str isEqualToString:m_substr];
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const Equals& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "equals string: " << Catch::toString( matcher.m_substr );
|
return "equals string: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Contains : StringHolder {
|
struct Contains : StringHolder<Contains> {
|
||||||
Contains( NSString* substr ) : StringHolder( substr ){}
|
Contains( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location != NSNotFound;
|
return [str rangeOfString:m_substr].location != NSNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const Contains& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "contains: " << Catch::toString( matcher.m_substr );
|
return "contains string: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StartsWith : StringHolder {
|
struct StartsWith : StringHolder<StartsWith> {
|
||||||
StartsWith( NSString* substr ) : StringHolder( substr ){}
|
StartsWith( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location == 0;
|
return [str rangeOfString:m_substr].location == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const StartsWith& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "starts with: " << Catch::toString( matcher.m_substr );
|
return "starts with: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct EndsWith : StringHolder {
|
struct EndsWith : StringHolder<EndsWith> {
|
||||||
EndsWith( NSString* substr ) : StringHolder( substr ){}
|
EndsWith( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
|
return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const EndsWith& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "ends with: " << Catch::toString( matcher.m_substr );
|
return "ends with: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Expected::Result m_expectedResult;
|
Expected::Result m_expectedResult;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated: 2012-11-13 22:03:59.839085
|
* Generated: 2013-02-19 08:44:57.311773
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -2550,6 +2550,8 @@ namespace Matchers {
|
|||||||
template<typename ExpressionT>
|
template<typename ExpressionT>
|
||||||
struct Matcher : SharedImpl<IShared>
|
struct Matcher : SharedImpl<IShared>
|
||||||
{
|
{
|
||||||
|
typedef ExpressionT ExpressionType;
|
||||||
|
|
||||||
virtual ~Matcher() {}
|
virtual ~Matcher() {}
|
||||||
virtual Ptr<Matcher> clone() const = 0;
|
virtual Ptr<Matcher> clone() const = 0;
|
||||||
virtual bool match( const ExpressionT& expr ) const = 0;
|
virtual bool match( const ExpressionT& expr ) const = 0;
|
||||||
@ -2841,8 +2843,9 @@ namespace Catch {
|
|||||||
std::string testCaseName = methodName.substr( 15 );
|
std::string testCaseName = methodName.substr( 15 );
|
||||||
std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
|
std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
|
||||||
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
|
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
|
||||||
|
const char* className = class_getName( cls );
|
||||||
|
|
||||||
getMutableRegistryHub().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) );
|
getMutableRegistryHub().registerTest( TestCaseInfo( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
|
||||||
noTestMethods++;
|
noTestMethods++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2856,8 +2859,10 @@ namespace Catch {
|
|||||||
namespace Impl {
|
namespace Impl {
|
||||||
namespace NSStringMatchers {
|
namespace NSStringMatchers {
|
||||||
|
|
||||||
struct StringHolder {
|
template<typename MatcherT>
|
||||||
|
struct StringHolder : MatcherImpl<MatcherT, NSString*>{
|
||||||
StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
|
StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
|
||||||
|
StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
|
||||||
StringHolder() {
|
StringHolder() {
|
||||||
arcSafeRelease( m_substr );
|
arcSafeRelease( m_substr );
|
||||||
}
|
}
|
||||||
@ -2865,54 +2870,50 @@ namespace Catch {
|
|||||||
NSString* m_substr;
|
NSString* m_substr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Equals : StringHolder {
|
struct Equals : StringHolder<Equals> {
|
||||||
Equals( NSString* substr ) : StringHolder( substr ){}
|
Equals( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str isEqualToString:m_substr];
|
return [str isEqualToString:m_substr];
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const Equals& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "equals string: " << Catch::toString( matcher.m_substr );
|
return "equals string: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Contains : StringHolder {
|
struct Contains : StringHolder<Contains> {
|
||||||
Contains( NSString* substr ) : StringHolder( substr ){}
|
Contains( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location != NSNotFound;
|
return [str rangeOfString:m_substr].location != NSNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const Contains& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "contains: " << Catch::toString( matcher.m_substr );
|
return "contains string: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StartsWith : StringHolder {
|
struct StartsWith : StringHolder<StartsWith> {
|
||||||
StartsWith( NSString* substr ) : StringHolder( substr ){}
|
StartsWith( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location == 0;
|
return [str rangeOfString:m_substr].location == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const StartsWith& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "starts with: " << Catch::toString( matcher.m_substr );
|
return "starts with: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct EndsWith : StringHolder {
|
struct EndsWith : StringHolder<EndsWith> {
|
||||||
EndsWith( NSString* substr ) : StringHolder( substr ){}
|
EndsWith( NSString* substr ) : StringHolder( substr ){}
|
||||||
|
|
||||||
bool operator()( NSString* str ) const {
|
virtual bool match( ExpressionType const& str ) const {
|
||||||
return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
|
return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& os, const EndsWith& matcher ) {
|
virtual std::string toString() const {
|
||||||
os << "ends with: " << Catch::toString( matcher.m_substr );
|
return "ends with: \"" + Catch::toString( m_substr ) + "\"";
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3102,7 +3103,7 @@ namespace Catch {
|
|||||||
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0;
|
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0;
|
||||||
virtual std::string argsSynopsis() const = 0;
|
virtual std::string argsSynopsis() const = 0;
|
||||||
virtual std::string optionSummary() const = 0;
|
virtual std::string optionSummary() const = 0;
|
||||||
virtual std::string optionDescription() const { return ""; };
|
virtual std::string optionDescription() const { return ""; }
|
||||||
|
|
||||||
std::string optionNames() const {
|
std::string optionNames() const {
|
||||||
std::string names;
|
std::string names;
|
||||||
|
Loading…
Reference in New Issue
Block a user