22-brackets.t 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!perl -T
  2. use strict;
  3. use warnings;
  4. use Test::More tests => 27;
  5. use Regexp::Wildcards;
  6. my $rw = Regexp::Wildcards->new(qw<do brackets>);
  7. is($rw->convert('a{b\\\\,c\\\\}d', 'jokers'), 'a\\{b\\\\\\,c\\\\\\}d','jokers');
  8. is($rw->convert('a{b\\\\,c\\\\}d', 'sql'), 'a\\{b\\\\\\,c\\\\\\}d', 'sql');
  9. is($rw->convert('a{b\\\\,c\\\\}d', 'win32'), '(?:a\\{b\\\\|c\\\\\\}d)','win32');
  10. is($rw->convert('{}'), '(?:)', 'empty brackets');
  11. is($rw->convert('{a}'), '(?:a)', 'brackets 1');
  12. is($rw->convert('{a,b}'), '(?:a|b)', 'brackets 2');
  13. is($rw->convert('{a,b,c}'), '(?:a|b|c)', 'brackets 3');
  14. is($rw->convert('a{b,c}d'), 'a(?:b|c)d',
  15. '1 bracketed block');
  16. is($rw->convert('a{b,c}d{e,,f}'), 'a(?:b|c)d(?:e||f)',
  17. '2 bracketed blocks');
  18. is($rw->convert('a{b,c}d{e,,f}{g,h,}'), 'a(?:b|c)d(?:e||f)(?:g|h|)',
  19. '3 bracketed blocks');
  20. is($rw->convert('{a{b}}'), '(?:a(?:b))',
  21. '2 nested bracketed blocks 1');
  22. is($rw->convert('{a,{b},c}'), '(?:a|(?:b)|c)',
  23. '2 nested bracketed blocks 2');
  24. is($rw->convert('{a,{b{d}e},c}'), '(?:a|(?:b(?:d)e)|c)',
  25. '3 nested bracketed blocks');
  26. is($rw->convert('{a,{b{d{}}e,f,,},c}'), '(?:a|(?:b(?:d(?:))e|f||)|c)',
  27. '4 nested bracketed blocks');
  28. is($rw->convert('{a,{b{d{}}e,f,,},c}{,g{{}h,i}}'), '(?:a|(?:b(?:d(?:))e|f||)|c)(?:|g(?:(?:)h|i))',
  29. '4+3 nested bracketed blocks');
  30. is($rw->convert('\\{\\\\}'), '\\{\\\\\\}',
  31. 'escaping brackets');
  32. is($rw->convert('\\{a,b,c\\\\\\}'), '\\{a\\,b\\,c\\\\\\}',
  33. 'escaping commas 1');
  34. is($rw->convert('\\{a\\\\,b\\,c}'), '\\{a\\\\\\,b\\,c\\}',
  35. 'escaping commas 2');
  36. is($rw->convert('\\{a\\\\,b\\,c\\}'), '\\{a\\\\\\,b\\,c\\}',
  37. 'escaping commas 3');
  38. is($rw->convert('\\{a\\\\,b\\,c\\\\}'), '\\{a\\\\\\,b\\,c\\\\\\}',
  39. 'escaping brackets and commas');
  40. is($rw->convert('{a\\},b\\{,c}'), '(?:a\\}|b\\{|c)',
  41. 'overlapping brackets');
  42. is($rw->convert('{a\\{b,c}d,e}'), '(?:a\\{b|c)d\\,e\\}',
  43. 'partial unbalanced catching 1');
  44. is($rw->convert('{a\\{\\\\}b,c\\\\}'), '(?:a\\{\\\\)b\\,c\\\\\\}',
  45. 'partial unbalanced catching 2');
  46. is($rw->convert('{a{b,c\\}d,e}'), '\\{a\\{b\\,c\\}d\\,e\\}',
  47. 'no partial unbalanced catching');
  48. is($rw->convert('{a,\\{,\\},b}'), '(?:a|\\{|\\}|b)',
  49. 'substituting commas 1');
  50. is($rw->convert('{a,\\{d,e,,\\}b,c}'), '(?:a|\\{d|e||\\}b|c)',
  51. 'substituting commas 2');
  52. is($rw->convert('{a,\\{d,e,,\\}b,c}\\\\{f,g,h,i}'), '(?:a|\\{d|e||\\}b|c)\\\\(?:f|g|h|i)',
  53. 'handling the rest');