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

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