Merge branches/gcc-4_9-branch rev 225109.
[official-gcc.git] / gcc-4_9-branch / libstdc++-v3 / testsuite / 28_regex / algorithms / regex_match / cstring_bracket_01.cc
blobf7653c6dc9d67afae4d12191624e40b45c6c1ce2
1 // { dg-options "-std=gnu++11" }
3 //
4 // 2013-08-01 Tim Shen <timshen91@gmail.com>
5 //
6 // Copyright (C) 2013-2015 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.11.2 regex_match
24 // Tests Extended bracket expression against a C-string.
26 #include <regex>
27 #include <testsuite_hooks.h>
28 #include <testsuite_regex.h>
30 using namespace __gnu_test;
31 using namespace std;
33 void
34 test01()
36 bool test __attribute__((unused)) = true;
39 std::regex re("pre/[za-x]", std::regex::extended);
40 VERIFY( regex_match_debug("pre/z", re) );
41 VERIFY( regex_match_debug("pre/a", re) );
42 VERIFY( !regex_match_debug("pre/y", re) );
45 std::regex re("pre/[[:uPPer:]]", std::regex::extended);
46 VERIFY( regex_match_debug("pre/Z", re) );
47 VERIFY( !regex_match_debug("pre/_", re) );
48 VERIFY( !regex_match_debug("pre/a", re) );
49 VERIFY( !regex_match_debug("pre/0", re) );
52 std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase);
53 VERIFY( regex_match_debug("pre/Z", re) );
54 VERIFY( regex_match_debug("pre/a", re) );
57 std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended);
58 VERIFY( regex_match_debug("pre/~", re) );
59 VERIFY( regex_match_debug("pre/_", re) );
60 VERIFY( regex_match_debug("pre/a", re) );
61 VERIFY( regex_match_debug("pre/0", re) );
64 std::regex re("pre/[[=a=]]", std::regex::extended);
65 VERIFY( regex_match_debug("pre/a", re) );
66 VERIFY( regex_match_debug("pre/A", re) );
70 void
71 test02()
73 bool test __attribute__((unused)) = true;
75 try
77 std::regex re("[-----]", std::regex::extended);
78 VERIFY(false);
80 catch (const std::regex_error& e)
82 VERIFY(e.code() == std::regex_constants::error_range);
84 std::regex re("[-----]", std::regex::ECMAScript);
87 void
88 test03()
90 bool test __attribute__((unused)) = true;
92 try
94 std::regex re("[z-a]", std::regex::extended);
95 VERIFY(false);
97 catch (const std::regex_error& e)
99 VERIFY(e.code() == std::regex_constants::error_range);
103 void
104 test04()
106 bool test __attribute__((unused)) = true;
108 std::regex re("[-0-9a-z]");
109 VERIFY(regex_match_debug("-", re));
110 VERIFY(regex_match_debug("1", re));
111 VERIFY(regex_match_debug("w", re));
112 re.assign("[-0-9a-z]", regex_constants::basic);
113 VERIFY(regex_match_debug("-", re));
114 VERIFY(regex_match_debug("1", re));
115 VERIFY(regex_match_debug("w", re));
119 main()
121 test01();
122 test02();
123 test03();
124 test04();
125 return 0;