X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F24-anchors.t;fp=t%2F24-anchors.t;h=5412cae5a5097990cf41a4561eac67daf7e98134;hb=99cec79018d12958619028d1e21bf7f41eacbd17;hp=0000000000000000000000000000000000000000;hpb=b89ade7968f3dfcf54d1c830f1ecdfd09731a412;p=perl%2Fmodules%2FRegexp-Wildcards.git diff --git a/t/24-anchors.t b/t/24-anchors.t new file mode 100644 index 0000000..5412cae --- /dev/null +++ b/t/24-anchors.t @@ -0,0 +1,35 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 16; + +use Regexp::Wildcards; + +my $rw = Regexp::Wildcards->new(do => 'anchors'); + +is($rw->convert('\\^'), '\\^', 'anchor: escape ^ 1'); +is($rw->convert('\\\\\\^'), '\\\\\\^', 'anchor: escape ^ 2'); +is($rw->convert('\\$'), '\\$', 'anchor: escape $ 1'); +is($rw->convert('\\\\\\$'), '\\\\\\$', 'anchor: escape $ 2'); + +is($rw->convert('^a?b*'), '^a\\?b\\*', 'anchor: ^'); +is($rw->convert('a?b*$'), 'a\\?b\\*$', 'anchor: $'); +is($rw->convert('^a?b*$'), '^a\\?b\\*$', 'anchor: ^$'); +is($rw->convert('x^a?b*$y'), 'x^a\\?b\\*$y', 'anchor: intermediate ^$'); + +$rw->do(add => 'jokers'); + +is($rw->convert('^a?b*'), '^a.b.*', 'anchor: ^ with jokers'); +is($rw->convert('a?b*$'), 'a.b.*$', 'anchor: $ with jokers'); +is($rw->convert('^a?b*$'), '^a.b.*$', 'anchor: ^$ with jokers'); +is($rw->convert('x^a?b*$y'), 'x^a.b.*$y','anchor: intermediate ^$ with jokers'); + +$rw->do(add => 'brackets'); + +is($rw->convert('{^,a}?b*'), '(?:^|a).b.*', 'anchor: ^ with brackets'); +is($rw->convert('a?{b*,$}'), 'a.(?:b.*|$)', 'anchor: $ with brackets'); +is($rw->convert('{^a,?}{b,*$}'),'(?:^a|.)(?:b|.*$)','anchor: ^$ with brackets'); +is($rw->convert('x{^,a}?b{*,$}y'), 'x(?:^|a).b(?:.*|$)y', + 'anchor: intermediate ^$ with brackets');