catch_test_spec_parser.h 2.3 KB

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