il_flg.pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <regex>
  11. // template <class charT, class traits = regex_traits<charT>> class basic_regex;
  12. // basic_regex(initializer_list<charT> il,
  13. // flag_type f = regex_constants::ECMAScript);
  14. #include <regex>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. void
  18. test(std::initializer_list<char> il, std::regex_constants::syntax_option_type f, unsigned mc)
  19. {
  20. std::basic_regex<char> r(il, f);
  21. assert(r.flags() == f);
  22. assert(r.mark_count() == mc);
  23. }
  24. int main()
  25. {
  26. std::string s1("\\(a\\)");
  27. std::string s2("\\(a[bc]\\)");
  28. std::string s3("\\(a\\([bc]\\)\\)");
  29. std::string s4("(a([bc]))");
  30. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1);
  31. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1);
  32. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2);
  33. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0);
  34. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0);
  35. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0);
  36. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0);
  37. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2);
  38. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  39. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  40. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  41. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2);
  42. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0);
  43. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0);
  44. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0);
  45. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2);
  46. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1);
  47. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1);
  48. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2);
  49. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0);
  50. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0);
  51. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0);
  52. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0);
  53. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2);
  54. }