1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <regex> 11 12 // template <class charT, class traits = regex_traits<charT>> class basic_regex; 13 14 // basic_regex(initializer_list<charT> il, 15 // flag_type f = regex_constants::ECMAScript); 16 17 #include <regex> 18 #include <cassert> 19 #include "test_macros.h" 20 21 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22 23 void 24 test(std::initializer_list<char> il, std::regex_constants::syntax_option_type f, unsigned mc) 25 { 26 std::basic_regex<char> r(il, f); 27 assert(r.flags() == f); 28 assert(r.mark_count() == mc); 29 } 30 31 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 32 33 int main() 34 { 35 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 36 std::string s1("\\(a\\)"); 37 std::string s2("\\(a[bc]\\)"); 38 std::string s3("\\(a\\([bc]\\)\\)"); 39 std::string s4("(a([bc]))"); 40 41 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1); 42 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1); 43 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2); 44 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0); 45 46 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0); 47 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0); 48 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0); 49 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2); 50 51 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0); 52 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0); 53 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0); 54 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2); 55 56 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0); 57 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0); 58 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0); 59 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2); 60 61 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1); 62 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1); 63 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2); 64 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0); 65 66 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0); 67 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0); 68 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0); 69 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2); 70 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 71 } 72