3 use Test::More tests => 3 * (4 + 2 + 9 + 2) * 3;
5 use Regexp::Wildcards qw/wc2re/;
8 my ($t, $s, $x, $y) = @_;
9 $y = $x unless defined $y;
10 ok(wc2re('ab' . $x, $t) eq 'ab' . $y, $s . ' (beginning)');
11 ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle)');
12 ok(wc2re($x . 'ab', $t) eq $y . 'ab', $s . ' (end)');
15 for my $t (qw/unix win32 jokers/) {
18 try $t, 'simple *', '*', '.*';
19 try $t, 'simple ?', '?', '.';
21 ok(wc2re('?*ab', $t) eq '..*ab', 'simple ? and * (beginning)');
22 ok(wc2re('?a*b', $t) eq '.a.*b', 'simple ? and * (middle)');
23 ok(wc2re('?ab*', $t) eq '.ab.*', 'simple ? and * (end)');
25 ok(wc2re('*ab?', $t) eq '.*ab.', 'simple * and ? (beginning)');
26 ok(wc2re('a*b?', $t) eq 'a.*b.', 'simple * and ? (middle)');
27 ok(wc2re('ab*?', $t) eq 'ab.*.', 'simple * and ? (end)');
31 try $t, 'multiple *', '**', '.*';
32 try $t, 'multiple ?', '??', '..';
36 try $t, 'escaping *', '\\*';
37 try $t, 'escaping *', '\\?';
38 try $t, 'escaping \\\\\\*', '\\\\\\*';
39 try $t, 'escaping \\\\\\?', '\\\\\\?';
41 try $t, 'not escaping \\\\*', '\\\\*', '\\\\.*';
42 try $t, 'not escaping \\\\?', '\\\\?', '\\\\.';
44 try $t, 'escaping \\', '\\', '\\\\';
45 try $t, 'escaping regex characters', '[]', '\\[\\]';
46 try $t, 'not escaping escaped regex characters', '\\\\\\[\\]';
50 try $t, 'mixed * and \\*', '*\\**', '.*\\*.*';
51 try $t, 'mixed ? and \\?', '?\\??', '.\\?.';