ptr_size_flg.pass.cpp 2.3 KB

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