]>
Commit | Line | Data |
---|---|---|
95c7d828 TS |
1 | // { dg-options "-std=gnu++11" } |
2 | ||
3 | // | |
4 | // 2013-07-29 Tim Shen <timshen91@gmail.com> | |
5 | // | |
6 | // Copyright (C) 2013 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. | |
13 | // | |
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. | |
18 | // | |
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/>. | |
22 | ||
23 | // 28.11.2 regex_match | |
24 | // Tests Extended automatic matcher dispatching against a std::string target. | |
25 | ||
26 | #include <regex> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | using namespace std; | |
30 | ||
31 | template<typename _Bi_iter, typename _Alloc, | |
32 | typename _Ch_type, typename _Rx_traits> | |
33 | void | |
34 | fake_match(_Bi_iter __s, | |
35 | _Bi_iter __e, | |
36 | match_results<_Bi_iter, _Alloc>& __m, | |
37 | const basic_regex<_Ch_type, _Rx_traits>& __re, | |
38 | regex_constants::match_flag_type __flags | |
39 | = regex_constants::match_default) | |
40 | { | |
c2669da9 | 41 | auto& __res = (vector<sub_match<_Bi_iter>, _Alloc>&)(__m); |
6cb784b6 TS |
42 | VERIFY( (dynamic_cast |
43 | <__detail::_DFSExecutor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits>*> | |
c2669da9 | 44 | (&*__detail::__get_executor(__s, __e, __res, __re, __flags)) |
6cb784b6 | 45 | != nullptr) ); |
95c7d828 TS |
46 | } |
47 | ||
48 | void | |
49 | test01() | |
50 | { | |
51 | bool test __attribute__((unused)) = true; | |
52 | ||
53 | regex re("()(one(.*))abc\\1"); // backref cause DFS | |
54 | const string target("onetwoabc"); | |
55 | smatch m; | |
56 | fake_match(target.begin(), target.end(), m, re); | |
57 | ||
58 | regex_match(target, m, re); | |
59 | VERIFY( m[2].matched ); | |
60 | VERIFY( m[3].matched ); | |
61 | VERIFY( std::string(m[2].first, m[2].second) == "onetwo" ); | |
62 | VERIFY( std::string(m[3].first, m[3].second) == "two" ); | |
63 | } | |
64 | ||
65 | int | |
66 | main() | |
67 | { | |
68 | test01(); | |
69 | return 0; | |
70 | } |