xref: /llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/il_flg.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03
109f7cc58fSEric Fiselier 
115a83710eSEric Fiselier // <regex>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template <class charT, class traits = regex_traits<charT>> class basic_regex;
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // basic_regex(initializer_list<charT> il,
165a83710eSEric Fiselier //             flag_type f = regex_constants::ECMAScript);
175a83710eSEric Fiselier 
185a83710eSEric Fiselier #include <regex>
195a83710eSEric Fiselier #include <cassert>
20fd5ceb22SMarshall Clow #include "test_macros.h"
215a83710eSEric Fiselier 
225a83710eSEric Fiselier 
235a83710eSEric Fiselier void
test(std::initializer_list<char> il,std::regex_constants::syntax_option_type f,unsigned mc)245a83710eSEric Fiselier test(std::initializer_list<char> il, std::regex_constants::syntax_option_type f, unsigned mc)
255a83710eSEric Fiselier {
265a83710eSEric Fiselier     std::basic_regex<char> r(il, f);
275a83710eSEric Fiselier     assert(r.flags() == f);
285a83710eSEric Fiselier     assert(r.mark_count() == mc);
295a83710eSEric Fiselier }
305a83710eSEric Fiselier 
315a83710eSEric Fiselier 
main(int,char **)322df59c50SJF Bastien int main(int, char**)
335a83710eSEric Fiselier {
345a83710eSEric Fiselier     std::string s1("\\(a\\)");
355a83710eSEric Fiselier     std::string s2("\\(a[bc]\\)");
365a83710eSEric Fiselier     std::string s3("\\(a\\([bc]\\)\\)");
375a83710eSEric Fiselier     std::string s4("(a([bc]))");
385a83710eSEric Fiselier 
395a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1);
405a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1);
415a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2);
425a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0);
435a83710eSEric Fiselier 
445a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0);
455a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0);
465a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0);
475a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2);
485a83710eSEric Fiselier 
495a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0);
505a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0);
515a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0);
525a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2);
535a83710eSEric Fiselier 
545a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0);
555a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0);
565a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0);
575a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2);
585a83710eSEric Fiselier 
595a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1);
605a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1);
615a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2);
625a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0);
635a83710eSEric Fiselier 
645a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0);
655a83710eSEric Fiselier     test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0);
665a83710eSEric Fiselier     test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0);
675a83710eSEric Fiselier     test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2);
682df59c50SJF Bastien 
692df59c50SJF Bastien   return 0;
705a83710eSEric Fiselier }
71