1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03 10 11 // <regex> 12 13 // template <class charT, class traits = regex_traits<charT>> class basic_regex; 14 15 // basic_regex(initializer_list<charT> il, 16 // flag_type f = regex_constants::ECMAScript); 17 18 #include <regex> 19 #include <cassert> 20 #include "test_macros.h" 21 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 32 int main() 33 { 34 std::string s1("\\(a\\)"); 35 std::string s2("\\(a[bc]\\)"); 36 std::string s3("\\(a\\([bc]\\)\\)"); 37 std::string s4("(a([bc]))"); 38 39 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1); 40 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1); 41 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2); 42 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0); 43 44 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0); 45 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0); 46 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0); 47 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2); 48 49 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0); 50 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0); 51 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0); 52 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2); 53 54 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0); 55 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0); 56 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0); 57 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2); 58 59 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1); 60 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1); 61 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2); 62 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0); 63 64 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0); 65 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0); 66 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0); 67 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2); 68 } 69