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