]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/match_results/out_of_range_submatches.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 28_regex / match_results / out_of_range_submatches.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <regex>
21 #include <testsuite_hooks.h>
22 #include <testsuite_regex.h>
23
24 using namespace std;
25 using namespace __gnu_test;
26
27 // libstdc++/64441
28 void
29 test01()
30 {
31 const char s[] = "abc";
32 const std::regex re("(\\d+)|(\\w+)");
33
34 std::cmatch m;
35 VERIFY(regex_search_debug(s, m, re));
36
37 std::tuple<bool, string, int, int> expected[] = {
38 make_tuple(true, "abc", 0, 3),
39 make_tuple(false, "", 3, 3),
40 make_tuple(true, "abc", 0, 3),
41 make_tuple(false, "", 3, 3),
42 };
43 for (size_t i = 0, n = m.size(); i <= n; ++i) {
44 auto&& sub = m[i];
45 VERIFY(sub.matched == std::get<0>(expected[i]));
46 VERIFY(sub.str() == std::get<1>(expected[i]));
47 VERIFY((sub.first - s) == std::get<2>(expected[i]));
48 VERIFY((sub.second - s) == std::get<3>(expected[i]));
49 }
50 }
51
52 // libstdc++/64781
53 void
54 test02()
55 {
56 std::match_results<const char*> m;
57 const char s[] = "a";
58 VERIFY(regex_search_debug(s, m, std::regex("a")));
59
60 VERIFY(m.size() == 1);
61
62 VERIFY(m[0].first == s+0);
63 VERIFY(m[0].second == s+1);
64 VERIFY(m[0].matched == true);
65
66 VERIFY(m[42].first == s+1);
67 VERIFY(m[42].second == s+1);
68 VERIFY(m[42].matched == false);
69 }
70
71 int
72 main()
73 {
74 test01();
75 test02();
76 return 0;
77 }