blob: d623a15936f4a19bd8dd6f19287e4e57968ba0b8 [file] [log] [blame]
Howard Hinnant87846502010-08-12 21:14:20 +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 Hinnant87846502010-08-12 21:14:20 +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, size_t len, flag_type f);
15
16#include <regex>
17#include <cassert>
Howard Hinnant87846502010-08-12 21:14:20 +000018
19template <class CharT>
20void
21test(const CharT* p, std::size_t len, std::regex_constants::syntax_option_type f,
22 unsigned mc)
23{
24 std::basic_regex<CharT> r(p, len, f);
25 assert(r.flags() == f);
26 assert(r.mark_count() == mc);
27}
28
29int main()
30{
31 test("\\(a\\)", 5, std::regex_constants::basic, 1);
32 test("\\(a[bc]\\)", 9, std::regex_constants::basic, 1);
33 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::basic, 2);
34 test("(a([bc]))", 9, std::regex_constants::basic, 0);
35
36 test("\\(a\\)", 5, std::regex_constants::extended, 0);
37 test("\\(a[bc]\\)", 9, std::regex_constants::extended, 0);
38 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::extended, 0);
39 test("(a([bc]))", 9, std::regex_constants::extended, 2);
40
41 test("\\(a\\)", 5, std::regex_constants::ECMAScript, 0);
42 test("\\(a[bc]\\)", 9, std::regex_constants::ECMAScript, 0);
43 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::ECMAScript, 0);
44 test("(a([bc]))", 9, std::regex_constants::ECMAScript, 2);
45
46 test("\\(a\\)", 5, std::regex_constants::awk, 0);
47 test("\\(a[bc]\\)", 9, std::regex_constants::awk, 0);
48 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::awk, 0);
49 test("(a([bc]))", 9, std::regex_constants::awk, 2);
50
51 test("\\(a\\)", 5, std::regex_constants::grep, 1);
52 test("\\(a[bc]\\)", 9, std::regex_constants::grep, 1);
53 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::grep, 2);
54 test("(a([bc]))", 9, std::regex_constants::grep, 0);
55
56 test("\\(a\\)", 5, std::regex_constants::egrep, 0);
57 test("\\(a[bc]\\)", 9, std::regex_constants::egrep, 0);
58 test("\\(a\\([bc]\\)\\)", 13, std::regex_constants::egrep, 0);
59 test("(a([bc]))", 9, std::regex_constants::egrep, 2);
60}