]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/regression.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 28_regex / regression.cc
1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
3
4 //
5 // Copyright (C) 2015-2023 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 #include <testsuite_hooks.h>
23 #include <testsuite_regex.h>
24
25 using namespace __gnu_test;
26 using namespace std;
27
28 // PR libstdc++/67362
29 void
30 test01()
31 {
32 regex re("((.)", regex_constants::basic);
33 }
34
35 void
36 test02()
37 {
38 std::string re_str
39 {
40 "/abcd" "\n"
41 "/aecf" "\n"
42 "/ghci"
43 };
44 auto rx = std::regex(re_str, std::regex_constants::grep | std::regex_constants::icase);
45 VERIFY(regex_search_debug("/abcd", rx));
46 }
47
48 void
49 test03()
50 {
51 VERIFY(regex_match_debug("a.", regex(R"(a\b.)"), regex_constants::match_not_eow));
52 VERIFY(regex_match_debug(".a", regex(R"(.\ba)"), regex_constants::match_not_bow));
53 VERIFY(regex_search_debug("a", regex(R"(^\b)")));
54 VERIFY(regex_search_debug("a", regex(R"(\b$)")));
55 VERIFY(!regex_search_debug("a", regex(R"(^\b)"), regex_constants::match_not_bow));
56 VERIFY(!regex_search_debug("a", regex(R"(\b$)"), regex_constants::match_not_eow));
57 }
58
59 // PR libstdc++/77356
60 void
61 test04()
62 {
63 static const char* kNumericAnchor ="(\\$|usd)(usd|\\$|to|and|up to|[0-9,\\.\\-\\sk])+";
64 const std::regex re(kNumericAnchor);
65 (void)re;
66 }
67
68 void
69 test05()
70 {
71 VERIFY(regex_match_debug("!", std::regex("[![:alnum:]]")));
72 VERIFY(regex_match_debug("-", std::regex("[a-]", regex_constants::basic)));
73 VERIFY(regex_match_debug("-", std::regex("[a-]")));
74 }
75
76 // PR libstdc++/78236
77 void
78 test06()
79 {
80 char const s[] = "afoo";
81 std::basic_regex<char> r("(f+)");
82 {
83 std::cregex_iterator i(s, s+sizeof(s), r);
84 std::cregex_iterator j(s, s+sizeof(s), r);
85 VERIFY(i == j);
86 }
87 // The iterator manipulation code must be repeated in the same scope
88 // to expose the undefined read during the execution of the ==
89 // operator (stack location reuse)
90 {
91 std::cregex_iterator i(s, s+sizeof(s), r);
92 std::cregex_iterator j;
93 VERIFY(!(i == j));
94 }
95 }
96
97 // PR libstdc++/71500
98 void
99 test07()
100 {
101 bool test [[gnu::unused]] = true;
102
103 VERIFY(regex_match_debug("abc abc", regex("([a-z]+) \\1", regex::icase)));
104 VERIFY(regex_match_debug("Abc abc", regex("([a-z]+) \\1", regex::icase)));
105 VERIFY(regex_match_debug("abc Abc", regex("([a-z]+) \\1", regex::icase)));
106 }
107
108 int
109 main()
110 {
111 test01();
112 test02();
113 test03();
114 test04();
115 test05();
116 test06();
117 test07();
118 return 0;
119 }
120