Debian Codegraph @

libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc

raw
1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
3
4 //
5 // 2013-10-01 Tim Shen <[email protected]>
6 //
7 // Copyright (C) 2013-2025 Free Software Foundation, Inc.
8 //
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
13 // any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
23
24 // 28.11.2 regex_match
25
26 #include <regex>
27 #include <testsuite_hooks.h>
28 #include <testsuite_regex.h>
29
30 using namespace __gnu_test;
31 using namespace std;
32
33 // libstdc++/58576
34 void
35 test01()
36 {
37 string domain_name = "valid.hostname.org";
38 /**
39 * based on http://stackoverflow.com/questions/1418423/the-hostname-regex
40 */
41 regex fqdn_regex
42 (
43 "^"
44 "(?=.{1,255}$)"
45 "[[:alnum:]]"
46 "("
47 "(([[:alnum:]]|-)"
48 "{0,61})"
49 "[[:alnum:]]"
50 ")?"
51 "("
52 "\\."
53 "[[:alnum:]]"
54 "("
55 "(([[:alnum:]]|-)"
56 "{0,61})"
57 "[[:alnum:]]"
58 ")?"
59 ")*"
60 "\\.?"
61 "$"
62 );
63
64 smatch m;
65 const char* sol[] =
66 {
67 "valid.hostname.org",
68 "alid",
69 "ali",
70 "i",
71 ".org",
72 "rg",
73 "r",
74 "r",
75 };
76 try
77 {
78 VERIFY(regex_match_debug( domain_name, m, fqdn_regex ));
79 VERIFY(m.size() == sizeof(sol) / sizeof(*sol));
80 for (size_t i = 0; i < m.size(); i++) {
81 string s(m[i].first, m[i].second);
82 VERIFY(s == sol[i]);
83 }
84 }
85 catch ( const regex_error& ex )
86 {
87 if ( ex.code() == regex_constants::error_brack )
88 {
89 throw;
90 }
91 }
92 }
93
94 int
95 main()
96 {
97 test01();
98 return 0;
99 }