il_flg.pass.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03
  9. // <regex>
  10. // template <class charT, class traits = regex_traits<charT>> class basic_regex;
  11. // basic_regex(initializer_list<charT> il,
  12. // flag_type f = regex_constants::ECMAScript);
  13. #include <regex>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. void
  17. test(std::initializer_list<char> il, std::regex_constants::syntax_option_type f, unsigned mc)
  18. {
  19. std::basic_regex<char> r(il, f);
  20. assert(r.flags() == f);
  21. assert(r.mark_count() == mc);
  22. }
  23. int main(int, char**)
  24. {
  25. std::string s1("\\(a\\)");
  26. std::string s2("\\(a[bc]\\)");
  27. std::string s3("\\(a\\([bc]\\)\\)");
  28. std::string s4("(a([bc]))");
  29. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::basic, 1);
  30. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::basic, 1);
  31. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::basic, 2);
  32. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::basic, 0);
  33. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::extended, 0);
  34. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::extended, 0);
  35. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::extended, 0);
  36. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::extended, 2);
  37. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  38. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  39. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::ECMAScript, 0);
  40. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::ECMAScript, 2);
  41. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::awk, 0);
  42. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::awk, 0);
  43. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::awk, 0);
  44. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::awk, 2);
  45. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::grep, 1);
  46. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::grep, 1);
  47. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::grep, 2);
  48. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::grep, 0);
  49. test({'\\', '(', 'a', '\\', ')'}, std::regex_constants::egrep, 0);
  50. test({'\\', '(', 'a', '[', 'b', 'c', ']', '\\', ')'}, std::regex_constants::egrep, 0);
  51. test({'\\', '(', 'a', '\\', '(', '[', 'b', 'c', ']', '\\', ')', '\\', ')'}, std::regex_constants::egrep, 0);
  52. test({'(', 'a', '(', '[', 'b', 'c', ']', ')', ')'}, std::regex_constants::egrep, 2);
  53. return 0;
  54. }