assign.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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& assign(const basic_regex& that);
  11. #include <regex>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. int main(int, char**)
  15. {
  16. std::regex r1("(a([bc]))");
  17. std::regex r2;
  18. r2.assign(r1);
  19. assert(r2.flags() == std::regex::ECMAScript);
  20. assert(r2.mark_count() == 2);
  21. assert(std::regex_search("ab", r2));
  22. #ifndef TEST_HAS_NO_EXCEPTIONS
  23. bool caught = false;
  24. try { r2.assign("(def", std::regex::extended); }
  25. catch(std::regex_error &) { caught = true; }
  26. assert(caught);
  27. assert(r2.flags() == std::regex::ECMAScript);
  28. assert(r2.mark_count() == 2);
  29. assert(std::regex_search("ab", r2));
  30. #endif
  31. return 0;
  32. }