Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_wildcard_pattern.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-09-09 11:30:45 +0200
committerMartin Hořeňovský2019-09-09 14:28:11 +0200
commitaf8b2538a62db34b3cec10ceb74e3d29bd06e37f (patch)
tree32069c3bf1662b5d50a78829584b3352458f238c /include/internal/catch_wildcard_pattern.cpp
parenta156440b19c1103419b6e4d3ebbfe3c7ddb948dc (diff)
downloadcatch3-af8b2538a62db34b3cec10ceb74e3d29bd06e37f.tar.gz
Ignore leading/trailing whitespace in test/section specs
The leading/trailing whitespace is problematic because of e.g. `WHEN` macro having preceeding whitespace for alignment, and it is generally messy. Credits to Phil who did lot of the original work. Closes #1708
Diffstat (limited to 'include/internal/catch_wildcard_pattern.cpp')
-rw-r--r--include/internal/catch_wildcard_pattern.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/include/internal/catch_wildcard_pattern.cpp b/include/internal/catch_wildcard_pattern.cpp
index 9bf20f04..95e5d3f0 100644
--- a/include/internal/catch_wildcard_pattern.cpp
+++ b/include/internal/catch_wildcard_pattern.cpp
@@ -9,14 +9,12 @@
#include "catch_enforce.h"
#include "catch_string_manip.h"
-#include <sstream>
-
namespace Catch {
WildcardPattern::WildcardPattern( std::string const& pattern,
CaseSensitive::Choice caseSensitivity )
: m_caseSensitivity( caseSensitivity ),
- m_pattern( adjustCase( pattern ) )
+ m_pattern( normaliseString( pattern ) )
{
if( startsWith( m_pattern, '*' ) ) {
m_pattern = m_pattern.substr( 1 );
@@ -31,19 +29,19 @@ namespace Catch {
bool WildcardPattern::matches( std::string const& str ) const {
switch( m_wildcard ) {
case NoWildcard:
- return m_pattern == adjustCase( str );
+ return m_pattern == normaliseString( str );
case WildcardAtStart:
- return endsWith( adjustCase( str ), m_pattern );
+ return endsWith( normaliseString( str ), m_pattern );
case WildcardAtEnd:
- return startsWith( adjustCase( str ), m_pattern );
+ return startsWith( normaliseString( str ), m_pattern );
case WildcardAtBothEnds:
- return contains( adjustCase( str ), m_pattern );
+ return contains( normaliseString( str ), m_pattern );
default:
CATCH_INTERNAL_ERROR( "Unknown enum" );
}
}
- std::string WildcardPattern::adjustCase( std::string const& str ) const {
- return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
+ std::string WildcardPattern::normaliseString( std::string const& str ) const {
+ return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str );
}
}