Home | History | Annotate | Download | only in re.regex.construct
      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 // template <class charT, class traits = regex_traits<charT>> class basic_regex;
     13 
     14 // template <class ST, class SA>
     15 //    basic_regex(const basic_string<charT, ST, SA>& s,
     16 //                flag_type f = regex_constants::ECMAScript);
     17 
     18 #include <regex>
     19 #include <cassert>
     20 #include "test_macros.h"
     21 
     22 template <class String>
     23 void
     24 test(const String& p, std::regex_constants::syntax_option_type f, unsigned mc)
     25 {
     26     std::basic_regex<typename String::value_type> r(p, f);
     27     assert(r.flags() == f);
     28     assert(r.mark_count() == mc);
     29 }
     30 
     31 int main()
     32 {
     33     test(std::string("\\(a\\)"), std::regex_constants::basic, 1);
     34     test(std::string("\\(a[bc]\\)"), std::regex_constants::basic, 1);
     35     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::basic, 2);
     36     test(std::string("(a([bc]))"), std::regex_constants::basic, 0);
     37 
     38     test(std::string("\\(a\\)"), std::regex_constants::extended, 0);
     39     test(std::string("\\(a[bc]\\)"), std::regex_constants::extended, 0);
     40     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::extended, 0);
     41     test(std::string("(a([bc]))"), std::regex_constants::extended, 2);
     42 
     43     test(std::string("\\(a\\)"), std::regex_constants::ECMAScript, 0);
     44     test(std::string("\\(a[bc]\\)"), std::regex_constants::ECMAScript, 0);
     45     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::ECMAScript, 0);
     46     test(std::string("(a([bc]))"), std::regex_constants::ECMAScript, 2);
     47 
     48     test(std::string("\\(a\\)"), std::regex_constants::awk, 0);
     49     test(std::string("\\(a[bc]\\)"), std::regex_constants::awk, 0);
     50     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::awk, 0);
     51     test(std::string("(a([bc]))"), std::regex_constants::awk, 2);
     52 
     53     test(std::string("\\(a\\)"), std::regex_constants::grep, 1);
     54     test(std::string("\\(a[bc]\\)"), std::regex_constants::grep, 1);
     55     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::grep, 2);
     56     test(std::string("(a([bc]))"), std::regex_constants::grep, 0);
     57 
     58     test(std::string("\\(a\\)"), std::regex_constants::egrep, 0);
     59     test(std::string("\\(a[bc]\\)"), std::regex_constants::egrep, 0);
     60     test(std::string("\\(a\\([bc]\\)\\)"), std::regex_constants::egrep, 0);
     61     test(std::string("(a([bc]))"), std::regex_constants::egrep, 2);
     62 }
     63