X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FRegexp-Wildcards.git;a=blobdiff_plain;f=t%2F10-jokers.t;h=0ce769e50eb7fa1e8cb1ddff5cb8beb407364671;hp=85c9ede9ce0b1e7de26dbf21205b97390da63397;hb=3426f55fba3da9c8801930f82107eeac9f1f8339;hpb=03007c83b1d852b1f2120c7aa500c36607d30e72 diff --git a/t/10-jokers.t b/t/10-jokers.t index 85c9ede..0ce769e 100644 --- a/t/10-jokers.t +++ b/t/10-jokers.t @@ -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', '_', '%';