3 use Test::More tests => 4 * (4 + 2 + 7 + 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 . ' (begin) ['.$t.']');
11 ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle) ['.$t.']');
12 ok(wc2re($x . 'ab', $t) eq $y . 'ab', $s . ' (end) ['.$t.']');
16 my ($t, $one, $any) = @_;
20 try $t, "simple $any", $any, '.*';
21 try $t, "simple $one", $one, '.';
23 ok(wc2re($one.$any.'ab', $t) eq '..*ab',
24 "simple $one and $any (begin) [$t]");
25 ok(wc2re($one.'a'.$any.'b', $t) eq '.a.*b',
26 "simple $one and $any (middle) [$t]");
27 ok(wc2re($one.'ab'.$any, $t) eq '.ab.*',
28 "simple $one and $any (end) [$t]");
30 ok(wc2re($any.'ab'.$one, $t) eq '.*ab.',
31 "simple $any and $one (begin) [$t]");
32 ok(wc2re('a'.$any.'b'.$one, $t) eq 'a.*b.',
33 "simple $any and $one (middle) [$t]");
34 ok(wc2re('ab'.$any.$one, $t) eq 'ab.*.',
35 "simple $any and $one (end) [$t]");
39 try $t, "multiple $any", $any x 2, '.*';
40 try $t, "multiple $one", $one x 2, '..';
45 local $Regexp::Wildcards::CaptureSingle = 1;
46 try $t, "multiple capturing $one", $one.$one.'\\'.$one.$one,
47 '(.)(.)\\'.$one.'(.)';
49 local $Regexp::Wildcards::CaptureAny = 1;
50 try $t, "multiple capturing $any (greedy)", $any.$any.'\\'.$any.$any,
52 my $wc = $any.$any.$one.$one.'\\'.$one.$one.'\\'.$any.$any;
53 try $t, "multiple capturing $any (greedy) and capturing $one",
54 $wc, '(.*)(.)(.)\\'.$one.'(.)\\'.$any.'(.*)';
56 $Regexp::Wildcards::CaptureSingle = 0;
57 try $t, "multiple capturing $any (greedy) and non-capturing $one",
58 $wc, '(.*)..\\'.$one.'.\\'.$any.'(.*)';
60 $Regexp::Wildcards::CaptureAny = -1;
61 try $t, "multiple capturing $any (non-greedy)", $any.$any.'\\'.$any.$any,
62 '(.*?)\\'.$any.'(.*?)';
63 try $t, "multiple capturing $any (non-greedy) and non-capturing $one",
64 $wc, '(.*?)..\\'.$one.'.\\'.$any.'(.*?)';
66 $Regexp::Wildcards::CaptureSingle = 1;
67 try $t, "multiple capturing $any (non-greedy) and capturing $one",
68 $wc, '(.*?)(.)(.)\\'.$one.'(.)\\'.$any.'(.*?)';
73 try $t, "escaping $any", '\\'.$any;
74 try $t, "escaping $one", '\\'.$one;
75 try $t, "escaping \\\\\\$any", '\\\\\\'.$any;
76 try $t, "escaping \\\\\\$one", '\\\\\\'.$one;
78 try $t, "not escaping \\\\$any", '\\\\'.$any, '\\\\.*';
79 try $t, "not escaping \\\\$one", '\\\\'.$one, '\\\\.';
81 try $t, 'escaping \\', '\\', '\\\\';
82 try $t, 'escaping regex characters', '[]', '\\[\\]';
83 try $t, 'not escaping escaped regex characters', '\\\\\\[\\]';
87 try $t, "mixed $any and \\$any", $any.'\\'.$any.$any, '.*\\'.$any.'.*';
88 try $t, "mixed $one and \\$one", $one.'\\'.$one.$one, '.\\'.$one.'.';
91 alltests $_, '?', '*' for qw/jokers unix win32/;
92 alltests 'sql', '_', '%';