1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 // <regex>
12 
13 // class regex_error
14 //     : public runtime_error
15 // {
16 // public:
17 //     explicit regex_error(regex_constants::error_type ecode);
18 //     regex_constants::error_type code() const;
19 // };
20 
21 #include <regex>
22 #include <cassert>
23 #include "test_macros.h"
24 
main()25 int main()
26 {
27     {
28         std::regex_error e(std::regex_constants::error_collate);
29         assert(e.code() == std::regex_constants::error_collate);
30         assert(e.what() == std::string("The expression contained an invalid collating element name."));
31     }
32     {
33         std::regex_error e(std::regex_constants::error_ctype);
34         assert(e.code() == std::regex_constants::error_ctype);
35         assert(e.what() == std::string("The expression contained an invalid character class name."));
36     }
37     {
38         std::regex_error e(std::regex_constants::error_escape);
39         assert(e.code() == std::regex_constants::error_escape);
40         assert(e.what() == std::string("The expression contained an invalid escaped character, or a "
41                "trailing escape."));
42     }
43     {
44         std::regex_error e(std::regex_constants::error_backref);
45         assert(e.code() == std::regex_constants::error_backref);
46         assert(e.what() == std::string("The expression contained an invalid back reference."));
47     }
48     {
49         std::regex_error e(std::regex_constants::error_brack);
50         assert(e.code() == std::regex_constants::error_brack);
51         assert(e.what() == std::string("The expression contained mismatched [ and ]."));
52     }
53     {
54         std::regex_error e(std::regex_constants::error_paren);
55         assert(e.code() == std::regex_constants::error_paren);
56         assert(e.what() == std::string("The expression contained mismatched ( and )."));
57     }
58     {
59         std::regex_error e(std::regex_constants::error_brace);
60         assert(e.code() == std::regex_constants::error_brace);
61         assert(e.what() == std::string("The expression contained mismatched { and }."));
62     }
63     {
64         std::regex_error e(std::regex_constants::error_badbrace);
65         assert(e.code() == std::regex_constants::error_badbrace);
66         assert(e.what() == std::string("The expression contained an invalid range in a {} expression."));
67     }
68     {
69         std::regex_error e(std::regex_constants::error_range);
70         assert(e.code() == std::regex_constants::error_range);
71         assert(e.what() == std::string("The expression contained an invalid character range, "
72                "such as [b-a] in most encodings."));
73     }
74     {
75         std::regex_error e(std::regex_constants::error_space);
76         assert(e.code() == std::regex_constants::error_space);
77         assert(e.what() == std::string("There was insufficient memory to convert the expression into "
78                "a finite state machine."));
79     }
80     {
81         std::regex_error e(std::regex_constants::error_badrepeat);
82         assert(e.code() == std::regex_constants::error_badrepeat);
83         assert(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression."));
84     }
85     {
86         std::regex_error e(std::regex_constants::error_complexity);
87         assert(e.code() == std::regex_constants::error_complexity);
88         assert(e.what() == std::string("The complexity of an attempted match against a regular "
89                "expression exceeded a pre-set level."));
90     }
91     {
92         std::regex_error e(std::regex_constants::error_stack);
93         assert(e.code() == std::regex_constants::error_stack);
94         assert(e.what() == std::string("There was insufficient memory to determine whether the regular "
95                "expression could match the specified character sequence."));
96     }
97 }
98