| 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 | // UNSUPPORTED: c++03, c++11, c++14 |
| 11 | |
| 12 | // template<class ForwardIterator> |
| 13 | // basic_regex(ForwardIterator, ForwardIterator, |
| 14 | // regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 15 | // -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; |
| 16 | |
| 17 | #include <regex> |
| 18 | #include <string> |
| 19 | #include <iterator> |
| 20 | #include <cassert> |
| 21 | #include <cstddef> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | #include "test_iterators.h" |
| 25 | #include "test_allocator.h" |
| 26 | |
| 27 | using namespace std::literals; |
| 28 | |
| 29 | struct A {}; |
| 30 | |
| 31 | int main(int, char**) |
| 32 | { |
| 33 | |
| 34 | // Test the explicit deduction guides |
| 35 | { |
| 36 | // basic_regex(ForwardIterator, ForwardIterator) |
| 37 | std::string s1("\\(a\\)" ); |
| 38 | std::basic_regex re(s1.begin(), s1.end()); |
| 39 | |
| 40 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 41 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 42 | assert(re.mark_count() == 0); |
| 43 | } |
| 44 | |
| 45 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 46 | { |
| 47 | std::wstring s1(L"\\(a\\)" ); |
| 48 | std::basic_regex re(s1.begin(), s1.end(), std::regex_constants::basic); |
| 49 | |
| 50 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "" ); |
| 51 | assert(re.flags() == std::regex_constants::basic); |
| 52 | assert(re.mark_count() == 1); |
| 53 | } |
| 54 | #endif |
| 55 | |
| 56 | // Test the implicit deduction guides |
| 57 | { |
| 58 | // basic_regex(string); |
| 59 | std::basic_regex re("(a([bc]))"s ); |
| 60 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 61 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 62 | assert(re.mark_count() == 2); |
| 63 | } |
| 64 | |
| 65 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 66 | { |
| 67 | // basic_regex(string, flag_type); |
| 68 | std::basic_regex re(L"(a([bc]))"s , std::regex_constants::awk); |
| 69 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "" ); |
| 70 | assert(re.flags() == std::regex_constants::awk); |
| 71 | assert(re.mark_count() == 2); |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | { |
| 76 | // basic_regex(const charT*); |
| 77 | std::basic_regex re("ABCDE" ); |
| 78 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 79 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 80 | assert(re.mark_count() == 0); |
| 81 | } |
| 82 | |
| 83 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 84 | { |
| 85 | // basic_regex(const charT*, flag_type); |
| 86 | std::basic_regex re(L"ABCDE" , std::regex_constants::grep); |
| 87 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "" ); |
| 88 | assert(re.flags() == std::regex_constants::grep); |
| 89 | assert(re.mark_count() == 0); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | { |
| 94 | // basic_regex(const charT*, size_t); |
| 95 | std::basic_regex re("ABCDEDEF" , 7); |
| 96 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 97 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 98 | assert(re.mark_count() == 0); |
| 99 | } |
| 100 | |
| 101 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 102 | { |
| 103 | // basic_regex(const charT*, size_t, flag_type); |
| 104 | std::basic_regex re(L"ABCDEDEF" , 8, std::regex_constants::awk); |
| 105 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "" ); |
| 106 | assert(re.flags() == std::regex_constants::awk); |
| 107 | assert(re.mark_count() == 0); |
| 108 | } |
| 109 | #endif |
| 110 | |
| 111 | { |
| 112 | // basic_regex(const basic_regex &); |
| 113 | std::basic_regex<char> source; |
| 114 | std::basic_regex re(source); |
| 115 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 116 | assert(re.flags() == source.flags()); |
| 117 | assert(re.mark_count() == source.mark_count()); |
| 118 | } |
| 119 | |
| 120 | { |
| 121 | // template<class ST, class SA> |
| 122 | // explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 123 | // flag_type f = regex_constants::ECMAScript); |
| 124 | } |
| 125 | |
| 126 | { |
| 127 | // basic_regex(initializer_list); |
| 128 | std::basic_regex re({'A', 'B', 'F', 'E', 'D'}); |
| 129 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, "" ); |
| 130 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 131 | assert(re.mark_count() == 0); |
| 132 | } |
| 133 | |
| 134 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 135 | { |
| 136 | // basic_regex(initializer_list, flag_type); |
| 137 | std::basic_regex re({L'A', L'B', L'F', L'E', L'D'}, std::regex_constants::grep); |
| 138 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, "" ); |
| 139 | assert(re.flags() == std::regex_constants::grep); |
| 140 | assert(re.mark_count() == 0); |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |