Marshall Clow | edd5e29 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <regex> |
| 11 | // UNSUPPORTED: c++98, c++03, c++11, c++14 |
| 12 | // UNSUPPORTED: libcpp-no-deduction-guides |
| 13 | |
| 14 | |
| 15 | // template<class ForwardIterator> |
| 16 | // basic_regex(ForwardIterator, ForwardIterator, |
| 17 | // regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 18 | // -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; |
Stephan T. Lavavej | cb0d205 | 2018-06-14 00:12:20 +0000 | [diff] [blame^] | 19 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 20 | |
| 21 | #include <regex> |
| 22 | #include <string> |
| 23 | #include <iterator> |
| 24 | #include <cassert> |
| 25 | #include <cstddef> |
| 26 | |
| 27 | #include "test_macros.h" |
| 28 | #include "test_iterators.h" |
| 29 | #include "test_allocator.h" |
| 30 | |
| 31 | using namespace std::literals; |
| 32 | |
| 33 | struct A {}; |
| 34 | |
| 35 | int main() |
| 36 | { |
Stephan T. Lavavej | cb0d205 | 2018-06-14 00:12:20 +0000 | [diff] [blame^] | 37 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 38 | // Test the explicit deduction guides |
| 39 | { |
| 40 | // basic_regex(ForwardIterator, ForwardIterator) |
| 41 | std::string s1("\\(a\\)"); |
| 42 | std::basic_regex re(s1.begin(), s1.end()); |
| 43 | |
| 44 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); |
| 45 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 46 | assert(re.mark_count() == 0); |
| 47 | } |
| 48 | |
| 49 | { |
| 50 | std::wstring s1(L"\\(a\\)"); |
| 51 | std::basic_regex re(s1.begin(), s1.end(), std::regex_constants::basic); |
| 52 | |
| 53 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); |
| 54 | assert(re.flags() == std::regex_constants::basic); |
| 55 | assert(re.mark_count() == 1); |
| 56 | } |
Stephan T. Lavavej | cb0d205 | 2018-06-14 00:12:20 +0000 | [diff] [blame^] | 57 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 58 | // Test the implicit deduction guides |
| 59 | { |
| 60 | // basic_regex(string); |
| 61 | std::basic_regex re("(a([bc]))"s); |
| 62 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); |
| 63 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 64 | assert(re.mark_count() == 2); |
| 65 | } |
| 66 | |
| 67 | { |
| 68 | // basic_regex(string, flag_type); |
| 69 | std::basic_regex re(L"(a([bc]))"s, std::regex_constants::awk); |
| 70 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); |
| 71 | assert(re.flags() == std::regex_constants::awk); |
| 72 | assert(re.mark_count() == 2); |
| 73 | } |
| 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 | { |
| 84 | // basic_regex(const charT*, flag_type); |
| 85 | std::basic_regex re(L"ABCDE", std::regex_constants::grep); |
| 86 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); |
| 87 | assert(re.flags() == std::regex_constants::grep); |
| 88 | assert(re.mark_count() == 0); |
| 89 | } |
Stephan T. Lavavej | cb0d205 | 2018-06-14 00:12:20 +0000 | [diff] [blame^] | 90 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 91 | { |
| 92 | // basic_regex(const charT*, size_t); |
| 93 | std::basic_regex re("ABCDEDEF", 7); |
| 94 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); |
| 95 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 96 | assert(re.mark_count() == 0); |
| 97 | } |
| 98 | |
| 99 | { |
| 100 | // basic_regex(const charT*, size_t, flag_type); |
| 101 | std::basic_regex re(L"ABCDEDEF", 8, std::regex_constants::awk); |
| 102 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); |
| 103 | assert(re.flags() == std::regex_constants::awk); |
| 104 | assert(re.mark_count() == 0); |
| 105 | } |
| 106 | |
| 107 | { |
| 108 | // basic_regex(const basic_regex &); |
| 109 | std::basic_regex<char> source; |
| 110 | std::basic_regex re(source); |
| 111 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); |
| 112 | assert(re.flags() == source.flags()); |
| 113 | assert(re.mark_count() == source.mark_count()); |
| 114 | } |
| 115 | |
| 116 | { |
| 117 | // template<class ST, class SA> |
| 118 | // explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 119 | // flag_type f = regex_constants::ECMAScript); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | // basic_regex(initializer_list); |
| 124 | std::basic_regex re({'A', 'B', 'F', 'E', 'D'}); |
| 125 | static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); |
| 126 | assert(re.flags() == std::regex_constants::ECMAScript); |
| 127 | assert(re.mark_count() == 0); |
| 128 | } |
| 129 | |
| 130 | { |
| 131 | // basic_regex(initializer_list, flag_type); |
| 132 | std::basic_regex re({L'A', L'B', L'F', L'E', L'D'}, std::regex_constants::grep); |
| 133 | static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); |
| 134 | assert(re.flags() == std::regex_constants::grep); |
| 135 | assert(re.mark_count() == 0); |
| 136 | } |
| 137 | } |