inverted_character_classes.pass.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // UNSUPPORTED: c++98, c++03
  10. // Make sure that we correctly match inverted character classes.
  11. #include <cassert>
  12. #include <regex>
  13. #include "test_macros.h"
  14. int main(int, char**) {
  15. assert(std::regex_match("X", std::regex("[X]")));
  16. assert(std::regex_match("X", std::regex("[XY]")));
  17. assert(!std::regex_match("X", std::regex("[^X]")));
  18. assert(!std::regex_match("X", std::regex("[^XY]")));
  19. assert(std::regex_match("X", std::regex("[\\S]")));
  20. assert(!std::regex_match("X", std::regex("[^\\S]")));
  21. assert(!std::regex_match("X", std::regex("[\\s]")));
  22. assert(std::regex_match("X", std::regex("[^\\s]")));
  23. assert(std::regex_match("X", std::regex("[\\s\\S]")));
  24. assert(std::regex_match("X", std::regex("[^Y\\s]")));
  25. assert(!std::regex_match("X", std::regex("[^X\\s]")));
  26. assert(std::regex_match("X", std::regex("[\\w]")));
  27. assert(std::regex_match("_", std::regex("[\\w]")));
  28. assert(!std::regex_match("X", std::regex("[^\\w]")));
  29. assert(!std::regex_match("_", std::regex("[^\\w]")));
  30. assert(!std::regex_match("X", std::regex("[\\W]")));
  31. assert(!std::regex_match("_", std::regex("[\\W]")));
  32. assert(std::regex_match("X", std::regex("[^\\W]")));
  33. assert(std::regex_match("_", std::regex("[^\\W]")));
  34. // Those test cases are taken from PR40904
  35. assert(std::regex_match("abZcd", std::regex("^ab[\\d\\D]cd")));
  36. assert(std::regex_match("ab5cd", std::regex("^ab[\\d\\D]cd")));
  37. assert(std::regex_match("abZcd", std::regex("^ab[\\D]cd")));
  38. assert(std::regex_match("abZcd", std::regex("^ab\\Dcd")));
  39. assert(std::regex_match("ab5cd", std::regex("^ab[\\d]cd")));
  40. assert(std::regex_match("ab5cd", std::regex("^ab\\dcd")));
  41. assert(!std::regex_match("abZcd", std::regex("^ab\\dcd")));
  42. assert(!std::regex_match("ab5cd", std::regex("^ab\\Dcd")));
  43. assert(std::regex_match("_xyz_", std::regex("_(\\s|\\S)+_")));
  44. assert(std::regex_match("_xyz_", std::regex("_[\\s\\S]+_")));
  45. return 0;
  46. }