string_flg.pass.cpp 2.6 KB

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