]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/blob - t/12-brackets.t
Importing Regexp-Wildcards-0.05.tar.gz
[perl/modules/Regexp-Wildcards.git] / t / 12-brackets.t
1 #!perl -T
2
3 use Test::More tests => 26;
4
5 use Regexp::Wildcards qw/wc2re_jokers wc2re_unix wc2re_win32/;
6
7 ok(wc2re_jokers('a{b\\\\,c\\\\}d') eq 'a\\{b\\\\\\,c\\\\\\}d', 'wc2re_jokers');
8
9 ok(wc2re_win32('a{b\\\\,c\\\\}d') eq '(?:a\\{b\\\\|c\\\\\\}d)', 'wc2re_win32');
10
11 ok(wc2re_unix('{}') eq '(?:)', 'empty brackets');
12 ok(wc2re_unix('{a}') eq '(?:a)', 'brackets 1');
13 ok(wc2re_unix('{a,b}') eq '(?:a|b)', 'brackets 2');
14 ok(wc2re_unix('{a,b,c}') eq '(?:a|b|c)', 'brackets 3');
15
16 ok(wc2re_unix('a{b,c}d') eq 'a(?:b|c)d',
17    '1 bracketed block');
18 ok(wc2re_unix('a{b,c}d{e,,f}') eq 'a(?:b|c)d(?:e||f)',
19    '2 bracketed blocks');
20 ok(wc2re_unix('a{b,c}d{e,,f}{g,h,}') eq 'a(?:b|c)d(?:e||f)(?:g|h|)',
21    '3 bracketed blocks');
22
23 ok(wc2re_unix('{a{b}}') eq '(?:a(?:b))',
24    '2 nested bracketed blocks 1');
25 ok(wc2re_unix('{a,{b},c}') eq '(?:a|(?:b)|c)',
26    '2 nested bracketed blocks 2');
27 ok(wc2re_unix('{a,{b{d}e},c}') eq '(?:a|(?:b(?:d)e)|c)',
28    '3 nested bracketed blocks');
29 ok(wc2re_unix('{a,{b{d{}}e,f,,},c}') eq '(?:a|(?:b(?:d(?:))e|f||)|c)',
30    '4 nested bracketed blocks');
31 ok(wc2re_unix('{a,{b{d{}}e,f,,},c}{,g{{}h,i}}') eq '(?:a|(?:b(?:d(?:))e|f||)|c)(?:|g(?:(?:)h|i))',
32    '4+3 nested bracketed blocks');
33
34 ok(wc2re_unix('\\{\\\\}') eq '\\{\\\\\\}',
35    'escaping brackets');
36 ok(wc2re_unix('\\{a,b,c\\\\\\}') eq '\\{a\\,b\\,c\\\\\\}',
37    'escaping commas 1');
38 ok(wc2re_unix('\\{a\\\\,b\\,c}') eq '\\{a\\\\\\,b\\,c\\}',
39    'escaping commas 2');
40 ok(wc2re_unix('\\{a\\\\,b\\,c\\}') eq '\\{a\\\\\\,b\\,c\\}',
41    'escaping commas 3');
42 ok(wc2re_unix('\\{a\\\\,b\\,c\\\\}') eq '\\{a\\\\\\,b\\,c\\\\\\}',
43    'escaping brackets and commas');
44
45 ok(wc2re_unix('{a\\},b\\{,c}') eq '(?:a\\}|b\\{|c)',
46    'overlapping brackets');
47 ok(wc2re_unix('{a\\{b,c}d,e}') eq '(?:a\\{b|c)d\\,e\\}',
48    'partial unbalanced catching 1');
49 ok(wc2re_unix('{a\\{\\\\}b,c\\\\}') eq '(?:a\\{\\\\)b\\,c\\\\\\}',
50    'partial unbalanced catching 2');
51 ok(wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}',
52    'no partial unbalanced catching');
53 ok(wc2re_unix('{a,\\{,\\},b}') eq '(?:a|\\{|\\}|b)',
54    'substituting commas 1');
55 ok(wc2re_unix('{a,\\{d,e,,\\}b,c}') eq '(?:a|\\{d|e||\\}b|c)',
56    'substituting commas 2');
57 ok(wc2re_unix('{a,\\{d,e,,\\}b,c}\\\\{f,g,h,i}') eq '(?:a|\\{d|e||\\}b|c)\\\\(?:f|g|h|i)',
58    'handling the rest');