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