10-obj.t 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!perl -T
  2. use strict;
  3. use warnings;
  4. use Test::More tests => 24;
  5. use Regexp::Wildcards;
  6. my $rw = Regexp::Wildcards->new;
  7. ok(defined $rw, 'RW object is defined');
  8. is(ref $rw, 'Regexp::Wildcards', 'RW object is valid');
  9. my $rw2 = $rw->new;
  10. ok(defined $rw2, 'RW::new called as an object method works' );
  11. is(ref $rw2, 'Regexp::Wildcards', 'RW::new called as an object method works is valid');
  12. $rw2 = Regexp::Wildcards::new();
  13. ok(defined $rw2, 'RW::new called without a class works');
  14. is(ref $rw2, 'Regexp::Wildcards', 'RW::new called without a class is valid');
  15. eval { $rw2 = Regexp::Wildcards->new(qw<a b c>) };
  16. like($@, qr/Optional\s+arguments/, 'RW::new gets parameters as key => value pairs');
  17. my $fake = { };
  18. bless $fake, 'Regexp::Wildcards::Hlagh';
  19. for (qw<do capture type convert>) {
  20. eval "Regexp::Wildcards::$_('Regexp::Wildcards')";
  21. like($@, qr/^First\s+argument/, "RW::$_ isn't a class method");
  22. eval "Regexp::Wildcards::$_(\$fake)";
  23. like($@, qr/^First\s+argument/, "RW::$_ only applies to RW objects");
  24. }
  25. for (qw<do capture>) {
  26. eval { $rw->$_(sub { 'dongs' }) };
  27. like($@, qr/Wrong\s+option\s+set/, "RW::$_ don't want code references");
  28. eval { $rw->$_(\*STDERR) };
  29. like($@, qr/Wrong\s+option\s+set/, "RW::$_ don't want globs");
  30. eval { $rw->$_(qw<a b c>) };
  31. like($@, qr/Arguments\s+must\s+be\s+passed.*unique\s+scalar.*key\s+=>\s+value\s+pairs/, "RW::$_ gets parameters after the first as key => value pairs");
  32. }
  33. eval { $rw->type('monkey!') };
  34. like($@, qr/Wrong\s+type/, 'RW::type wants a type it knows');
  35. eval { $rw->convert(undef, 'again monkey!') };
  36. like($@, qr/Wrong\s+type/, 'RW::convert wants a type it knows');
  37. for (qw<convert>) {
  38. ok(!defined $rw->$_(undef), "RW::$_ returns undef when passed undef");
  39. }