summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/lib/Test/Simple/t/overload.t
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/lib/Test/Simple/t/overload.t')
-rwxr-xr-xgnu/usr.bin/perl/lib/Test/Simple/t/overload.t34
1 files changed, 21 insertions, 13 deletions
diff --git a/gnu/usr.bin/perl/lib/Test/Simple/t/overload.t b/gnu/usr.bin/perl/lib/Test/Simple/t/overload.t
index e0e70d42296..fb74c59b078 100755
--- a/gnu/usr.bin/perl/lib/Test/Simple/t/overload.t
+++ b/gnu/usr.bin/perl/lib/Test/Simple/t/overload.t
@@ -1,4 +1,5 @@
#!/usr/bin/perl -w
+# $Id: overload.t,v 1.2 2009/05/16 21:42:57 simon Exp $
BEGIN {
if( $ENV{PERL_CORE} ) {
@@ -11,38 +12,45 @@ BEGIN {
}
use strict;
-use Test::More;
-
-BEGIN {
- if( !eval "require overload" ) {
- plan skip_all => "needs overload.pm";
- }
- else {
- plan tests => 13;
- }
-}
+use Test::More tests => 15;
package Overloaded;
use overload
- q{""} => sub { $_[0]->{string} },
- q{0+} => sub { $_[0]->{num} };
+ q{eq} => sub { $_[0]->{string} },
+ q{==} => sub { $_[0]->{num} },
+ q{""} => sub { $_[0]->{stringfy}++; $_[0]->{string} },
+ q{0+} => sub { $_[0]->{numify}++; $_[0]->{num} }
+;
sub new {
my $class = shift;
- bless { string => shift, num => shift }, $class;
+ bless {
+ string => shift,
+ num => shift,
+ stringify => 0,
+ numify => 0,
+ }, $class;
}
package main;
+local $SIG{__DIE__} = sub {
+ my($call_file, $call_line) = (caller)[1,2];
+ fail("SIGDIE accidentally called");
+ diag("From $call_file at $call_line");
+};
+
my $obj = Overloaded->new('foo', 42);
isa_ok $obj, 'Overloaded';
is $obj, 'foo', 'is() with string overloading';
cmp_ok $obj, 'eq', 'foo', 'cmp_ok() ...';
+is $obj->{stringify}, 0, 'cmp_ok() eq does not stringify';
cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading';
+is $obj->{numify}, 0, 'cmp_ok() == does not numify';
is_deeply [$obj], ['foo'], 'is_deeply with string overloading';
ok eq_array([$obj], ['foo']), 'eq_array ...';