]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/blobdiff - t/10-jokers.t
Importing Regexp-Wildcards-0.06.tar.gz
[perl/modules/Regexp-Wildcards.git] / t / 10-jokers.t
index 85c9ede9ce0b1e7de26dbf21205b97390da63397..0ce769e50eb7fa1e8cb1ddff5cb8beb407364671 100644 (file)
@@ -1,66 +1,82 @@
 #!perl -T
 
-use Test::More tests => 3 * (4 + 2 + 7 + 9 + 2) * 3;
+use Test::More tests => 4 * (4 + 2 + 7 + 9 + 2) * 3;
 
 use Regexp::Wildcards qw/wc2re/;
 
 sub try {
  my ($t, $s, $x, $y) = @_;
  $y = $x unless defined $y;
- ok(wc2re('ab' . $x,      $t) eq 'ab' . $y,      $s . ' (beginning)');
- ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle)');
- ok(wc2re($x . 'ab',      $t) eq $y . 'ab',      $s . ' (end)');
+ ok(wc2re('ab' . $x,      $t) eq 'ab' . $y,      $s . ' (begin) ['.$t.']');
+ ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle) ['.$t.']');
+ ok(wc2re($x . 'ab',      $t) eq $y . 'ab',      $s . ' (end) ['.$t.']');
 }
 
-for my $t (qw/unix win32 jokers/) {
+sub alltests {
+ my ($t, $one, $any) = @_;
+
  # Simple
 
- try $t, 'simple *', '*', '.*';
- try $t, 'simple ?', '?', '.';
+ try $t, "simple $any", $any, '.*';
+ try $t, "simple $one", $one, '.';
 
- ok(wc2re('?*ab', $t) eq '..*ab', 'simple ? and * (beginning)');
- ok(wc2re('?a*b', $t) eq '.a.*b', 'simple ? and * (middle)');
- ok(wc2re('?ab*', $t) eq '.ab.*', 'simple ? and * (end)');
+ ok(wc2re($one.$any.'ab', $t)    eq '..*ab',
+    "simple $one and $any (begin) [$t]");
+ ok(wc2re($one.'a'.$any.'b', $t) eq '.a.*b',
+    "simple $one and $any (middle) [$t]");
+ ok(wc2re($one.'ab'.$any, $t)    eq '.ab.*',
+    "simple $one and $any (end) [$t]");
 
- ok(wc2re('*ab?', $t) eq '.*ab.', 'simple * and ? (beginning)');
- ok(wc2re('a*b?', $t) eq 'a.*b.', 'simple * and ? (middle)');
- ok(wc2re('ab*?', $t) eq 'ab.*.', 'simple * and ? (end)');
+ ok(wc2re($any.'ab'.$one, $t)    eq '.*ab.',
+    "simple $any and $one (begin) [$t]");
+ ok(wc2re('a'.$any.'b'.$one, $t) eq 'a.*b.',
+    "simple $any and $one (middle) [$t]");
+ ok(wc2re('ab'.$any.$one, $t)    eq 'ab.*.',
+    "simple $any and $one (end) [$t]");
 
  # Multiple
 
- try $t, 'multiple *', '**', '.*';
- try $t, 'multiple ?', '??', '..';
+ try $t, "multiple $any", $any x 2, '.*';
+ try $t, "multiple $one", $one x 2, '..';
 
  # Variables
 
  {
   local $Regexp::Wildcards::CaptureSingle = 1;
-  try $t, 'multiple capturing ?', '??\\??', '(.)(.)\\?(.)';
+  try $t, "multiple capturing $one", $one.$one.'\\'.$one.$one,
+                                     '(.)(.)\\'.$one.'(.)';
+
   local $Regexp::Wildcards::CaptureAny = 1;
-  try $t, 'multiple capturing * (greedy)', '**\\**', '(.*)\\*(.*)';
-  try $t, 'multiple capturing * (greedy) and capturing ?',
-          '**??\\??\\**', '(.*)(.)(.)\\?(.)\\*(.*)';
+  try $t, "multiple capturing $any (greedy)", $any.$any.'\\'.$any.$any,
+                                              '(.*)\\'.$any.'(.*)';
+  my $wc = $any.$any.$one.$one.'\\'.$one.$one.'\\'.$any.$any;
+  try $t, "multiple capturing $any (greedy) and capturing $one",
+          $wc, '(.*)(.)(.)\\'.$one.'(.)\\'.$any.'(.*)';
+
   $Regexp::Wildcards::CaptureSingle = 0;
-  try $t, 'multiple capturing * (greedy) and non-capturing ?',
-          '**??\\??\\**', '(.*)..\\?.\\*(.*)';
+  try $t, "multiple capturing $any (greedy) and non-capturing $one",
+          $wc, '(.*)..\\'.$one.'.\\'.$any.'(.*)';
+
   $Regexp::Wildcards::CaptureAny = -1;
-  try $t, 'multiple capturing * (non-greedy)', '**\\**', '(.*?)\\*(.*?)';
-  try $t, 'multiple capturing * (non-greedy) and non-capturing ?',
-          '**??\\??\\**', '(.*?)..\\?.\\*(.*?)';
+  try $t, "multiple capturing $any (non-greedy)", $any.$any.'\\'.$any.$any,
+                                                  '(.*?)\\'.$any.'(.*?)';
+  try $t, "multiple capturing $any (non-greedy) and non-capturing $one",
+          $wc, '(.*?)..\\'.$one.'.\\'.$any.'(.*?)';
+
   $Regexp::Wildcards::CaptureSingle = 1;
-  try $t, 'multiple capturing * (non-greedy) and capturing ?',
-          '**??\\??\\**', '(.*?)(.)(.)\\?(.)\\*(.*?)';
+  try $t, "multiple capturing $any (non-greedy) and capturing $one",
+          $wc, '(.*?)(.)(.)\\'.$one.'(.)\\'.$any.'(.*?)';
  }
 
  # Escaping
 
- try $t, 'escaping *', '\\*';
- try $t, 'escaping *', '\\?';
- try $t, 'escaping \\\\\\*', '\\\\\\*';
- try $t, 'escaping \\\\\\?', '\\\\\\?';
+ try $t, "escaping $any", '\\'.$any;
+ try $t, "escaping $one", '\\'.$one;
+ try $t, "escaping \\\\\\$any", '\\\\\\'.$any;
+ try $t, "escaping \\\\\\$one", '\\\\\\'.$one;
 
- try $t, 'not escaping \\\\*', '\\\\*', '\\\\.*';
- try $t, 'not escaping \\\\?', '\\\\?', '\\\\.';
+ try $t, "not escaping \\\\$any", '\\\\'.$any, '\\\\.*';
+ try $t, "not escaping \\\\$one", '\\\\'.$one, '\\\\.';
 
  try $t, 'escaping \\', '\\', '\\\\';
  try $t, 'escaping regex characters', '[]', '\\[\\]';
@@ -68,6 +84,9 @@ for my $t (qw/unix win32 jokers/) {
 
  # Mixed
 
- try $t, 'mixed * and \\*', '*\\**', '.*\\*.*';
- try $t, 'mixed ? and \\?', '?\\??', '.\\?.';
+ try $t, "mixed $any and \\$any", $any.'\\'.$any.$any, '.*\\'.$any.'.*';
+ try $t, "mixed $one and \\$one", $one.'\\'.$one.$one, '.\\'.$one.'.';
 }
+
+alltests $_,    '?', '*' for qw/jokers unix win32/;
+alltests 'sql', '_', '%';