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 // <regex>
10
11 // template <class charT, class traits = regex_traits<charT>> class basic_regex;
12
13 // basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
14
15 #include <regex>
16 #include <cassert>
17 #include "test_macros.h"
18
19 template <class CharT>
20 void
test(const CharT * p,std::regex_constants::syntax_option_type f,unsigned mc)21 test(const CharT* p, std::regex_constants::syntax_option_type f, unsigned mc)
22 {
23 std::basic_regex<CharT> r(p, f);
24 assert(r.flags() == f);
25 assert(r.mark_count() == mc);
26 }
27
main(int,char **)28 int main(int, char**)
29 {
30 test("\\(a\\)", std::regex_constants::basic, 1);
31 test("\\(a[bc]\\)", std::regex_constants::basic, 1);
32 test("\\(a\\([bc]\\)\\)", std::regex_constants::basic, 2);
33 test("(a([bc]))", std::regex_constants::basic, 0);
34
35 test("\\(a\\)", std::regex_constants::extended, 0);
36 test("\\(a[bc]\\)", std::regex_constants::extended, 0);
37 test("\\(a\\([bc]\\)\\)", std::regex_constants::extended, 0);
38 test("(a([bc]))", std::regex_constants::extended, 2);
39
40 test("\\(a\\)", std::regex_constants::ECMAScript, 0);
41 test("\\(a[bc]\\)", std::regex_constants::ECMAScript, 0);
42 test("\\(a\\([bc]\\)\\)", std::regex_constants::ECMAScript, 0);
43 test("(a([bc]))", std::regex_constants::ECMAScript, 2);
44
45 test("\\(a\\)", std::regex_constants::awk, 0);
46 test("\\(a[bc]\\)", std::regex_constants::awk, 0);
47 test("\\(a\\([bc]\\)\\)", std::regex_constants::awk, 0);
48 test("(a([bc]))", std::regex_constants::awk, 2);
49
50 test("\\(a\\)", std::regex_constants::grep, 1);
51 test("\\(a[bc]\\)", std::regex_constants::grep, 1);
52 test("\\(a\\([bc]\\)\\)", std::regex_constants::grep, 2);
53 test("(a([bc]))", std::regex_constants::grep, 0);
54
55 test("\\(a\\)", std::regex_constants::egrep, 0);
56 test("\\(a[bc]\\)", std::regex_constants::egrep, 0);
57 test("\\(a\\([bc]\\)\\)", std::regex_constants::egrep, 0);
58 test("(a([bc]))", std::regex_constants::egrep, 2);
59
60 return 0;
61 }
62