File indexing completed on 2025-01-19 09:25:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_UNIT_TEST_MATCH_HPP
0011 #define BOOST_BEAST_UNIT_TEST_MATCH_HPP
0012
0013 #include <boost/beast/_experimental/unit_test/suite_info.hpp>
0014 #include <string>
0015
0016 namespace boost {
0017 namespace beast {
0018 namespace unit_test {
0019
0020
0021 class selector
0022 {
0023 public:
0024 enum mode_t
0025 {
0026
0027 all,
0028
0029
0030 automatch,
0031
0032
0033 suite,
0034
0035
0036 library,
0037
0038
0039 module,
0040
0041
0042 none
0043 };
0044
0045 private:
0046 mode_t mode_;
0047 std::string pat_;
0048 std::string library_;
0049
0050 public:
0051 template<class = void>
0052 explicit
0053 selector(mode_t mode, std::string const& pattern = "");
0054
0055 template<class = void>
0056 bool
0057 operator()(suite_info const& s);
0058 };
0059
0060
0061
0062 template<class>
0063 selector::selector(mode_t mode, std::string const& pattern)
0064 : mode_(mode)
0065 , pat_(pattern)
0066 {
0067 if(mode_ == automatch && pattern.empty())
0068 mode_ = all;
0069 }
0070
0071 template<class>
0072 bool
0073 selector::operator()(suite_info const& s)
0074 {
0075 switch(mode_)
0076 {
0077 case automatch:
0078
0079 if(s.name() == pat_ || s.full_name() == pat_)
0080 {
0081 mode_ = none;
0082 return true;
0083 }
0084
0085
0086 if(pat_ == s.module())
0087 {
0088 mode_ = module;
0089 library_ = s.library();
0090 return ! s.manual();
0091 }
0092
0093
0094 if(pat_ == s.library())
0095 {
0096 mode_ = library;
0097 return ! s.manual();
0098 }
0099
0100 return false;
0101
0102 case suite:
0103 return pat_ == s.name();
0104
0105 case module:
0106 return pat_ == s.module() && ! s.manual();
0107
0108 case library:
0109 return pat_ == s.library() && ! s.manual();
0110
0111 case none:
0112 return false;
0113
0114 case all:
0115 default:
0116
0117 break;
0118 };
0119
0120 return ! s.manual();
0121 }
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 inline
0143 selector
0144 match_auto(std::string const& name)
0145 {
0146 return selector(selector::automatch, name);
0147 }
0148
0149
0150 inline
0151 selector
0152 match_all()
0153 {
0154 return selector(selector::all);
0155 }
0156
0157
0158 inline
0159 selector
0160 match_suite(std::string const& name)
0161 {
0162 return selector(selector::suite, name);
0163 }
0164
0165
0166 inline
0167 selector
0168 match_library(std::string const& name)
0169 {
0170 return selector(selector::library, name);
0171 }
0172
0173 }
0174 }
0175 }
0176
0177 #endif