blob: 02fecbda2d95b8e865c7518523a9731e05765e22 [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001// -*- C++ -*-
Howard Hinnant0ce02242010-09-28 17:19:10 +00002//===----------------------------------------------------------------------===//
Howard Hinnant3257c982010-06-17 00:34:59 +00003//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3257c982010-06-17 00:34:59 +00008//
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
24int main()
25{
26 {
27 std::regex_error e(std::regex_constants::error_collate);
28 assert(e.code() == std::regex_constants::error_collate);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000029 assert(e.what() == std::string("The expression contained an invalid collating element name."));
Howard Hinnant3257c982010-06-17 00:34:59 +000030 }
31 {
32 std::regex_error e(std::regex_constants::error_ctype);
33 assert(e.code() == std::regex_constants::error_ctype);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000034 assert(e.what() == std::string("The expression contained an invalid character class name."));
Howard Hinnant3257c982010-06-17 00:34:59 +000035 }
36 {
37 std::regex_error e(std::regex_constants::error_escape);
38 assert(e.code() == std::regex_constants::error_escape);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000039 assert(e.what() == std::string("The expression contained an invalid escaped character, or a "
40 "trailing escape."));
Howard Hinnant3257c982010-06-17 00:34:59 +000041 }
42 {
43 std::regex_error e(std::regex_constants::error_backref);
44 assert(e.code() == std::regex_constants::error_backref);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000045 assert(e.what() == std::string("The expression contained an invalid back reference."));
Howard Hinnant3257c982010-06-17 00:34:59 +000046 }
47 {
48 std::regex_error e(std::regex_constants::error_brack);
49 assert(e.code() == std::regex_constants::error_brack);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000050 assert(e.what() == std::string("The expression contained mismatched [ and ]."));
Howard Hinnant3257c982010-06-17 00:34:59 +000051 }
52 {
53 std::regex_error e(std::regex_constants::error_paren);
54 assert(e.code() == std::regex_constants::error_paren);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000055 assert(e.what() == std::string("The expression contained mismatched ( and )."));
Howard Hinnant3257c982010-06-17 00:34:59 +000056 }
57 {
58 std::regex_error e(std::regex_constants::error_brace);
59 assert(e.code() == std::regex_constants::error_brace);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000060 assert(e.what() == std::string("The expression contained mismatched { and }."));
Howard Hinnant3257c982010-06-17 00:34:59 +000061 }
62 {
63 std::regex_error e(std::regex_constants::error_badbrace);
64 assert(e.code() == std::regex_constants::error_badbrace);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000065 assert(e.what() == std::string("The expression contained an invalid range in a {} expression."));
Howard Hinnant3257c982010-06-17 00:34:59 +000066 }
67 {
68 std::regex_error e(std::regex_constants::error_range);
69 assert(e.code() == std::regex_constants::error_range);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000070 assert(e.what() == std::string("The expression contained an invalid character range, "
71 "such as [b-a] in most encodings."));
Howard Hinnant3257c982010-06-17 00:34:59 +000072 }
73 {
74 std::regex_error e(std::regex_constants::error_space);
75 assert(e.code() == std::regex_constants::error_space);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000076 assert(e.what() == std::string("There was insufficient memory to convert the expression into "
77 "a finite state machine."));
Howard Hinnant3257c982010-06-17 00:34:59 +000078 }
79 {
80 std::regex_error e(std::regex_constants::error_badrepeat);
81 assert(e.code() == std::regex_constants::error_badrepeat);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000082 assert(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression."));
Howard Hinnant3257c982010-06-17 00:34:59 +000083 }
84 {
85 std::regex_error e(std::regex_constants::error_complexity);
86 assert(e.code() == std::regex_constants::error_complexity);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000087 assert(e.what() == std::string("The complexity of an attempted match against a regular "
88 "expression exceeded a pre-set level."));
Howard Hinnant3257c982010-06-17 00:34:59 +000089 }
90 {
91 std::regex_error e(std::regex_constants::error_stack);
92 assert(e.code() == std::regex_constants::error_stack);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +000093 assert(e.what() == std::string("There was insufficient memory to determine whether the regular "
94 "expression could match the specified character sequence."));
Howard Hinnant3257c982010-06-17 00:34:59 +000095 }
96}