61 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <regex>10// UNSUPPORTED: c++0311 12// Make sure that we correctly match inverted character classes.13 14#include <cassert>15#include <regex>16 17#include "test_macros.h"18 19 20int main(int, char**) {21 assert(std::regex_match("X", std::regex("[X]")));22 assert(std::regex_match("X", std::regex("[XY]")));23 assert(!std::regex_match("X", std::regex("[^X]")));24 assert(!std::regex_match("X", std::regex("[^XY]")));25 26 assert(std::regex_match("X", std::regex("[\\S]")));27 assert(!std::regex_match("X", std::regex("[^\\S]")));28 29 assert(!std::regex_match("X", std::regex("[\\s]")));30 assert(std::regex_match("X", std::regex("[^\\s]")));31 32 assert(std::regex_match("X", std::regex("[\\s\\S]")));33 assert(std::regex_match("X", std::regex("[^Y\\s]")));34 assert(!std::regex_match("X", std::regex("[^X\\s]")));35 36 assert(std::regex_match("X", std::regex("[\\w]")));37 assert(std::regex_match("_", std::regex("[\\w]")));38 assert(!std::regex_match("X", std::regex("[^\\w]")));39 assert(!std::regex_match("_", std::regex("[^\\w]")));40 41 assert(!std::regex_match("X", std::regex("[\\W]")));42 assert(!std::regex_match("_", std::regex("[\\W]")));43 assert(std::regex_match("X", std::regex("[^\\W]")));44 assert(std::regex_match("_", std::regex("[^\\W]")));45 46 // Those test cases are taken from PR4090447 assert(std::regex_match("abZcd", std::regex("^ab[\\d\\D]cd")));48 assert(std::regex_match("ab5cd", std::regex("^ab[\\d\\D]cd")));49 assert(std::regex_match("abZcd", std::regex("^ab[\\D]cd")));50 assert(std::regex_match("abZcd", std::regex("^ab\\Dcd")));51 assert(std::regex_match("ab5cd", std::regex("^ab[\\d]cd")));52 assert(std::regex_match("ab5cd", std::regex("^ab\\dcd")));53 assert(!std::regex_match("abZcd", std::regex("^ab\\dcd")));54 assert(!std::regex_match("ab5cd", std::regex("^ab\\Dcd")));55 56 assert(std::regex_match("_xyz_", std::regex("_(\\s|\\S)+_")));57 assert(std::regex_match("_xyz_", std::regex("_[\\s\\S]+_")));58 59 return 0;60}61