]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/commitdiff
Importing Regexp-Wildcards-0.04.tar.gz v0.04
authorVincent Pit <vince@profvince.com>
Sun, 29 Jun 2008 15:43:52 +0000 (17:43 +0200)
committerVincent Pit <vince@profvince.com>
Sun, 29 Jun 2008 15:43:52 +0000 (17:43 +0200)
Changes
MANIFEST
META.yml
README
lib/Regexp/Wildcards.pm
samples/wc2re.pl
t/02-wc2re.t [new file with mode: 0644]
t/10-jokers.t

diff --git a/Changes b/Changes
index 1490402c97bfe30f3b0505458656577778c7426b..421a0e2f0a656cc0a2ef6535d739536dfd7fb344 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,14 @@
 Revision history for Regexp-Wildcards
 
 Revision history for Regexp-Wildcards
 
+0.04    2007-06-20 19:00 UTC
+        + Add : You can supply $^O as the type for wc2re, which will wrap to
+                wc2re_win32 for 'dos', 'os2', 'MSWin32', 'cygwin', and to
+                wc2re_unix in all the other cases.
+        + Add : Generated regexps can now capture the interesting bits of the
+                wildcard expression via the configuration variables
+                $CaptureSingle, $CaptureAny and $CaptureBrackets (see pod)
+        + Add : Corresponding pod & tests
+
 0.03    2007-06-17 14:45 UTC
         + Fix : Missing PREREQ_PM in Makefile.PL
        + Fix : Typos in pod.
 0.03    2007-06-17 14:45 UTC
         + Fix : Missing PREREQ_PM in Makefile.PL
        + Fix : Typos in pod.
index 2cd91d2a657b68a3c33237f3494def2cbde79ce0..b6cdff9a3a85e07c2d015c9f7de6b927d0e099b9 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -7,6 +7,7 @@ README
 samples/wc2re.pl
 t/00-load.t
 t/01-import.t
 samples/wc2re.pl
 t/00-load.t
 t/01-import.t
+t/02-wc2re.t
 t/10-jokers.t
 t/11-commas.t
 t/12-brackets.t
 t/10-jokers.t
 t/11-commas.t
 t/12-brackets.t
index 24e1ab87c43ba2d5b27bdce40b11c211cdebff68..10dd95b442bcb57d6557f91571b5102824c63148 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                Regexp-Wildcards
 --- #YAML:1.0
 name:                Regexp-Wildcards
-version:             0.03
+version:             0.04
 abstract:            Converts wildcard expressions to Perl regular expressions.
 license:             perl
 generated_by:        ExtUtils::MakeMaker version 6.32
 abstract:            Converts wildcard expressions to Perl regular expressions.
 license:             perl
 generated_by:        ExtUtils::MakeMaker version 6.32
diff --git a/README b/README
index dab8850022b6f62ba95049f2c0c1881177687a54..c7bd7943c1d5e2dbd77dcbb316fcb2d852224ba9 100644 (file)
--- a/README
+++ b/README
@@ -3,7 +3,7 @@ NAME
     expressions.
 
 VERSION
     expressions.
 
 VERSION
-    Version 0.03
+    Version 0.04
 
 SYNOPSIS
         use Regexp::Wildcards qw/wc2re/;
 
 SYNOPSIS
         use Regexp::Wildcards qw/wc2re/;
@@ -22,17 +22,71 @@ DESCRIPTION
     and uses the backspace ("\") as an escape character. Wrappers are
     provided to mimic the behaviour of Windows and Unix shells.
 
     and uses the backspace ("\") as an escape character. Wrappers are
     provided to mimic the behaviour of Windows and Unix shells.
 
+VARIABLES
+    These variables control if the wildcards jokers and brackets must
+    capture their match. They can be globally set by writing in your program
+
+        $Regexp::Wildcards::CaptureAny = -1;
+        # From then, '*' jokers are capturing
+
+    or can be locally specified via "local"
+
+        {
+         local $Regexp::Wildcards::CaptureAny = -1;
+         # In this block, the '*' joker is capturing.
+         ...
+        }
+        # Back to the situation from before the block
+
+    This section describes also how those elements are translated by the
+    functions.
+
+  $CaptureSingle
+    When this variable is true, each occurence of the unescaped "?" joker is
+    made capturing in the resulting regexp (they are be replaced by "(.)").
+    Otherwise, they are just replaced by ".". Default is the latter.
+
+        'a???b\\??' is translated to 'a(.)(.)(.)b\\?(.)' if $CaptureSingle is true
+                                     'a...b\\?.'         otherwise (default)
+
+  $CaptureAny
+    By default this variable is false, and successions of unescaped "*"
+    jokers are replaced by one single ".*". When it evalutes to true, those
+    sequences of "*" are made into one capture, which is greedy ("(.*)") for
+    "$CaptureAny > 0" and otherwise non-greedy ("(.*?)").
+
+        'a***b\\**' is translated to 'a.*b\\*.*'       if $CaptureAny is false (default)
+                                     'a(.*)b\\*(.*)'   if $CaptureAny > 0
+                                     'a(.*?)b\\*(.*?)' otherwise
+
+  $CaptureBrackets
+    If this variable is set to true, valid brackets constructs are made into
+    "( | )" captures, and otherwise they are replaced by non-capturing
+    alternations ("(?: | ")), which is the default.
+
+        'a{b\\},\\{c}' is translated to 'a(b\\}|\\{c)'   if $CaptureBrackets is true
+                                        'a(?:b\\}|\\{c)' otherwise (default)
+
 FUNCTIONS
 FUNCTIONS
-  "wc2re_unix"
+  "wc2re_jokers"
     This function takes as its only argument the wildcard string to process,
     This function takes as its only argument the wildcard string to process,
-    and returns the corresponding regular expression according to standard
-    Unix wildcard rules. It successively escapes all unprotected regexp
-    special characters that doesn't hold any meaning for wildcards, turns
-    jokers into their regexp equivalents, and changes bracketed blocks into
-    "(?:|)" alternations. If brackets are unbalanced, it will try to
-    substitute as many of them as possible, and then escape the remaining
-    "{" and "}". Commas outside of any bracket-delimited block will also be
-    escaped.
+    and returns the corresponding regular expression where the jokers "?"
+    and "*" have been translated into their regexp equivalents (see
+    "VARIABLES" for more details). All other unprotected regexp
+    metacharacters are escaped.
+
+        # Everything is escaped.
+        print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
+
+  "wc2re_unix"
+    Similar to the precedent, but this one conforms to standard Unix shell
+    wildcard rules. It successively escapes all unprotected regexp special
+    characters that doesn't hold any meaning for wildcards, turns jokers
+    into their regexp equivalents (see "wc2re_jokers"), and changes
+    bracketed blocks into (possibly capturing) alternations as described in
+    "VARIABLES". If brackets are unbalanced, it tries to substitute as many
+    of them as possible, and then escape the remaining "{" and "}". Commas
+    outside of any bracket-delimited block are also escaped.
 
         # This is a valid bracket expression, and is completely translated.
         print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
 
         # This is a valid bracket expression, and is completely translated.
         print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
@@ -47,29 +101,39 @@ FUNCTIONS
         print 'ok' if wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
 
   "wc2re_win32"
         print 'ok' if wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
 
   "wc2re_win32"
-    Similar to the precedent, but for Windows wildcards. Bracketed blocks
-    are no longer handled (which means that brackets will be escaped), but
-    you can provide a comma-separated list of items.
+    This one works just like the two before, but for Windows wildcards.
+    Bracketed blocks are no longer handled (which means that brackets are
+    escaped), but you can provide a comma-separated list of items.
 
         # All the brackets are escaped, and commas are seen as list delimiters.
         print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
 
 
         # All the brackets are escaped, and commas are seen as list delimiters.
         print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
 
-  "wc2re_jokers"
-    This one only handles the "?" and "*" jokers. All other unquoted regexp
-    metacharacters will be escaped.
-
-        # Everything is escaped.
-        print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
-
   "wc2re"
     A generic function that wraps around all the different rules. The first
     argument is the wildcard expression, and the second one is the type of
   "wc2re"
     A generic function that wraps around all the different rules. The first
     argument is the wildcard expression, and the second one is the type of
-    rules to apply, currently either "unix", "win32" or "jokers". If the
-    type is undefined, it defaults to "unix".
+    rules to apply which can be :
+
+    'unix', 'win32', 'jokers'
+        For one of those raw rule names, "wc2re" simply maps to
+        "wc2re_unix", "wc2re_win32" and "wc2re_jokers" respectively.
+
+    $^O If you supply the Perl operating system name, the call is deferred
+        to "wc2re_win32" for $^O equal to 'dos', 'os2', 'MSWin32' or
+        'cygwin', and to "wc2re_unix" in all the other cases.
+
+    If the type is undefined or not supported, it defaults to 'unix'.
+
+         # Wraps to wc2re_jokers ($re eq 'a\\{b\\,c\\}.*').
+         $re = wc2re 'a{b,c}*' => 'jokers';
+
+         # Wraps to wc2re_win32 ($re eq '(?:a\\{b|c\\}.*)')
+         #       or wc2re_unix  ($re eq 'a(?:b|c).*')       depending on $^O.
+         $re = wc2re 'a{b,c}*' => $^O;
 
 EXPORT
     These four functions are exported only on request : "wc2re",
 
 EXPORT
     These four functions are exported only on request : "wc2re",
-    "wc2re_unix", "wc2re_win32" and "wc2re_jokers".
+    "wc2re_unix", "wc2re_win32" and "wc2re_jokers". The variables are not
+    exported.
 
 DEPENDENCIES
     Text::Balanced, which is bundled with perl since version 5.7.3
 
 DEPENDENCIES
     Text::Balanced, which is bundled with perl since version 5.7.3
index a077628649fcd51bade94a1ed3112fc1ce2e58dc..d4b1cb3a4956d6be2fd8c2b11593abb8478a18f3 100644 (file)
@@ -11,11 +11,11 @@ Regexp::Wildcards - Converts wildcard expressions to Perl regular expressions.
 
 =head1 VERSION
 
 
 =head1 VERSION
 
-Version 0.03
+Version 0.04
 
 =cut
 
 
 =cut
 
-our $VERSION = '0.03';
+our $VERSION = '0.04';
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
@@ -30,11 +30,78 @@ our $VERSION = '0.03';
 
 In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C<?> jokers, as well as Unix bracketed alternatives C<{,}>, and uses the backspace (C<\>) as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells.
 
 
 In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C<?> jokers, as well as Unix bracketed alternatives C<{,}>, and uses the backspace (C<\>) as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells.
 
+=head1 VARIABLES
+
+These variables control if the wildcards jokers and brackets must capture their match. They can be globally set by writing in your program
+
+    $Regexp::Wildcards::CaptureAny = -1;
+    # From then, '*' jokers are capturing
+
+or can be locally specified via C<local>
+
+    {
+     local $Regexp::Wildcards::CaptureAny = -1;
+     # In this block, the '*' joker is capturing.
+     ...
+    }
+    # Back to the situation from before the block
+
+This section describes also how those elements are translated by the L<functions|/FUNCTIONS>.
+
+=head2 C<$CaptureSingle>
+
+When this variable is true, each occurence of the unescaped C<?> joker is made capturing in the resulting regexp (they are be replaced by C<(.)>). Otherwise, they are just replaced by C<.>. Default is the latter.
+
+    'a???b\\??' is translated to 'a(.)(.)(.)b\\?(.)' if $CaptureSingle is true
+                                 'a...b\\?.'         otherwise (default)
+
+=cut
+
+our $CaptureSingle = 0;
+
+=head2 C<$CaptureAny>
+
+By default this variable is false, and successions of unescaped C<*> jokers are replaced by B<one> single C<.*>. When it evalutes to true, those sequences of C<*> are made into B<one> capture, which is greedy (C<(.*)>) for C<$CaptureAny E<gt> 0> and otherwise non-greedy (C<(.*?)>).
+
+    'a***b\\**' is translated to 'a.*b\\*.*'       if $CaptureAny is false (default)
+                                 'a(.*)b\\*(.*)'   if $CaptureAny > 0
+                                 'a(.*?)b\\*(.*?)' otherwise
+
+=cut
+
+our $CaptureAny = 0;
+
+=head2 C<$CaptureBrackets>
+
+If this variable is set to true, valid brackets constructs are made into C<( | )> captures, and otherwise they are replaced by non-capturing alternations (C<(?: | >)), which is the default.
+
+    'a{b\\},\\{c}' is translated to 'a(b\\}|\\{c)'   if $CaptureBrackets is true
+                                    'a(?:b\\}|\\{c)' otherwise (default)
+
+=cut
+
+our $CaptureBrackets = 0;
+
 =head1 FUNCTIONS
 
 =head1 FUNCTIONS
 
+=head2 C<wc2re_jokers>
+
+This function takes as its only argument the wildcard string to process, and returns the corresponding regular expression where the jokers C<?> and C<*> have been translated into their regexp equivalents (see L</VARIABLES> for more details). All other unprotected regexp metacharacters are escaped.
+
+    # Everything is escaped.
+    print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
+
+=cut
+
+sub wc2re_jokers {
+ my ($wc) = @_;
+ $wc =~ s/(?<!\\)((?:\\\\)*[^\w\s?*\\])/\\$1/g;
+ return do_jokers($wc);
+}
+
 =head2 C<wc2re_unix>
 
 =head2 C<wc2re_unix>
 
-This function takes as its only argument the wildcard string to process, and returns the corresponding regular expression according to standard Unix wildcard rules. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, turns jokers into their regexp equivalents, and changes bracketed blocks into C<(?:|)> alternations. If brackets are unbalanced, it will try to substitute as many of them as possible, and then escape the remaining C<{> and C<}>. Commas outside of any bracket-delimited block will also be escaped.
+Similar to the precedent, but this one conforms to standard Unix shell wildcard rules. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, turns jokers into their regexp equivalents (see L</wc2re_jokers>), and changes bracketed blocks into (possibly capturing) alternations as described in L</VARIABLES>. If brackets are unbalanced, it tries to substitute as many of them as possible, and then escape the remaining C<{> and C<}>. Commas outside of any bracket-delimited block are also escaped.
 
     # This is a valid bracket expression, and is completely translated.
     print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
 
     # This is a valid bracket expression, and is completely translated.
     print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
@@ -58,7 +125,7 @@ sub wc2re_unix {
 
 =head2 C<wc2re_win32>
 
 
 =head2 C<wc2re_win32>
 
-Similar to the precedent, but for Windows wildcards. Bracketed blocks are no longer handled (which means that brackets will be escaped), but you can provide a comma-separated list of items.
+This one works just like the two before, but for Windows wildcards. Bracketed blocks are no longer handled (which means that brackets are escaped), but you can provide a comma-separated list of items.
 
     # All the brackets are escaped, and commas are seen as list delimiters.
     print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
 
     # All the brackets are escaped, and commas are seen as list delimiters.
     print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
@@ -71,48 +138,55 @@ sub wc2re_win32 {
  $wc =~ s/(?<!\\)((?:\\\\)*[^\w\s?*\\,])/\\$1/g;
  my $re = do_jokers($wc);
  if ($re =~ /(?<!\\)(?:\\\\)*,/) { # win32 allows comma-separated lists
  $wc =~ s/(?<!\\)((?:\\\\)*[^\w\s?*\\,])/\\$1/g;
  my $re = do_jokers($wc);
  if ($re =~ /(?<!\\)(?:\\\\)*,/) { # win32 allows comma-separated lists
-  $re = '(?:' . do_commas($re) . ')';
+  $re = ($CaptureBrackets ? '(' : '(?:') . do_commas($re) . ')';
  }
  return $re;
 }
 
  }
  return $re;
 }
 
-=head2 C<wc2re_jokers>
+=head2 C<wc2re>
 
 
-This one only handles the C<?> and C<*> jokers. All other unquoted regexp metacharacters will be escaped.
+A generic function that wraps around all the different rules. The first argument is the wildcard expression, and the second one is the type of rules to apply which can be :
 
 
-    # Everything is escaped.
-    print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
+=over 4
 
 
-=cut
+=item C<'unix'>, C<'win32'>, C<'jokers'>
 
 
-sub wc2re_jokers {
- my ($wc) = @_;
- $wc =~ s/(?<!\\)((?:\\\\)*[^\w\s?*\\])/\\$1/g;
- return do_jokers($wc);
-}
+For one of those raw rule names, C<wc2re> simply maps to C<wc2re_unix>, C<wc2re_win32> and C<wc2re_jokers> respectively.
 
 
-=head2 C<wc2re>
+=item C<$^O>
+
+If you supply the Perl operating system name, the call is deferred to C<wc2re_win32> for C< $^O> equal to C<'dos'>, C<'os2'>, C<'MSWin32'> or C<'cygwin'>, and to C<wc2re_unix> in all the other cases.
+
+=back
+
+If the type is undefined or not supported, it defaults to C<'unix'>.
+
+     # Wraps to wc2re_jokers ($re eq 'a\\{b\\,c\\}.*').
+     $re = wc2re 'a{b,c}*' => 'jokers';
 
 
-A generic function that wraps around all the different rules. The first argument is the wildcard expression, and the second one is the type of rules to apply, currently either C<unix>, C<win32> or C<jokers>. If the type is undefined, it defaults to C<unix>.
+     # Wraps to wc2re_win32 ($re eq '(?:a\\{b|c\\}.*)')
+     #       or wc2re_unix  ($re eq 'a(?:b|c).*')       depending on $^O.
+     $re = wc2re 'a{b,c}*' => $^O;
 
 =cut
 
 my %types = (
 
 =cut
 
 my %types = (
- 'jokers' => \&wc2re_jokers,
- 'unix'   => \&wc2re_unix,
- 'win32'  => \&wc2re_win32
+ 'jokers'    => \&wc2re_jokers,
+ 'unix'      => \&wc2re_unix,
+ map { lc $_ => \&wc2re_win32 } qw/win32 dos os2 MSWin32 cygwin/
 );
 
 sub wc2re {
  my ($wc, $type) = @_;
  return unless defined $wc;
 );
 
 sub wc2re {
  my ($wc, $type) = @_;
  return unless defined $wc;
- $type ||= 'unix';
- return $types{lc $type}($wc);
+ $type = $type ? lc $type : 'unix';
+ $type = 'unix' unless exists $types{$type};
+ return $types{$type}($wc);
 }
 
 =head1 EXPORT
 
 }
 
 =head1 EXPORT
 
-These four functions are exported only on request : C<wc2re>, C<wc2re_unix>, C<wc2re_win32> and C<wc2re_jokers>.
+These four functions are exported only on request : C<wc2re>, C<wc2re_unix>, C<wc2re_win32> and C<wc2re_jokers>. The variables are not exported.
 
 =cut
 
 
 =cut
 
@@ -171,9 +245,12 @@ sub do_jokers {
  # escape an odd number of \ that doesn't protect a regexp/wildcard special char
  s/(?<!\\)((?:\\\\)*\\(?:[\w\s]|$))/\\$1/g;
  # substitute ? preceded by an even number of \
  # escape an odd number of \ that doesn't protect a regexp/wildcard special char
  s/(?<!\\)((?:\\\\)*\\(?:[\w\s]|$))/\\$1/g;
  # substitute ? preceded by an even number of \
- s/(?<!\\)((?:\\\\)*)\?/$1./g;
+ my $s = $CaptureSingle ? '(.)' : '.';
+ s/(?<!\\)((?:\\\\)*)\?/$1$s/g;
  # substitute * preceded by an even number of \
  # substitute * preceded by an even number of \
- s/(?<!\\)((?:\\\\)*)\*+/$1.*/g;
+ $s = $CaptureAny ? (($CaptureAny > 0) ? '(.*)' : '(.*?)')
+                  : '.*';
+ s/(?<!\\)((?:\\\\)*)\*+/$1$s/g;
  return $_;
 }
 
  return $_;
 }
 
@@ -193,7 +270,7 @@ sub do_brackets {
   $re .= do_commas($prefix) . do_brackets($bracket);
  }
  $re .= do_commas($rest);
   $re .= do_commas($prefix) . do_brackets($bracket);
  }
  $re .= do_commas($rest);
- return '(?:' . $re . ')';
+ return ($CaptureBrackets ? '(' : '(?:') . $re . ')';
 }
 
 sub do_bracketed {
 }
 
 sub do_bracketed {
index 4c6c3404e80d882c9184f9eb979a99f5e5957cc8..49a78909dd0b86fdb7cf4ad5e07ef71df96d6d09 100755 (executable)
@@ -3,9 +3,16 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
+use lib q:../lib/:;
+
 use Regexp::Wildcards qw/wc2re/;
 
 my $type = (grep $^O eq $_, qw/dos os2 MSWin32 cygwin/) ? 'win32' : 'unix';
 use Regexp::Wildcards qw/wc2re/;
 
 my $type = (grep $^O eq $_, qw/dos os2 MSWin32 cygwin/) ? 'win32' : 'unix';
-
 print "For this system, type is $type\n";
 print "For this system, type is $type\n";
-print $_, ' => ', wc2re($_ => $type), "\n" for @ARGV;
+
+{
+ local $Regexp::Wildcards::CaptureBrackets = 1;
+ local $Regexp::Wildcards::CaptureAny = -1;
+ print $_, ' => ', wc2re($_ => $^O), "\n" for @ARGV;
+}
+
diff --git a/t/02-wc2re.t b/t/02-wc2re.t
new file mode 100644 (file)
index 0000000..0d45ab7
--- /dev/null
@@ -0,0 +1,11 @@
+#!perl -T
+
+use Test::More tests => 10;
+
+use Regexp::Wildcards qw/wc2re wc2re_unix wc2re_win32/;
+
+for my $O (qw/win32 dos os2 cygwin/, 'MSWin32') {
+ for ('a{b,c}*', 'a?{b\\{,\\}c}') {
+  ok(wc2re($_, $O) eq wc2re_win32($_), $_ . ' (' . $O . ')');
+ }
+}
index 67a1fd8ac2b206f6d89039ea02c564e461857d5e..85c9ede9ce0b1e7de26dbf21205b97390da63397 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -T
 
 #!perl -T
 
-use Test::More tests => 3 * (4 + 2 + 9 + 2) * 3;
+use Test::More tests => 3 * (4 + 2 + 7 + 9 + 2) * 3;
 
 use Regexp::Wildcards qw/wc2re/;
 
 
 use Regexp::Wildcards qw/wc2re/;
 
@@ -31,6 +31,27 @@ for my $t (qw/unix win32 jokers/) {
  try $t, 'multiple *', '**', '.*';
  try $t, 'multiple ?', '??', '..';
 
  try $t, 'multiple *', '**', '.*';
  try $t, 'multiple ?', '??', '..';
 
+ # Variables
+
+ {
+  local $Regexp::Wildcards::CaptureSingle = 1;
+  try $t, 'multiple capturing ?', '??\\??', '(.)(.)\\?(.)';
+  local $Regexp::Wildcards::CaptureAny = 1;
+  try $t, 'multiple capturing * (greedy)', '**\\**', '(.*)\\*(.*)';
+  try $t, 'multiple capturing * (greedy) and capturing ?',
+          '**??\\??\\**', '(.*)(.)(.)\\?(.)\\*(.*)';
+  $Regexp::Wildcards::CaptureSingle = 0;
+  try $t, 'multiple capturing * (greedy) and non-capturing ?',
+          '**??\\??\\**', '(.*)..\\?.\\*(.*)';
+  $Regexp::Wildcards::CaptureAny = -1;
+  try $t, 'multiple capturing * (non-greedy)', '**\\**', '(.*?)\\*(.*?)';
+  try $t, 'multiple capturing * (non-greedy) and non-capturing ?',
+          '**??\\??\\**', '(.*?)..\\?.\\*(.*?)';
+  $Regexp::Wildcards::CaptureSingle = 1;
+  try $t, 'multiple capturing * (non-greedy) and capturing ?',
+          '**??\\??\\**', '(.*?)(.)(.)\\?(.)\\*(.*?)';
+ }
+
  # Escaping
 
  try $t, 'escaping *', '\\*';
  # Escaping
 
  try $t, 'escaping *', '\\*';