libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

match_not_null.pass.cpp (1688B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <regex>
     11 
     12 // match_not_null:
     13 //     The regular expression shall not match an empty sequence.
     14 
     15 #include "test_macros.h"
     16 #include <cassert>
     17 #include <regex>
     18 
     19 int main()
     20 {
     21   // When match_not_null is on, the regex engine should reject empty matches and
     22   // move on to try other solutions.
     23   std::cmatch m;
     24   assert(!std::regex_search("a", m, std::regex("b*"),
     25                             std::regex_constants::match_not_null));
     26   assert(std::regex_search("aa", m, std::regex("a*?"),
     27                            std::regex_constants::match_not_null));
     28   assert(m[0].length() == 1);
     29   assert(!std::regex_search("a", m, std::regex("b*", std::regex::extended),
     30                             std::regex_constants::match_not_null));
     31   assert(!std::regex_search(
     32       "a", m,
     33       std::regex("b*", std::regex::extended | std::regex_constants::nosubs),
     34       std::regex_constants::match_not_null));
     35 
     36   assert(!std::regex_match("", m, std::regex("a*"),
     37                            std::regex_constants::match_not_null));
     38   assert(!std::regex_match("", m, std::regex("a*", std::regex::extended),
     39                            std::regex_constants::match_not_null));
     40   assert(!std::regex_match(
     41       "", m,
     42       std::regex("a*", std::regex::extended | std::regex_constants::nosubs),
     43       std::regex_constants::match_not_null));
     44 
     45   return 0;
     46 }