Home | History | Annotate | Download | only in re.traits
      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> struct regex_traits;
     13 
     14 // bool isctype(charT c, char_class_type f) const;
     15 
     16 // TODO(EricWF): This test takes 40+ minutes to build with Clang 3.8 under ASAN or MSAN.
     17 // UNSUPPORTED: asan, msan
     18 
     19 
     20 #include <regex>
     21 #include <cassert>
     22 #include "test_macros.h"
     23 
     24 int main()
     25 {
     26     {
     27         std::regex_traits<char> t;
     28 
     29         std::string s("w");
     30         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     31         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     32         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     33         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     34         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     35         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     36         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     37 
     38         s = "alnum";
     39         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     40         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     41         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     42         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     43         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     44         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     45         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     46 
     47         s = "alpha";
     48         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     49         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     50         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     51         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     52         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     53         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     54         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     55 
     56         s = "blank";
     57         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     58         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     59         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     60         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     61         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     62         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     63         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     64 
     65         s = "cntrl";
     66         assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
     67         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     68         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     69         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     70         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     71         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     72         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     73         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     74 
     75         s = "digit";
     76         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
     77         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     78         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     79         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     80         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     81         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     82         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     83         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     84 
     85         s = "graph";
     86         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
     87         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     88         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     89         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
     90         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
     91         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
     92         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
     93         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
     94 
     95         s = "lower";
     96         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
     97         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
     98         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
     99         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    100         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    101         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    102         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    103         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    104 
    105         s = "print";
    106         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
    107         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
    108         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
    109         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    110         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    111         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    112         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    113         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    114 
    115         s = "punct";
    116         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
    117         assert( t.isctype('_', t.lookup_classname(s.begin(), s.end())));
    118         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
    119         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    120         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    121         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    122         assert( t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    123         assert( t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    124 
    125         s = "space";
    126         assert( t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
    127         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
    128         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
    129         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    130         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    131         assert( t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    132         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    133         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    134 
    135         s = "upper";
    136         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
    137         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
    138         assert(!t.isctype('a', t.lookup_classname(s.begin(), s.end())));
    139         assert( t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    140         assert(!t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    141         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    142         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    143         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    144 
    145         s = "xdigit";
    146         assert(!t.isctype('\n', t.lookup_classname(s.begin(), s.end())));
    147         assert(!t.isctype('_', t.lookup_classname(s.begin(), s.end())));
    148         assert( t.isctype('a', t.lookup_classname(s.begin(), s.end())));
    149         assert(!t.isctype('Z', t.lookup_classname(s.begin(), s.end())));
    150         assert( t.isctype('5', t.lookup_classname(s.begin(), s.end())));
    151         assert(!t.isctype(' ', t.lookup_classname(s.begin(), s.end())));
    152         assert(!t.isctype('-', t.lookup_classname(s.begin(), s.end())));
    153         assert(!t.isctype('@', t.lookup_classname(s.begin(), s.end())));
    154     }
    155     {
    156         std::regex_traits<wchar_t> t;
    157 
    158         std::wstring s(L"w");
    159         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    160         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    161         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    162         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    163         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    164         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    165         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    166 
    167         s = L"alnum";
    168         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    169         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    170         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    171         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    172         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    173         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    174         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    175 
    176         s = L"alpha";
    177         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    178         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    179         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    180         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    181         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    182         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    183         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    184 
    185         s = L"blank";
    186         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    187         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    188         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    189         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    190         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    191         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    192         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    193 
    194         s = L"cntrl";
    195         assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    196         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    197         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    198         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    199         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    200         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    201         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    202         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    203 
    204         s = L"digit";
    205         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    206         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    207         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    208         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    209         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    210         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    211         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    212         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    213 
    214         s = L"graph";
    215         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    216         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    217         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    218         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    219         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    220         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    221         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    222         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    223 
    224         s = L"lower";
    225         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    226         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    227         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    228         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    229         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    230         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    231         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    232         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    233 
    234         s = L"print";
    235         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    236         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    237         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    238         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    239         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    240         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    241         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    242         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    243 
    244         s = L"punct";
    245         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    246         assert( t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    247         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    248         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    249         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    250         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    251         assert( t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    252         assert( t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    253 
    254         s = L"space";
    255         assert( t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    256         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    257         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    258         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    259         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    260         assert( t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    261         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    262         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    263 
    264         s = L"upper";
    265         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    266         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    267         assert(!t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    268         assert( t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    269         assert(!t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    270         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    271         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    272         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    273 
    274         s = L"xdigit";
    275         assert(!t.isctype(L'\n', t.lookup_classname(s.begin(), s.end())));
    276         assert(!t.isctype(L'_', t.lookup_classname(s.begin(), s.end())));
    277         assert( t.isctype(L'a', t.lookup_classname(s.begin(), s.end())));
    278         assert(!t.isctype(L'Z', t.lookup_classname(s.begin(), s.end())));
    279         assert( t.isctype(L'5', t.lookup_classname(s.begin(), s.end())));
    280         assert(!t.isctype(L' ', t.lookup_classname(s.begin(), s.end())));
    281         assert(!t.isctype(L'-', t.lookup_classname(s.begin(), s.end())));
    282         assert(!t.isctype(L'@', t.lookup_classname(s.begin(), s.end())));
    283     }
    284 }
    285