blob: 70d28df370d11857ca9904fe7a7ca7361bb5f561 [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(initializer_list<charT> il,
15// flag_type f = regex_constants::ECMAScript);
16
17#include <regex>
18#include <cassert>
19
Howard Hinnante3e32912011-08-12 21:56:02 +000020#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant87846502010-08-12 21:14:20 +000021
22void
23test(std::initializer_list<char> il, std::regex_constants::syntax_option_type f, unsigned mc)
24{
25 std::basic_regex<char> r(il, f);
26 assert(r.flags() == f);
27 assert(r.mark_count() == mc);
28}
29
Howard Hinnante3e32912011-08-12 21:56:02 +000030#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant87846502010-08-12 21:14:20 +000031
32int main()
33{
Howard Hinnante3e32912011-08-12 21:56:02 +000034#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant87846502010-08-12 21:14:20 +000035 std::string s1("\\(a\\)");
36 std::string s2("\\(a[bc]\\)");
37 std::string s3("\\(a\\([bc]\\)\\)");
38 std::string s4("(a([bc]))");
39
40 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1);
41 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1);
42 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2);
43 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0);
44
45 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0);
46 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0);
47 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0);
48 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2);
49
50 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0);
51 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0);
52 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0);
53 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2);
54
55 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0);
56 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0);
57 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0);
58 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2);
59
60 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1);
61 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1);
62 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2);
63 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0);
64
65 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0);
66 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0);
67 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0);
68 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2);
Howard Hinnante3e32912011-08-12 21:56:02 +000069#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant87846502010-08-12 21:14:20 +000070}