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 // NetBSD does not support LC_COLLATE at the moment
10 // XFAIL: netbsd
11 // XFAIL: LIBCXX-AIX-FIXME
12
13 // REQUIRES: locale.cs_CZ.ISO8859-2
14
15 // <regex>
16
17 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
18 // bool
19 // regex_search(BidirectionalIterator first, BidirectionalIterator last,
20 // match_results<BidirectionalIterator, Allocator>& m,
21 // const basic_regex<charT, traits>& e,
22 // regex_constants::match_flag_type flags = regex_constants::match_default);
23
24 // TODO: investigation needed
25 // XFAIL: target={{.*}}-linux-gnu{{.*}}, freebsd
26
27 #include <regex>
28 #include <cassert>
29 #include "test_macros.h"
30 #include "test_iterators.h"
31
32 #include "platform_support.h" // locale name macros
33
main(int,char **)34 int main(int, char**)
35 {
36 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
37 {
38 std::cmatch m;
39 const char s[] = "m";
40 assert(std::regex_search(s, m, std::regex("[a[=M=]z]")));
41 assert(m.size() == 1);
42 assert(!m.prefix().matched);
43 assert(m.prefix().first == s);
44 assert(m.prefix().second == m[0].first);
45 assert(!m.suffix().matched);
46 assert(m.suffix().first == m[0].second);
47 assert(m.suffix().second == m[0].second);
48 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
49 assert(m.position(0) == 0);
50 assert(m.str(0) == s);
51 }
52 {
53 std::cmatch m;
54 const char s[] = "Ch";
55 assert(std::regex_search(s, m, std::regex("[a[.ch.]z]",
56 std::regex_constants::icase)));
57 assert(m.size() == 1);
58 assert(!m.prefix().matched);
59 assert(m.prefix().first == s);
60 assert(m.prefix().second == m[0].first);
61 assert(!m.suffix().matched);
62 assert(m.suffix().first == m[0].second);
63 assert(m.suffix().second == m[0].second);
64 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
65 assert(m.position(0) == 0);
66 assert(m.str(0) == s);
67 }
68 std::locale::global(std::locale("C"));
69 {
70 std::cmatch m;
71 const char s[] = "m";
72 assert(!std::regex_search(s, m, std::regex("[a[=M=]z]")));
73 assert(m.size() == 0);
74 }
75
76 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
77 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
78 {
79 std::wcmatch m;
80 const wchar_t s[] = L"m";
81 assert(std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
82 assert(m.size() == 1);
83 assert(!m.prefix().matched);
84 assert(m.prefix().first == s);
85 assert(m.prefix().second == m[0].first);
86 assert(!m.suffix().matched);
87 assert(m.suffix().first == m[0].second);
88 assert(m.suffix().second == m[0].second);
89 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
90 assert(m.position(0) == 0);
91 assert(m.str(0) == s);
92 }
93 {
94 std::wcmatch m;
95 const wchar_t s[] = L"Ch";
96 assert(std::regex_search(s, m, std::wregex(L"[a[.ch.]z]",
97 std::regex_constants::icase)));
98 assert(m.size() == 1);
99 assert(!m.prefix().matched);
100 assert(m.prefix().first == s);
101 assert(m.prefix().second == m[0].first);
102 assert(!m.suffix().matched);
103 assert(m.suffix().first == m[0].second);
104 assert(m.suffix().second == m[0].second);
105 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
106 assert(m.position(0) == 0);
107 assert(m.str(0) == s);
108 }
109 std::locale::global(std::locale("C"));
110 {
111 std::wcmatch m;
112 const wchar_t s[] = L"m";
113 assert(!std::regex_search(s, m, std::wregex(L"[a[=M=]z]")));
114 assert(m.size() == 0);
115 }
116 #endif // TEST_HAS_NO_WIDE_CHARACTERS
117
118 return 0;
119 }
120