Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_tag_alias_registry.cpp
Go to the documentation of this file.
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
11#include "catch_enforce.h"
13#include "catch_string_manip.h"
14
15#include <sstream>
16
17namespace Catch {
18
20
21 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
29 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
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
53
57
58} // end namespace Catch
#define CATCH_ENFORCE(condition, msg)
void add(std::string const &alias, std::string const &tag, SourceLineInfo const &lineInfo)
TagAlias const * find(std::string const &alias) const override
std::string expandAliases(std::string const &unexpandedTestSpec) const override
IRegistryHub const & getRegistryHub()
bool startsWith(std::string const &s, std::string const &prefix)
bool endsWith(std::string const &s, std::string const &suffix)
virtual ITagAliasRegistry const & getTagAliasRegistry() const =0
static ITagAliasRegistry const & get()