grep.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 BidirectionalIterator, class Allocator, class charT, class traits>
  10. // bool
  11. // regex_match(BidirectionalIterator first, BidirectionalIterator last,
  12. // match_results<BidirectionalIterator, Allocator>& m,
  13. // const basic_regex<charT, traits>& e,
  14. // regex_constants::match_flag_type flags = regex_constants::match_default);
  15. #include <regex>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #include "test_iterators.h"
  19. int main(int, char**)
  20. {
  21. {
  22. std::cmatch m;
  23. const char s[] = "tournament";
  24. assert(std::regex_match(s, m, std::regex("tour\nto\ntournament",
  25. std::regex_constants::grep)));
  26. assert(m.size() == 1);
  27. assert(!m.prefix().matched);
  28. assert(m.prefix().first == s);
  29. assert(m.prefix().second == m[0].first);
  30. assert(!m.suffix().matched);
  31. assert(m.suffix().first == m[0].second);
  32. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  33. assert(m.length(0) == 10);
  34. assert(m.position(0) == 0);
  35. assert(m.str(0) == "tournament");
  36. }
  37. {
  38. std::cmatch m;
  39. const char s[] = "ment";
  40. assert(!std::regex_match(s, m, std::regex("tour\n\ntournament",
  41. std::regex_constants::grep)));
  42. assert(m.size() == 0);
  43. }
  44. return 0;
  45. }