91 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 11// match_not_eol:12// The last character in the sequence [first,last) shall be treated as13// though it is not at the end of a line, so the character "$" in14// the regular expression shall not match [last,last).15 16#include <regex>17#include <cassert>18#include "test_macros.h"19 20int main(int, char**)21{22 {23 std::string target = "foo";24 std::regex re("foo$");25 assert( std::regex_match(target, re));26 assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));27 }28 29 {30 std::string target = "foo";31 std::regex re("foo");32 assert( std::regex_match(target, re));33 assert( std::regex_match(target, re, std::regex_constants::match_not_eol));34 }35 36 {37 std::string target = "refoo";38 std::regex re("foo$");39 assert( std::regex_search(target, re));40 assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));41 }42 43 {44 std::string target = "refoo";45 std::regex re("foo");46 assert( std::regex_search(target, re));47 assert( std::regex_search(target, re, std::regex_constants::match_not_eol));48 }49 50 {51 std::string target = "foo";52 std::regex re("$");53 assert(std::regex_search(target, re));54 assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));55 56 std::smatch match;57 assert(std::regex_search(target, match, re));58 assert(match.position(0) == 3);59 assert(match.length(0) == 0);60 assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));61 assert(match.length(0) == 0);62 }63 64 {65 std::string target = "foo";66 std::regex re("$", std::regex::multiline);67 std::smatch match;68 assert(std::regex_search(target, match, re));69 assert(match.position(0) == 3);70 assert(match.length(0) == 0);71 assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));72 assert(match.length(0) == 0);73 }74 75 {76 std::string target = "foo";77 std::regex re("$");78 assert(!std::regex_match(target, re));79 assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));80 }81 82 {83 std::string target = "a";84 std::regex re("^b*$");85 assert(!std::regex_search(target, re));86 assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));87 }88 89 return 0;90}91