2014-06-30 08:33:17 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 27/6/2014.
|
|
|
|
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "catch_tag_alias_registry.h"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_console_colour.h"
|
2017-08-01 18:46:33 +02:00
|
|
|
#include "catch_enforce.h"
|
2017-03-15 10:45:37 +01:00
|
|
|
#include "catch_interfaces_registry_hub.h"
|
|
|
|
#include "catch_stream.h"
|
2017-07-25 21:57:35 +02:00
|
|
|
#include "catch_string_manip.h"
|
2014-06-30 08:33:17 +02:00
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
TagAliasRegistry::~TagAliasRegistry() {}
|
|
|
|
|
2017-07-27 11:55:30 +02:00
|
|
|
TagAlias const* TagAliasRegistry::find( std::string const& alias ) const {
|
2017-07-18 09:08:17 +02:00
|
|
|
auto it = m_registry.find( alias );
|
2014-06-30 08:33:17 +02:00
|
|
|
if( it != m_registry.end() )
|
2017-07-27 11:55:30 +02:00
|
|
|
return &(it->second);
|
2014-06-30 08:33:17 +02:00
|
|
|
else
|
2017-07-27 11:55:30 +02:00
|
|
|
return nullptr;
|
2014-06-30 08:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
|
|
|
|
std::string expandedTestSpec = unexpandedTestSpec;
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto const& registryKvp : m_registry ) {
|
|
|
|
std::size_t pos = expandedTestSpec.find( registryKvp.first );
|
2014-06-30 08:33:17 +02:00
|
|
|
if( pos != std::string::npos ) {
|
|
|
|
expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
|
2017-04-25 12:06:52 +02:00
|
|
|
registryKvp.second.tag +
|
|
|
|
expandedTestSpec.substr( pos + registryKvp.first.size() );
|
2014-06-30 08:33:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return expandedTestSpec;
|
|
|
|
}
|
|
|
|
|
2017-03-15 10:45:37 +01:00
|
|
|
void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
|
2017-06-04 22:37:59 +02:00
|
|
|
CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'),
|
|
|
|
"error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo );
|
2014-06-30 08:33:17 +02:00
|
|
|
|
2017-06-04 22:37:59 +02:00
|
|
|
CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
|
|
|
|
"error: tag alias, '" << alias << "' already registered.\n"
|
|
|
|
<< "\tFirst seen at: " << find(alias)->lineInfo << "\n"
|
|
|
|
<< "\tRedefined at: " << lineInfo );
|
2014-06-30 08:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ITagAliasRegistry::~ITagAliasRegistry() {}
|
|
|
|
|
2017-03-15 10:45:37 +01:00
|
|
|
ITagAliasRegistry const& ITagAliasRegistry::get() {
|
|
|
|
return getRegistryHub().getTagAliasRegistry();
|
|
|
|
}
|
2014-06-30 08:33:17 +02:00
|
|
|
|
|
|
|
} // end namespace Catch
|