PR libstdc++/64239
[official-gcc.git] / libstdc++-v3 / testsuite / 28_regex / iterators / regex_iterator / char / string_position_01.cc
blob91aa06137f5b0a8dc71a7da4110a7036bc579298
1 // { dg-options "-std=gnu++11" }
3 //
4 // 2013-07-25 Tim Shen <timshen91@gmail.com>
5 //
6 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
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.
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.
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/>.
23 // 28.12.1 regex_iterator
24 // Tests iter->position() behavior
26 #include <regex>
27 #include <tuple>
28 #include <testsuite_hooks.h>
30 void
31 test01()
33 bool test __attribute__((unused)) = true;
35 std::regex re("asdf");
36 std::string s("asdfasdfasdf");
37 int i = 0;
38 for (std::sregex_iterator it(s.begin(), s.end(), re);
39 it != std::sregex_iterator();
40 ++it, i++) {
41 VERIFY( it->position() == 4 * i );
45 // PR libstdc++/64239
46 void
47 test02()
49 bool test __attribute__((unused)) = true;
51 std::regex re("\\w+");
52 std::string s("-a-b-c-");
54 std::tuple<int, int, const char*> expected[] =
56 std::make_tuple(1, 1, "a"),
57 std::make_tuple(3, 1, "b"),
58 std::make_tuple(5, 1, "c"),
61 int i = 0;
62 for (auto it1 = std::sregex_iterator(s.begin(), s.end(), re),
63 end = std::sregex_iterator(); it1 != end; ++it1, i++)
65 auto it2 = it1;
66 VERIFY(it1->position() == std::get<0>(expected[i]));
67 VERIFY(it1->length() == std::get<1>(expected[i]));
68 VERIFY(it1->str() == std::get<2>(expected[i]));
69 VERIFY(it2->position() == std::get<0>(expected[i]));
70 VERIFY(it2->length() == std::get<1>(expected[i]));
71 VERIFY(it2->str() == std::get<2>(expected[i]));
75 void
76 test03()
78 bool test __attribute__((unused)) = true;
80 std::smatch m;
81 std::string s = "abcde";
82 std::regex_search(s, m, std::regex("bcd"));
83 VERIFY(m.position() == 1);
84 VERIFY(m.position() == m.prefix().length());
87 int
88 main()
90 test01();
91 test02();
92 test03();
93 return 0;