annotate libstdc++-v3/testsuite/28_regex/regression.cc @ 131:84e7813d76e9

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