X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbugs%2Fmoose_octal_defaults.t;fp=t%2Fbugs%2Fmoose_octal_defaults.t;h=a05a170f47014e75f0de16031c1be47274142b97;hb=829433c47061dd70a608bfcd940113c4172b6950;hp=0000000000000000000000000000000000000000;hpb=51c788414482c813eb48fb417b08ba03134ff1a6;p=gitmo%2FMoose.git diff --git a/t/bugs/moose_octal_defaults.t b/t/bugs/moose_octal_defaults.t new file mode 100644 index 0000000..a05a170 --- /dev/null +++ b/t/bugs/moose_octal_defaults.t @@ -0,0 +1,119 @@ +#!/usr/bin/env perl +use Test::More; + +{ + my $package = qq{ +package Test::Moose::Go::Boom; +use Moose; +use lib qw(lib); + +has id => ( + isa => 'Str', + is => 'ro', + default => '019600', # this caused the original failure +); + +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' ); +} + +{ + my $package = qq{ +package Test::Moose::Go::Boom2; +use Moose; +use lib qw(lib); + +has id => ( + isa => 'Str', + is => 'ro', + default => 017600, +); + +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' ); +} + +{ + 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;