This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert Data::Dumper's overload.t to Test::More
[perl5.git] / dist / Data-Dumper / t / bless.t
1 #!perl
2
3 use Test::More 0.60;
4
5 # Test::More 0.60 required because:
6 # - is_deeply(undef, $not_undef); now works. [rt.cpan.org 9441]
7
8 BEGIN { plan tests => 1+5*2; }
9
10 BEGIN { use_ok('Data::Dumper') };
11
12 # RT 39420: Data::Dumper fails to escape bless class name
13
14 # test under XS and pure Perl version
15 foreach $Data::Dumper::Useperl (0, 1) {
16
17 #diag("\$Data::Dumper::Useperl = $Data::Dumper::Useperl");
18
19 {
20 my $t = bless( {}, q{a'b} );
21 my $dt = Dumper($t);
22 my $o = <<'PERL';
23 $VAR1 = bless( {}, 'a\'b' );
24 PERL
25
26 is($dt, $o, "package name in bless is escaped if needed");
27 is_deeply(scalar eval($dt), $t, "eval reverts dump");
28 }
29
30 {
31 my $t = bless( {}, q{a\\} );
32 my $dt = Dumper($t);
33 my $o = <<'PERL';
34 $VAR1 = bless( {}, 'a\\' );
35 PERL
36
37 is($dt, $o, "package name in bless is escaped if needed");
38 is_deeply(scalar eval($dt), $t, "eval reverts dump");
39 }
40 SKIP: {
41     skip(q/no 're::regexp_pattern'/, 1)
42         if ! defined(*re::regexp_pattern{CODE});
43
44 my $t = bless( qr//, 'foo');
45 my $dt = Dumper($t);
46 my $o = ($] >= 5.013006 ? <<'PERL' : <<'PERL_LEGACY');
47 $VAR1 = bless( qr/(?^:)/, 'foo' );
48 PERL
49 $VAR1 = bless( qr/(?-xism:)/, 'foo' );
50 PERL_LEGACY
51
52 is($dt, $o, "We can dump blessed qr//'s properly");
53
54 }
55 }