24-anchors.t 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!perl -T
  2. use strict;
  3. use warnings;
  4. use Test::More tests => 16;
  5. use Regexp::Wildcards;
  6. my $rw = Regexp::Wildcards->new(do => 'anchors');
  7. is($rw->convert('\\^'), '\\^', 'anchor: escape ^ 1');
  8. is($rw->convert('\\\\\\^'), '\\\\\\^', 'anchor: escape ^ 2');
  9. is($rw->convert('\\$'), '\\$', 'anchor: escape $ 1');
  10. is($rw->convert('\\\\\\$'), '\\\\\\$', 'anchor: escape $ 2');
  11. is($rw->convert('^a?b*'), '^a\\?b\\*', 'anchor: ^');
  12. is($rw->convert('a?b*$'), 'a\\?b\\*$', 'anchor: $');
  13. is($rw->convert('^a?b*$'), '^a\\?b\\*$', 'anchor: ^$');
  14. is($rw->convert('x^a?b*$y'), 'x^a\\?b\\*$y', 'anchor: intermediate ^$');
  15. $rw->do(add => 'jokers');
  16. is($rw->convert('^a?b*'), '^a.b.*', 'anchor: ^ with jokers');
  17. is($rw->convert('a?b*$'), 'a.b.*$', 'anchor: $ with jokers');
  18. is($rw->convert('^a?b*$'), '^a.b.*$', 'anchor: ^$ with jokers');
  19. is($rw->convert('x^a?b*$y'), 'x^a.b.*$y','anchor: intermediate ^$ with jokers');
  20. $rw->do(add => 'brackets');
  21. is($rw->convert('{^,a}?b*'), '(?:^|a).b.*', 'anchor: ^ with brackets');
  22. is($rw->convert('a?{b*,$}'), 'a.(?:b.*|$)', 'anchor: $ with brackets');
  23. is($rw->convert('{^a,?}{b,*$}'),'(?:^a|.)(?:b|.*$)','anchor: ^$ with brackets');
  24. is($rw->convert('x{^,a}?b{*,$}y'), 'x(?:^|a).b(?:.*|$)y',
  25. 'anchor: intermediate ^$ with brackets');