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_match(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// XFAIL: target={{.*}}-amazon-linux{{.*}}
27
28#include <regex>
29#include <cassert>
30#include "test_macros.h"
31#include "test_iterators.h"
32
33#include "platform_support.h" // locale name macros
34
35int main(int, char**)
36{
37 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
38 {
39 std::cmatch m;
40 const char s[] = "m";
41 assert(std::regex_match(s, m, std::regex("[a[=M=]z]",
42 std::regex_constants::basic)));
43 assert(m.size() == 1);
44 assert(!m.prefix().matched);
45 assert(m.prefix().first == s);
46 assert(m.prefix().second == m[0].first);
47 assert(!m.suffix().matched);
48 assert(m.suffix().first == m[0].second);
49 assert(m.suffix().second == m[0].second);
50 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
51 assert(m.position(0) == 0);
52 assert(m.str(0) == s);
53 }
54 {
55 std::cmatch m;
56 const char s[] = "Ch";
57 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
58 std::regex_constants::basic | std::regex_constants::icase)));
59 assert(m.size() == 1);
60 assert(!m.prefix().matched);
61 assert(m.prefix().first == s);
62 assert(m.prefix().second == m[0].first);
63 assert(!m.suffix().matched);
64 assert(m.suffix().first == m[0].second);
65 assert(m.suffix().second == m[0].second);
66 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
67 assert(m.position(0) == 0);
68 assert(m.str(0) == s);
69 }
70 std::locale::global(loc: std::locale("C"));
71 {
72 std::cmatch m;
73 const char s[] = "m";
74 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]",
75 std::regex_constants::basic)));
76 assert(m.size() == 0);
77 }
78
79#ifndef TEST_HAS_NO_WIDE_CHARACTERS
80 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
81 {
82 std::wcmatch m;
83 const wchar_t s[] = L"m";
84 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
85 std::regex_constants::basic)));
86 assert(m.size() == 1);
87 assert(!m.prefix().matched);
88 assert(m.prefix().first == s);
89 assert(m.prefix().second == m[0].first);
90 assert(!m.suffix().matched);
91 assert(m.suffix().first == m[0].second);
92 assert(m.suffix().second == m[0].second);
93 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
94 assert(m.position(0) == 0);
95 assert(m.str(0) == s);
96 }
97 {
98 std::wcmatch m;
99 const wchar_t s[] = L"Ch";
100 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
101 std::regex_constants::basic | std::regex_constants::icase)));
102 assert(m.size() == 1);
103 assert(!m.prefix().matched);
104 assert(m.prefix().first == s);
105 assert(m.prefix().second == m[0].first);
106 assert(!m.suffix().matched);
107 assert(m.suffix().first == m[0].second);
108 assert(m.suffix().second == m[0].second);
109 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
110 assert(m.position(0) == 0);
111 assert(m.str(0) == s);
112 }
113 std::locale::global(loc: std::locale("C"));
114 {
115 std::wcmatch m;
116 const wchar_t s[] = L"m";
117 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]",
118 std::regex_constants::basic)));
119 assert(m.size() == 0);
120 }
121#endif // TEST_HAS_NO_WIDE_CHARACTERS
122
123 return 0;
124}
125

source code of libcxx/test/std/re/re.alg/re.alg.match/basic.locale.pass.cpp