1 /* 2 * Created by Phil on 15/5/2013. 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 #ifndef TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED 10 11 #ifdef __clang__ 12 #pragma clang diagnostic push 13 #pragma clang diagnostic ignored "-Wpadded" 14 #endif 15 16 #include "catch_test_spec.h" 17 #include "catch_string_manip.h" 18 #include "catch_interfaces_tag_alias_registry.h" 19 20 namespace Catch { 21 22 class TestSpecParser { 23 enum Mode{ None, Name, QuotedName, Tag, EscapedName }; 24 Mode m_mode = None; 25 Mode lastMode = None; 26 bool m_exclusion = false; 27 std::size_t m_pos = 0; 28 std::size_t m_realPatternPos = 0; 29 std::string m_arg; 30 std::string m_substring; 31 std::string m_patternName; 32 std::vector<std::size_t> m_escapeChars; 33 TestSpec::Filter m_currentFilter; 34 TestSpec m_testSpec; 35 ITagAliasRegistry const* m_tagAliases = nullptr; 36 37 public: 38 TestSpecParser( ITagAliasRegistry const& tagAliases ); 39 40 TestSpecParser& parse( std::string const& arg ); 41 TestSpec testSpec(); 42 43 private: 44 bool visitChar( char c ); 45 void startNewMode( Mode mode ); 46 bool processNoneChar( char c ); 47 void processNameChar( char c ); 48 bool processOtherChar( char c ); 49 void endMode(); 50 void escape(); 51 bool isControlChar( char c ) const; 52 void saveLastMode(); 53 void revertBackToLastMode(); 54 void addFilter(); 55 bool separate(); 56 57 // Handles common preprocessing of the pattern for name/tag patterns 58 std::string preprocessPattern(); 59 // Adds the current pattern as a test name 60 void addNamePattern(); 61 // Adds the current pattern as a tag 62 void addTagPattern(); 63 addCharToPattern(char c)64 inline void addCharToPattern(char c) { 65 m_substring += c; 66 m_patternName += c; 67 m_realPatternPos++; 68 } 69 70 }; 71 TestSpec parseTestSpec( std::string const& arg ); 72 73 } // namespace Catch 74 75 #ifdef __clang__ 76 #pragma clang diagnostic pop 77 #endif 78 79 #endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED