Implement strict constructors, which will warn unkown constructor arguments
[gitmo/Mouse.git] / t / 100_bugs / 019_moose_octal_defaults.t
1 #!/usr/bin/env perl
2 use Test::More tests => 10;
3
4 {
5     my $package = qq{
6 package Test::Mouse::Go::Boom;
7 use Mouse;
8 use lib qw(lib);
9
10 has id => (
11     isa     => 'Str',
12     is      => 'ro',
13     default => '019600', # this caused the original failure
14 );
15
16 no Mouse;
17
18 __PACKAGE__->meta->make_immutable;
19 };
20
21     eval $package;
22     $@ ? ::fail($@) : ::pass('quoted 019600 default works');
23     my $obj = Test::Mouse::Go::Boom->new;
24     ::is( $obj->id, '019600', 'value is still the same' );
25 }
26
27 {
28     my $package = qq{
29 package Test::Mouse::Go::Boom2;
30 use Mouse;
31 use lib qw(lib);
32
33 has id => (
34     isa     => 'Str',
35     is      => 'ro',
36     default => 017600,
37 );
38
39 no Mouse;
40
41 __PACKAGE__->meta->make_immutable;
42 };
43
44     eval $package;
45     $@ ? ::fail($@) : ::pass('017600 octal default works');
46     my $obj = Test::Mouse::Go::Boom2->new;
47     ::is( $obj->id, 8064, 'value is still the same' );
48 }
49
50 {
51     my $package = qq{
52 package Test::Mouse::Go::Boom3;
53 use Mouse;
54 use lib qw(lib);
55
56 has id => (
57     isa     => 'Str',
58     is      => 'ro',
59     default => 0xFF,
60 );
61
62 no Mouse;
63
64 __PACKAGE__->meta->make_immutable;
65 };
66
67     eval $package;
68     $@ ? ::fail($@) : ::pass('017600 octal default works');
69     my $obj = Test::Mouse::Go::Boom3->new;
70     ::is( $obj->id, 255, 'value is still the same' );
71 }
72
73 {
74     my $package = qq{
75 package Test::Mouse::Go::Boom4;
76 use Mouse;
77 use lib qw(lib);
78
79 has id => (
80     isa     => 'Str',
81     is      => 'ro',
82     default => '0xFF',
83 );
84
85 no Mouse;
86
87 __PACKAGE__->meta->make_immutable;
88 };
89
90     eval $package;
91     $@ ? ::fail($@) : ::pass('017600 octal default works');
92     my $obj = Test::Mouse::Go::Boom4->new;
93     ::is( $obj->id, '0xFF', 'value is still the same' );
94 }
95
96 {
97     my $package = qq{
98 package Test::Mouse::Go::Boom5;
99 use Mouse;
100 use lib qw(lib);
101
102 has id => (
103     isa     => 'Str',
104     is      => 'ro',
105     default => '0 but true',
106 );
107
108 no Mouse;
109
110 __PACKAGE__->meta->make_immutable;
111 };
112
113     eval $package;
114     $@ ? ::fail($@) : ::pass('017600 octal default works');
115     my $obj = Test::Mouse::Go::Boom5->new;
116     ::is( $obj->id, '0 but true', 'value is still the same' );
117 }