regex_error.pass.cpp 3.9 KB

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