xref: /llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/iter_iter_flg.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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 
95a83710eSEric Fiselier // <regex>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template <class charT, class traits = regex_traits<charT>> class basic_regex;
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template <class ForwardIterator>
145a83710eSEric Fiselier //    basic_regex(ForwardIterator first, ForwardIterator last,
155a83710eSEric Fiselier //                flag_type f = regex_constants::ECMAScript);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <regex>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier 
205a83710eSEric Fiselier #include "test_iterators.h"
21fd5ceb22SMarshall Clow #include "test_macros.h"
225a83710eSEric Fiselier 
235a83710eSEric Fiselier template <class Iter>
245a83710eSEric Fiselier void
test(Iter first,Iter last,std::regex_constants::syntax_option_type f,unsigned mc)255a83710eSEric Fiselier test(Iter first, Iter last, std::regex_constants::syntax_option_type f, unsigned mc)
265a83710eSEric Fiselier {
275a83710eSEric Fiselier     std::basic_regex<typename std::iterator_traits<Iter>::value_type> r(first, last, f);
285a83710eSEric Fiselier     assert(r.flags() == f);
295a83710eSEric Fiselier     assert(r.mark_count() == mc);
305a83710eSEric Fiselier }
315a83710eSEric Fiselier 
main(int,char **)32*2df59c50SJF Bastien int main(int, char**)
335a83710eSEric Fiselier {
345a83710eSEric Fiselier     typedef forward_iterator<std::string::const_iterator> F;
355a83710eSEric Fiselier     std::string s1("\\(a\\)");
365a83710eSEric Fiselier     std::string s2("\\(a[bc]\\)");
375a83710eSEric Fiselier     std::string s3("\\(a\\([bc]\\)\\)");
385a83710eSEric Fiselier     std::string s4("(a([bc]))");
395a83710eSEric Fiselier 
405a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::basic, 1);
415a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::basic, 1);
425a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::basic, 2);
435a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::basic, 0);
445a83710eSEric Fiselier 
455a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::extended, 0);
465a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::extended, 0);
475a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::extended, 0);
485a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::extended, 2);
495a83710eSEric Fiselier 
505a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::ECMAScript, 0);
515a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::ECMAScript, 0);
525a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::ECMAScript, 0);
535a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::ECMAScript, 2);
545a83710eSEric Fiselier 
555a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::awk, 0);
565a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::awk, 0);
575a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::awk, 0);
585a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::awk, 2);
595a83710eSEric Fiselier 
605a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::grep, 1);
615a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::grep, 1);
625a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::grep, 2);
635a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::grep, 0);
645a83710eSEric Fiselier 
655a83710eSEric Fiselier     test(F(s1.begin()), F(s1.end()), std::regex_constants::egrep, 0);
665a83710eSEric Fiselier     test(F(s2.begin()), F(s2.end()), std::regex_constants::egrep, 0);
675a83710eSEric Fiselier     test(F(s3.begin()), F(s3.end()), std::regex_constants::egrep, 0);
685a83710eSEric Fiselier     test(F(s4.begin()), F(s4.end()), std::regex_constants::egrep, 2);
69*2df59c50SJF Bastien 
70*2df59c50SJF Bastien   return 0;
715a83710eSEric Fiselier }
72