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 assert(m.size() == 1);
43 assert(!m.prefix().matched);
44 assert(m.prefix().first == s);
45 assert(m.prefix().second == m[0].first);
46 assert(!m.suffix().matched);
47 assert(m.suffix().first == m[0].second);
48 assert(m.suffix().second == m[0].second);
49 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
50 assert(m.position(0) == 0);
51 assert(m.str(0) == s);
52 }
53 {
54 std::cmatch m;
55 const char s[] = "Ch";
56 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
57 std::regex_constants::icase)));
58 assert(m.size() == 1);
59 assert(!m.prefix().matched);
60 assert(m.prefix().first == s);
61 assert(m.prefix().second == m[0].first);
62 assert(!m.suffix().matched);
63 assert(m.suffix().first == m[0].second);
64 assert(m.suffix().second == m[0].second);
65 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<char>::length(s));
66 assert(m.position(0) == 0);
67 assert(m.str(0) == s);
68 }
69 std::locale::global(loc: std::locale("C"));
70 {
71 std::cmatch m;
72 const char s[] = "m";
73 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]")));
74 assert(m.size() == 0);
75 }
76
77#ifndef TEST_HAS_NO_WIDE_CHARACTERS
78 std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
79 {
80 std::wcmatch m;
81 const wchar_t s[] = L"m";
82 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]")));
83 assert(m.size() == 1);
84 assert(!m.prefix().matched);
85 assert(m.prefix().first == s);
86 assert(m.prefix().second == m[0].first);
87 assert(!m.suffix().matched);
88 assert(m.suffix().first == m[0].second);
89 assert(m.suffix().second == m[0].second);
90 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
91 assert(m.position(0) == 0);
92 assert(m.str(0) == s);
93 }
94 {
95 std::wcmatch m;
96 const wchar_t s[] = L"Ch";
97 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
98 std::regex_constants::icase)));
99 assert(m.size() == 1);
100 assert(!m.prefix().matched);
101 assert(m.prefix().first == s);
102 assert(m.prefix().second == m[0].first);
103 assert(!m.suffix().matched);
104 assert(m.suffix().first == m[0].second);
105 assert(m.suffix().second == m[0].second);
106 assert(m.length(0) >= 0 && static_cast<std::size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
107 assert(m.position(0) == 0);
108 assert(m.str(0) == s);
109 }
110 std::locale::global(loc: std::locale("C"));
111 {
112 std::wcmatch m;
113 const wchar_t s[] = L"m";
114 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]")));
115 assert(m.size() == 0);
116 }
117#endif // TEST_HAS_NO_WIDE_CHARACTERS
118
119 return 0;
120}
121

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