]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/28_regex/algorithms/regex_match/cstring_bracket_01.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 28_regex / algorithms / regex_match / cstring_bracket_01.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
399eeef9
TS
2
3//
4// 2013-08-01 Tim Shen <timshen91@gmail.com>
5//
cbe34bb5 6// Copyright (C) 2013-2017 Free Software Foundation, Inc.
399eeef9
TS
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 3, or (at your option)
12// any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
22
23// 28.11.2 regex_match
24// Tests Extended bracket expression against a C-string.
25
26#include <regex>
27#include <testsuite_hooks.h>
6cb43087
TS
28#include <testsuite_regex.h>
29
30using namespace __gnu_test;
31using namespace std;
399eeef9
TS
32
33void
34test01()
35{
399eeef9
TS
36 {
37 std::regex re("pre/[za-x]", std::regex::extended);
6cb43087
TS
38 VERIFY( regex_match_debug("pre/z", re) );
39 VERIFY( regex_match_debug("pre/a", re) );
40 VERIFY( !regex_match_debug("pre/y", re) );
399eeef9
TS
41 }
42 {
43 std::regex re("pre/[[:uPPer:]]", std::regex::extended);
6cb43087
TS
44 VERIFY( regex_match_debug("pre/Z", re) );
45 VERIFY( !regex_match_debug("pre/_", re) );
46 VERIFY( !regex_match_debug("pre/a", re) );
47 VERIFY( !regex_match_debug("pre/0", re) );
399eeef9
TS
48 }
49 {
50 std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase);
6cb43087
TS
51 VERIFY( regex_match_debug("pre/Z", re) );
52 VERIFY( regex_match_debug("pre/a", re) );
399eeef9
TS
53 }
54 {
55 std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended);
6cb43087
TS
56 VERIFY( regex_match_debug("pre/~", re) );
57 VERIFY( regex_match_debug("pre/_", re) );
58 VERIFY( regex_match_debug("pre/a", re) );
59 VERIFY( regex_match_debug("pre/0", re) );
399eeef9 60 }
756aa0c3
TS
61 {
62 std::regex re("pre/[[=a=]]", std::regex::extended);
6cb43087
TS
63 VERIFY( regex_match_debug("pre/a", re) );
64 VERIFY( regex_match_debug("pre/A", re) );
756aa0c3 65 }
399eeef9
TS
66}
67
79b576cc
TS
68void
69test02()
70{
79b576cc
TS
71 try
72 {
73 std::regex re("[-----]", std::regex::extended);
74 VERIFY(false);
75 }
76 catch (const std::regex_error& e)
77 {
78 VERIFY(e.code() == std::regex_constants::error_range);
79 }
80 std::regex re("[-----]", std::regex::ECMAScript);
f9ce3c16
TS
81
82 VERIFY(!regex_match("b", regex("[-ac]", regex_constants::extended)));
83 VERIFY(!regex_match("b", regex("[ac-]", regex_constants::extended)));
84 VERIFY(regex_match("b", regex("[^-ac]", regex_constants::extended)));
85 VERIFY(regex_match("b", regex("[^ac-]", regex_constants::extended)));
86 VERIFY(regex_match("&", regex("[%--]", regex_constants::extended)));
87 VERIFY(regex_match(".", regex("[--@]", regex_constants::extended)));
88 try
89 {
90 regex("[a--@]", regex_constants::extended);
91 VERIFY(false);
92 }
93 catch (const std::regex_error& e)
94 {
95 }
96 VERIFY(regex_match("].", regex("[][.hyphen.]-0]*", regex_constants::extended)));
79b576cc
TS
97}
98
99void
100test03()
101{
79b576cc
TS
102 try
103 {
104 std::regex re("[z-a]", std::regex::extended);
105 VERIFY(false);
106 }
107 catch (const std::regex_error& e)
108 {
109 VERIFY(e.code() == std::regex_constants::error_range);
110 }
111}
112
113void
114test04()
115{
79b576cc
TS
116 std::regex re("[-0-9a-z]");
117 VERIFY(regex_match_debug("-", re));
118 VERIFY(regex_match_debug("1", re));
119 VERIFY(regex_match_debug("w", re));
120 re.assign("[-0-9a-z]", regex_constants::basic);
121 VERIFY(regex_match_debug("-", re));
122 VERIFY(regex_match_debug("1", re));
123 VERIFY(regex_match_debug("w", re));
124}
125
f9ce3c16
TS
126// libstdc++/67015
127void
128test05()
129{
f9ce3c16
TS
130 regex lanana_namespace("^[a-z0-9]+$", regex::extended);
131 regex lsb_namespace("^_?([a-z0-9_.]+-, regex::extended)+[a-z0-9]+$");
132 regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp, regex::extended)$");
133 regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$", regex::extended);
134 VERIFY(regex_match("test", debian_cron_namespace));
135 VERIFY(!regex_match("-a", debian_cron_namespace));
136 VERIFY(regex_match("a-", debian_cron_namespace));
137 regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$", regex::extended);
138 VERIFY(regex_match("test", debian_cron_namespace_ok));
139 VERIFY(!regex_match("-a", debian_cron_namespace_ok));
140 VERIFY(regex_match("a-", debian_cron_namespace_ok));
141}
142
143// libstdc++/67015
144void
145test06()
146{
f9ce3c16
TS
147 regex lanana_namespace("^[a-z0-9]+$");
148 regex lsb_namespace("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
149 regex debian_dpkg_conffile_cruft("dpkg-(old|dist|new|tmp)$");
150 regex debian_cron_namespace("^[a-z0-9][a-z0-9-]*$");
151 VERIFY(regex_match("test", debian_cron_namespace));
152 VERIFY(!regex_match("-a", debian_cron_namespace));
153 VERIFY(regex_match("a-", debian_cron_namespace));
154 regex debian_cron_namespace_ok("^[a-z0-9][-a-z0-9]*$");
155 VERIFY(regex_match("test", debian_cron_namespace_ok));
156 VERIFY(!regex_match("-a", debian_cron_namespace_ok));
157 VERIFY(regex_match("a-", debian_cron_namespace_ok));
158}
159
399eeef9
TS
160int
161main()
162{
163 test01();
79b576cc
TS
164 test02();
165 test03();
166 test04();
f9ce3c16
TS
167 test05();
168 test06();
169
399eeef9
TS
170 return 0;
171}