blob: 138e20efbf657eba57720a5c0dcdb2e9dfe6395f [file] [log] [blame]
Howard Hinnant0de86b62010-06-25 20:56:08 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant0de86b62010-06-25 20:56:08 +00007//
8//===----------------------------------------------------------------------===//
9
10// <regex>
11
12// template <class charT, class traits = regex_traits<charT>> class basic_regex;
13
14// basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
15
Howard Hinnant0de86b62010-06-25 20:56:08 +000016#include <regex>
17#include <cassert>
18
19template <class CharT>
20void
21test(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
28int main()
29{
Howard Hinnant0de86b62010-06-25 20:56:08 +000030 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);
Howard Hinnant87846502010-08-12 21:14:20 +000034
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);
Howard Hinnant0de86b62010-06-25 20:56:08 +000059}