mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26: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 ) {
|
||||
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 )
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user