]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/blob - t/10-jokers.t
67a1fd8ac2b206f6d89039ea02c564e461857d5e
[perl/modules/Regexp-Wildcards.git] / t / 10-jokers.t
1 #!perl -T
2
3 use Test::More tests => 3 * (4 + 2 + 9 + 2) * 3;
4
5 use Regexp::Wildcards qw/wc2re/;
6
7 sub try {
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)');
13 }
14
15 for my $t (qw/unix win32 jokers/) {
16  # Simple
17
18  try $t, 'simple *', '*', '.*';
19  try $t, 'simple ?', '?', '.';
20
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)');
24
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)');
28
29  # Multiple
30
31  try $t, 'multiple *', '**', '.*';
32  try $t, 'multiple ?', '??', '..';
33
34  # Escaping
35
36  try $t, 'escaping *', '\\*';
37  try $t, 'escaping *', '\\?';
38  try $t, 'escaping \\\\\\*', '\\\\\\*';
39  try $t, 'escaping \\\\\\?', '\\\\\\?';
40
41  try $t, 'not escaping \\\\*', '\\\\*', '\\\\.*';
42  try $t, 'not escaping \\\\?', '\\\\?', '\\\\.';
43
44  try $t, 'escaping \\', '\\', '\\\\';
45  try $t, 'escaping regex characters', '[]', '\\[\\]';
46  try $t, 'not escaping escaped regex characters', '\\\\\\[\\]';
47
48  # Mixed
49
50  try $t, 'mixed * and \\*', '*\\**', '.*\\*.*';
51  try $t, 'mixed ? and \\?', '?\\??', '.\\?.';
52 }