blob: 31f9da9e4dfbe5bc1daefaad1b9cb47454b2d40b [file] [log] [blame]
Howard Hinnant853aff82010-06-25 20:56:08 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
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 Hinnante5561b02010-06-29 18:37:43 +000016#include <iostream>
17
Howard Hinnant853aff82010-06-25 20:56:08 +000018#include <regex>
19#include <cassert>
20
21template <class CharT>
22void
23test(const CharT* p, std::regex_constants::syntax_option_type f, unsigned mc)
24{
25 std::basic_regex<CharT> r(p, f);
26 assert(r.flags() == f);
27 assert(r.mark_count() == mc);
28}
29
30int main()
31{
Howard Hinnant853aff82010-06-25 20:56:08 +000032 test("\\(a\\)", std::regex_constants::basic, 1);
33 test("\\(a[bc]\\)", std::regex_constants::basic, 1);
34 test("\\(a\\([bc]\\)\\)", std::regex_constants::basic, 2);
35 test("(a([bc]))", std::regex_constants::basic, 0);
Howard Hinnant3d87b692010-08-12 21:14:20 +000036
37 test("\\(a\\)", std::regex_constants::extended, 0);
38 test("\\(a[bc]\\)", std::regex_constants::extended, 0);
39 test("\\(a\\([bc]\\)\\)", std::regex_constants::extended, 0);
40 test("(a([bc]))", std::regex_constants::extended, 2);
41
42 test("\\(a\\)", std::regex_constants::ECMAScript, 0);
43 test("\\(a[bc]\\)", std::regex_constants::ECMAScript, 0);
44 test("\\(a\\([bc]\\)\\)", std::regex_constants::ECMAScript, 0);
45 test("(a([bc]))", std::regex_constants::ECMAScript, 2);
46
47 test("\\(a\\)", std::regex_constants::awk, 0);
48 test("\\(a[bc]\\)", std::regex_constants::awk, 0);
49 test("\\(a\\([bc]\\)\\)", std::regex_constants::awk, 0);
50 test("(a([bc]))", std::regex_constants::awk, 2);
51
52 test("\\(a\\)", std::regex_constants::grep, 1);
53 test("\\(a[bc]\\)", std::regex_constants::grep, 1);
54 test("\\(a\\([bc]\\)\\)", std::regex_constants::grep, 2);
55 test("(a([bc]))", std::regex_constants::grep, 0);
56
57 test("\\(a\\)", std::regex_constants::egrep, 0);
58 test("\\(a[bc]\\)", std::regex_constants::egrep, 0);
59 test("\\(a\\([bc]\\)\\)", std::regex_constants::egrep, 0);
60 test("(a([bc]))", std::regex_constants::egrep, 2);
Howard Hinnant853aff82010-06-25 20:56:08 +000061}