Files
Catch2/src/catch2/internal/catch_test_spec_parser.hpp
T

83 lines
2.2 KiB
C++
Raw Normal View History

// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
#ifndef CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
#define CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
2014-05-16 18:24:07 +01:00
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
2020-03-30 10:34:21 +02:00
#include <catch2/catch_test_spec.hpp>
2020-07-29 16:29:41 +02:00
#include <vector>
#include <string>
namespace Catch {
2020-07-29 16:29:41 +02:00
struct ITagAliasRegistry;
class TestSpecParser {
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
Mode m_mode = None;
2019-09-14 12:38:47 +03:00
Mode lastMode = None;
bool m_exclusion = false;
std::size_t m_pos = 0;
std::size_t m_realPatternPos = 0;
std::string m_arg;
std::string m_substring;
std::string m_patternName;
std::vector<std::size_t> m_escapeChars;
TestSpec::Filter m_currentFilter;
2014-05-16 18:24:07 +01:00
TestSpec m_testSpec;
ITagAliasRegistry const* m_tagAliases = nullptr;
public:
2017-07-19 10:13:47 +02:00
TestSpecParser( ITagAliasRegistry const& tagAliases );
TestSpecParser& parse( std::string const& arg );
TestSpec testSpec();
2014-06-30 07:33:17 +01:00
private:
bool visitChar( char c );
void startNewMode( Mode mode );
bool processNoneChar( char c );
void processNameChar( char c );
bool processOtherChar( char c );
void endMode();
2017-07-19 10:13:47 +02:00
void escape();
bool isControlChar( char c ) const;
2019-09-14 12:38:47 +03:00
void saveLastMode();
void revertBackToLastMode();
void addFilter();
bool separate();
// Handles common preprocessing of the pattern for name/tag patterns
std::string preprocessPattern();
// Adds the current pattern as a test name
void addNamePattern();
// Adds the current pattern as a tag
void addTagPattern();
inline void addCharToPattern(char c) {
m_substring += c;
m_patternName += c;
m_realPatternPos++;
}
};
2017-07-19 10:13:47 +02:00
TestSpec parseTestSpec( std::string const& arg );
} // namespace Catch
2014-05-16 18:24:07 +01:00
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // CATCH_TEST_SPEC_PARSER_HPP_INCLUDED