refactored toLower

This commit is contained in:
Phil Nash 2013-03-22 19:00:42 +00:00
parent f4254b8622
commit 6ba2057abd
5 changed files with 13 additions and 12 deletions

View File

@ -80,9 +80,14 @@ namespace Catch {
inline bool contains( const std::string& s, const std::string& infix ) {
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 );
}
inline std::string toLower( std::string const& s ) {
std::string lc = s;
toLowerInPlace( lc );
return lc;
}
struct pluralise {
pluralise( std::size_t count, const std::string& label )

View File

@ -70,9 +70,7 @@ namespace Catch {
private:
virtual void acceptTag( const std::string& tag ) {
std::string lcTag = tag;
toLower( lcTag );
m_tags.insert( lcTag );
m_tags.insert( toLower( tag ) );
}
virtual void acceptChar( char c ) {
m_remainder += c;
@ -115,9 +113,7 @@ namespace Catch {
typedef std::map<std::string, Tag> TagMap;
public:
void add( const Tag& tag ) {
std::string tagName = tag.getName();
toLower( tagName );
m_tags.insert( std::make_pair( tagName, tag ) );
m_tags.insert( std::make_pair( toLower( tag.getName() ), tag ) );
}
bool empty() const {

View File

@ -11,6 +11,7 @@
#include "catch_tags.hpp"
#include "catch_test_case_info.h"
#include "catch_interfaces_testcase.h"
#include "catch_common.h"
namespace Catch {
@ -76,7 +77,7 @@ namespace Catch {
}
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 {
TagExpression exp;

View File

@ -33,12 +33,10 @@ namespace Catch {
public:
TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
: m_stringToMatch( testSpec ),
: m_stringToMatch( toLower( testSpec ) ),
m_filterType( matchBehaviour ),
m_wildcardPosition( NoWildcard )
{
toLower( m_stringToMatch );
if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
if( startsWith( m_stringToMatch, "exclude:" ) ) {
m_stringToMatch = m_stringToMatch.substr( 8 );
@ -79,7 +77,7 @@ namespace Catch {
bool isMatch( const TestCase& testCase ) const {
std::string name = testCase.getTestCaseInfo().name;
toLower( name );
toLowerInPlace( name );
switch( m_wildcardPosition ) {
case NoWildcard:

View File

@ -383,6 +383,7 @@ TEST_CASE( "selftest/tags", "" ) {
CHECK( twoTags.getTestCaseInfo().description == "" );
CHECK( twoTags.hasTag( "one" ) );
CHECK( twoTags.hasTag( "two" ) );
CHECK( twoTags.hasTag( "Two" ) );
CHECK( twoTags.hasTag( "three" ) == false );
CHECK( twoTags.getTags().size() == 2 );