1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // template <class charT, class traits = regex_traits<charT>> class basic_regex;
15 // basic_regex(initializer_list<charT> il,
16 // flag_type f = regex_constants::ECMAScript);
20 #include "test_macros.h"
24 test(std::initializer_list
<char> il
, std::regex_constants::syntax_option_type f
, unsigned mc
)
26 std::basic_regex
<char> r(il
, f
);
27 assert(r
.flags() == f
);
28 assert(r
.mark_count() == mc
);
34 std::string
s1("\\(a\\)");
35 std::string
s2("\\(a[bc]\\)");
36 std::string
s3("\\(a\\([bc]\\)\\)");
37 std::string
s4("(a([bc]))");
39 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic
, 1);
40 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic
, 1);
41 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic
, 2);
42 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic
, 0);
44 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended
, 0);
45 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended
, 0);
46 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended
, 0);
47 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended
, 2);
49 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript
, 0);
50 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript
, 0);
51 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript
, 0);
52 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript
, 2);
54 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk
, 0);
55 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk
, 0);
56 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk
, 0);
57 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk
, 2);
59 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep
, 1);
60 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep
, 1);
61 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep
, 2);
62 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep
, 0);
64 test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep
, 0);
65 test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep
, 0);
66 test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep
, 0);
67 test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep
, 2);