• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 // <regex>
10 
11 // match_not_null:
12 //     The regular expression shall not match an empty sequence.
13 
14 #include "test_macros.h"
15 #include <cassert>
16 #include <regex>
17 
main(int,char **)18 int main(int, char**)
19 {
20   // When match_not_null is on, the regex engine should reject empty matches and
21   // move on to try other solutions.
22   std::cmatch m;
23   assert(!std::regex_search("a", m, std::regex("b*"),
24                             std::regex_constants::match_not_null));
25   assert(std::regex_search("aa", m, std::regex("a*?"),
26                            std::regex_constants::match_not_null));
27   assert(m[0].length() == 1);
28   assert(!std::regex_search("a", m, std::regex("b*", std::regex::extended),
29                             std::regex_constants::match_not_null));
30   assert(!std::regex_search(
31       "a", m,
32       std::regex("b*", std::regex::extended | std::regex_constants::nosubs),
33       std::regex_constants::match_not_null));
34 
35   assert(!std::regex_match("", m, std::regex("a*"),
36                            std::regex_constants::match_not_null));
37   assert(!std::regex_match("", m, std::regex("a*", std::regex::extended),
38                            std::regex_constants::match_not_null));
39   assert(!std::regex_match(
40       "", m,
41       std::regex("a*", std::regex::extended | std::regex_constants::nosubs),
42       std::regex_constants::match_not_null));
43 
44   return 0;
45 }
46