ptr_flg.pass.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // <regex>
  9. // template <class charT, class traits = regex_traits<charT>> class basic_regex;
  10. // basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
  11. #include <regex>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. template <class CharT>
  15. void
  16. test(const CharT* p, std::regex_constants::syntax_option_type f, unsigned mc)
  17. {
  18. std::basic_regex<CharT> r(p, f);
  19. assert(r.flags() == f);
  20. assert(r.mark_count() == mc);
  21. }
  22. int main(int, char**)
  23. {
  24. test("\\(a\\)", std::regex_constants::basic, 1);
  25. test("\\(a[bc]\\)", std::regex_constants::basic, 1);
  26. test("\\(a\\([bc]\\)\\)", std::regex_constants::basic, 2);
  27. test("(a([bc]))", std::regex_constants::basic, 0);
  28. test("\\(a\\)", std::regex_constants::extended, 0);
  29. test("\\(a[bc]\\)", std::regex_constants::extended, 0);
  30. test("\\(a\\([bc]\\)\\)", std::regex_constants::extended, 0);
  31. test("(a([bc]))", std::regex_constants::extended, 2);
  32. test("\\(a\\)", std::regex_constants::ECMAScript, 0);
  33. test("\\(a[bc]\\)", std::regex_constants::ECMAScript, 0);
  34. test("\\(a\\([bc]\\)\\)", std::regex_constants::ECMAScript, 0);
  35. test("(a([bc]))", std::regex_constants::ECMAScript, 2);
  36. test("\\(a\\)", std::regex_constants::awk, 0);
  37. test("\\(a[bc]\\)", std::regex_constants::awk, 0);
  38. test("\\(a\\([bc]\\)\\)", std::regex_constants::awk, 0);
  39. test("(a([bc]))", std::regex_constants::awk, 2);
  40. test("\\(a\\)", std::regex_constants::grep, 1);
  41. test("\\(a[bc]\\)", std::regex_constants::grep, 1);
  42. test("\\(a\\([bc]\\)\\)", std::regex_constants::grep, 2);
  43. test("(a([bc]))", std::regex_constants::grep, 0);
  44. test("\\(a\\)", std::regex_constants::egrep, 0);
  45. test("\\(a[bc]\\)", std::regex_constants::egrep, 0);
  46. test("\\(a\\([bc]\\)\\)", std::regex_constants::egrep, 0);
  47. test("(a([bc]))", std::regex_constants::egrep, 2);
  48. return 0;
  49. }