blob: 768de568e2295d63ea20c297b12049ee66ea49fa [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// template <class ST, class SA>
15// basic_regex(const basic_string<charT, ST, SA>& s,
16// flag_type f = regex_constants::ECMAScript);
17
Howard Hinnant87846502010-08-12 21:14:20 +000018#include <regex>
19#include <cassert>
Howard Hinnant87846502010-08-12 21:14:20 +000020
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()
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}