mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 23:36:11 +01:00
refactored toLower
This commit is contained in:
parent
f4254b8622
commit
6ba2057abd
@ -80,9 +80,14 @@ namespace Catch {
|
|||||||
inline bool contains( const std::string& s, const std::string& infix ) {
|
inline bool contains( const std::string& s, const std::string& infix ) {
|
||||||
return s.find( infix ) != std::string::npos;
|
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 );
|
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 {
|
struct pluralise {
|
||||||
pluralise( std::size_t count, const std::string& label )
|
pluralise( std::size_t count, const std::string& label )
|
||||||
|
@ -70,9 +70,7 @@ namespace Catch {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void acceptTag( const std::string& tag ) {
|
virtual void acceptTag( const std::string& tag ) {
|
||||||
std::string lcTag = tag;
|
m_tags.insert( toLower( tag ) );
|
||||||
toLower( lcTag );
|
|
||||||
m_tags.insert( lcTag );
|
|
||||||
}
|
}
|
||||||
virtual void acceptChar( char c ) {
|
virtual void acceptChar( char c ) {
|
||||||
m_remainder += c;
|
m_remainder += c;
|
||||||
@ -115,9 +113,7 @@ namespace Catch {
|
|||||||
typedef std::map<std::string, Tag> TagMap;
|
typedef std::map<std::string, Tag> TagMap;
|
||||||
public:
|
public:
|
||||||
void add( const Tag& tag ) {
|
void add( const Tag& tag ) {
|
||||||
std::string tagName = tag.getName();
|
m_tags.insert( std::make_pair( toLower( tag.getName() ), tag ) );
|
||||||
toLower( tagName );
|
|
||||||
m_tags.insert( std::make_pair( tagName, tag ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "catch_tags.hpp"
|
#include "catch_tags.hpp"
|
||||||
#include "catch_test_case_info.h"
|
#include "catch_test_case_info.h"
|
||||||
#include "catch_interfaces_testcase.h"
|
#include "catch_interfaces_testcase.h"
|
||||||
|
#include "catch_common.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TestCase::hasTag( const std::string& tag ) const {
|
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 {
|
bool TestCase::matchesTags( const std::string& tagPattern ) const {
|
||||||
TagExpression exp;
|
TagExpression exp;
|
||||||
|
@ -33,12 +33,10 @@ namespace Catch {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
|
TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
|
||||||
: m_stringToMatch( testSpec ),
|
: m_stringToMatch( toLower( testSpec ) ),
|
||||||
m_filterType( matchBehaviour ),
|
m_filterType( matchBehaviour ),
|
||||||
m_wildcardPosition( NoWildcard )
|
m_wildcardPosition( NoWildcard )
|
||||||
{
|
{
|
||||||
toLower( m_stringToMatch );
|
|
||||||
|
|
||||||
if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
|
if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
|
||||||
if( startsWith( m_stringToMatch, "exclude:" ) ) {
|
if( startsWith( m_stringToMatch, "exclude:" ) ) {
|
||||||
m_stringToMatch = m_stringToMatch.substr( 8 );
|
m_stringToMatch = m_stringToMatch.substr( 8 );
|
||||||
@ -79,7 +77,7 @@ namespace Catch {
|
|||||||
|
|
||||||
bool isMatch( const TestCase& testCase ) const {
|
bool isMatch( const TestCase& testCase ) const {
|
||||||
std::string name = testCase.getTestCaseInfo().name;
|
std::string name = testCase.getTestCaseInfo().name;
|
||||||
toLower( name );
|
toLowerInPlace( name );
|
||||||
|
|
||||||
switch( m_wildcardPosition ) {
|
switch( m_wildcardPosition ) {
|
||||||
case NoWildcard:
|
case NoWildcard:
|
||||||
|
@ -383,6 +383,7 @@ TEST_CASE( "selftest/tags", "" ) {
|
|||||||
CHECK( twoTags.getTestCaseInfo().description == "" );
|
CHECK( twoTags.getTestCaseInfo().description == "" );
|
||||||
CHECK( twoTags.hasTag( "one" ) );
|
CHECK( twoTags.hasTag( "one" ) );
|
||||||
CHECK( twoTags.hasTag( "two" ) );
|
CHECK( twoTags.hasTag( "two" ) );
|
||||||
|
CHECK( twoTags.hasTag( "Two" ) );
|
||||||
CHECK( twoTags.hasTag( "three" ) == false );
|
CHECK( twoTags.hasTag( "three" ) == false );
|
||||||
CHECK( twoTags.getTags().size() == 2 );
|
CHECK( twoTags.getTags().size() == 2 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user