X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100_bugs%2F019_moose_octal_defaults.t;h=a05a170f47014e75f0de16031c1be47274142b97;hb=d004fa1854b6970442a2e764b72f54bb0b030050;hp=8cde1e4484b54c41828e6e434da0696bd7ca7d74;hpb=ff6d0a021bbd973257f9e911955e3ac6282e9af7;p=gitmo%2FMoose.git diff --git a/t/100_bugs/019_moose_octal_defaults.t b/t/100_bugs/019_moose_octal_defaults.t index 8cde1e4..a05a170 100644 --- a/t/100_bugs/019_moose_octal_defaults.t +++ b/t/100_bugs/019_moose_octal_defaults.t @@ -1,7 +1,8 @@ #!/usr/bin/env perl -use Test::More qw(no_plan); +use Test::More; -my $package = qq{ +{ + my $package = qq{ package Test::Moose::Go::Boom; use Moose; use lib qw(lib); @@ -9,7 +10,7 @@ use lib qw(lib); has id => ( isa => 'Str', is => 'ro', - default => '019600', # Moose doesn't quote this when inlining, an perl treats it as an octal ... and 9 isn't a valid octal + default => '019600', # this caused the original failure ); no Moose; @@ -17,12 +18,14 @@ no Moose; __PACKAGE__->meta->make_immutable; }; -eval $package; -$@ ? ::fail($@) : ::pass('quoted 019600 default works'); -my $obj = Test::Moose::Go::Boom->new; -::is($obj->id, '019600', 'value is still the same'); + eval $package; + $@ ? ::fail($@) : ::pass('quoted 019600 default works'); + my $obj = Test::Moose::Go::Boom->new; + ::is( $obj->id, '019600', 'value is still the same' ); +} -my $package2 = qq{ +{ + my $package = qq{ package Test::Moose::Go::Boom2; use Moose; use lib qw(lib); @@ -30,7 +33,7 @@ use lib qw(lib); has id => ( isa => 'Str', is => 'ro', - default => 017600, # Moose doesn't quote this when inlining, an perl treats it as an octal ... and 9 isn't a valid octal + default => 017600, ); no Moose; @@ -38,8 +41,79 @@ no Moose; __PACKAGE__->meta->make_immutable; }; + eval $package; + $@ ? ::fail($@) : ::pass('017600 octal default works'); + my $obj = Test::Moose::Go::Boom2->new; + ::is( $obj->id, 8064, 'value is still the same' ); +} -eval $package2; -$@ ? ::fail($@) : ::pass('017600 octal default works'); -my $obj = Test::Moose::Go::Boom2->new; -::is($obj->id, 8064, 'value is still the same'); \ No newline at end of file +{ + my $package = qq{ +package Test::Moose::Go::Boom3; +use Moose; +use lib qw(lib); + +has id => ( + isa => 'Str', + is => 'ro', + default => 0xFF, +); + +no Moose; + +__PACKAGE__->meta->make_immutable; +}; + + eval $package; + $@ ? ::fail($@) : ::pass('017600 octal default works'); + my $obj = Test::Moose::Go::Boom3->new; + ::is( $obj->id, 255, 'value is still the same' ); +} + +{ + my $package = qq{ +package Test::Moose::Go::Boom4; +use Moose; +use lib qw(lib); + +has id => ( + isa => 'Str', + is => 'ro', + default => '0xFF', +); + +no Moose; + +__PACKAGE__->meta->make_immutable; +}; + + eval $package; + $@ ? ::fail($@) : ::pass('017600 octal default works'); + my $obj = Test::Moose::Go::Boom4->new; + ::is( $obj->id, '0xFF', 'value is still the same' ); +} + +{ + my $package = qq{ +package Test::Moose::Go::Boom5; +use Moose; +use lib qw(lib); + +has id => ( + isa => 'Str', + is => 'ro', + default => '0 but true', +); + +no Moose; + +__PACKAGE__->meta->make_immutable; +}; + + eval $package; + $@ ? ::fail($@) : ::pass('017600 octal default works'); + my $obj = Test::Moose::Go::Boom5->new; + ::is( $obj->id, '0 but true', 'value is still the same' ); +} + +done_testing;