1 /* 2 * Created by Phil on 27/6/2014. 3 * Copyright 2014 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 9 #include "catch_tag_alias_registry.h" 10 #include "catch_console_colour.h" 11 #include "catch_enforce.h" 12 #include "catch_interfaces_registry_hub.h" 13 #include "catch_string_manip.h" 14 15 #include <sstream> 16 17 namespace Catch { 18 ~TagAliasRegistry()19 TagAliasRegistry::~TagAliasRegistry() {} 20 find(std::string const & alias) const21 TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { 22 auto it = m_registry.find( alias ); 23 if( it != m_registry.end() ) 24 return &(it->second); 25 else 26 return nullptr; 27 } 28 expandAliases(std::string const & unexpandedTestSpec) const29 std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { 30 std::string expandedTestSpec = unexpandedTestSpec; 31 for( auto const& registryKvp : m_registry ) { 32 std::size_t pos = expandedTestSpec.find( registryKvp.first ); 33 if( pos != std::string::npos ) { 34 expandedTestSpec = expandedTestSpec.substr( 0, pos ) + 35 registryKvp.second.tag + 36 expandedTestSpec.substr( pos + registryKvp.first.size() ); 37 } 38 } 39 return expandedTestSpec; 40 } 41 add(std::string const & alias,std::string const & tag,SourceLineInfo const & lineInfo)42 void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { 43 CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), 44 "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); 45 46 CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, 47 "error: tag alias, '" << alias << "' already registered.\n" 48 << "\tFirst seen at: " << find(alias)->lineInfo << "\n" 49 << "\tRedefined at: " << lineInfo ); 50 } 51 ~ITagAliasRegistry()52 ITagAliasRegistry::~ITagAliasRegistry() {} 53 get()54 ITagAliasRegistry const& ITagAliasRegistry::get() { 55 return getRegistryHub().getTagAliasRegistry(); 56 } 57 58 } // end namespace Catch 59