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++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
23void
24test(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
32int main(int, char**)
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(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::basic, mc: 1);
40 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::basic, mc: 1);
41 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::basic, mc: 2);
42 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::basic, mc: 0);
43
44 test(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::extended, mc: 0);
45 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::extended, mc: 0);
46 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::extended, mc: 0);
47 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::extended, mc: 2);
48
49 test(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::ECMAScript, mc: 0);
50 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::ECMAScript, mc: 0);
51 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::ECMAScript, mc: 0);
52 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::ECMAScript, mc: 2);
53
54 test(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::awk, mc: 0);
55 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::awk, mc: 0);
56 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::awk, mc: 0);
57 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::awk, mc: 2);
58
59 test(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::grep, mc: 1);
60 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::grep, mc: 1);
61 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::grep, mc: 2);
62 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::grep, mc: 0);
63
64 test(il: {'\\', '(', 'a', '\\', ')'}, f: std::regex_constants::egrep, mc: 0);
65 test(il: {'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, f: std::regex_constants::egrep, mc: 0);
66 test(il: {'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, f: std::regex_constants::egrep, mc: 0);
67 test(il: {'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, f: std::regex_constants::egrep, mc: 2);
68
69 return 0;
70}
71

source code of libcxx/test/std/re/re.regex/re.regex.construct/il_flg.pass.cpp