| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <regex> |
| 10 | |
| 11 | // template <class charT, class traits = regex_traits<charT>> class basic_regex; |
| 12 | |
| 13 | // template <class ForwardIterator> |
| 14 | // basic_regex(ForwardIterator first, ForwardIterator last, |
| 15 | // flag_type f = regex_constants::ECMAScript); |
| 16 | |
| 17 | #include <regex> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_iterators.h" |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | template <class Iter> |
| 24 | void |
| 25 | test(Iter first, Iter last, std::regex_constants::syntax_option_type f, unsigned mc) |
| 26 | { |
| 27 | std::basic_regex<typename std::iterator_traits<Iter>::value_type> r(first, last, f); |
| 28 | assert(r.flags() == f); |
| 29 | assert(r.mark_count() == mc); |
| 30 | } |
| 31 | |
| 32 | int main(int, char**) |
| 33 | { |
| 34 | typedef forward_iterator<std::string::const_iterator> F; |
| 35 | 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(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::basic, mc: 1); |
| 41 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::basic, mc: 1); |
| 42 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::basic, mc: 2); |
| 43 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::basic, mc: 0); |
| 44 | |
| 45 | test(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::extended, mc: 0); |
| 46 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::extended, mc: 0); |
| 47 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::extended, mc: 0); |
| 48 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::extended, mc: 2); |
| 49 | |
| 50 | test(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::ECMAScript, mc: 0); |
| 51 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::ECMAScript, mc: 0); |
| 52 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::ECMAScript, mc: 0); |
| 53 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::ECMAScript, mc: 2); |
| 54 | |
| 55 | test(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::awk, mc: 0); |
| 56 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::awk, mc: 0); |
| 57 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::awk, mc: 0); |
| 58 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::awk, mc: 2); |
| 59 | |
| 60 | test(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::grep, mc: 1); |
| 61 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::grep, mc: 1); |
| 62 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::grep, mc: 2); |
| 63 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::grep, mc: 0); |
| 64 | |
| 65 | test(first: F(s1.begin()), last: F(s1.end()), f: std::regex_constants::egrep, mc: 0); |
| 66 | test(first: F(s2.begin()), last: F(s2.end()), f: std::regex_constants::egrep, mc: 0); |
| 67 | test(first: F(s3.begin()), last: F(s3.end()), f: std::regex_constants::egrep, mc: 0); |
| 68 | test(first: F(s4.begin()), last: F(s4.end()), f: std::regex_constants::egrep, mc: 2); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |