This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fixup new hash benchmarks to be lighter
[perl5.git] / t / mro / overload_c3.t
1 #!./perl
2
3 use strict;
4 use warnings;
5 BEGIN {
6     unless (-d 'blib') {
7         chdir 't' if -d 't';
8     }
9     require q(./test.pl);
10     set_up_inc('../lib');
11 }
12
13 plan(tests => 7);
14
15 {
16     package BaseTest;
17     use strict;
18     use warnings;
19     use mro 'c3';
20     
21     package OverloadingTest;
22     use strict;
23     use warnings;
24     use mro 'c3';
25     use base 'BaseTest';        
26     use overload '""' => sub { ref(shift) . " stringified" },
27                  fallback => 1;
28     
29     sub new { bless {} => shift }    
30     
31     package InheritingFromOverloadedTest;
32     use strict;
33     use warnings;
34     use base 'OverloadingTest';
35     use mro 'c3';
36 }
37
38 my $x = InheritingFromOverloadedTest->new();
39 object_ok($x, 'InheritingFromOverloadedTest');
40
41 my $y = OverloadingTest->new();
42 object_ok($y, 'OverloadingTest');
43
44 is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
45 is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
46
47 ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
48
49 my $result;
50 eval { 
51     $result = $x eq 'InheritingFromOverloadedTest stringified' 
52 };
53 ok(!$@, '... this should not throw an exception');
54 ok($result, '... and we should get the true value');
55