Implement strict constructors, which will warn unkown constructor arguments
[gitmo/Mouse.git] / t / 100_bugs / 019_moose_octal_defaults.t
CommitLineData
4c98ebb0 1#!/usr/bin/env perl
2use Test::More tests => 10;
3
4{
5 my $package = qq{
6package Test::Mouse::Go::Boom;
7use Mouse;
8use lib qw(lib);
9
10has id => (
11 isa => 'Str',
12 is => 'ro',
13 default => '019600', # this caused the original failure
14);
15
16no 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{
29package Test::Mouse::Go::Boom2;
30use Mouse;
31use lib qw(lib);
32
33has id => (
34 isa => 'Str',
35 is => 'ro',
36 default => 017600,
37);
38
39no 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{
52package Test::Mouse::Go::Boom3;
53use Mouse;
54use lib qw(lib);
55
56has id => (
57 isa => 'Str',
58 is => 'ro',
59 default => 0xFF,
60);
61
62no 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{
75package Test::Mouse::Go::Boom4;
76use Mouse;
77use lib qw(lib);
78
79has id => (
80 isa => 'Str',
81 is => 'ro',
82 default => '0xFF',
83);
84
85no 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{
98package Test::Mouse::Go::Boom5;
99use Mouse;
100use lib qw(lib);
101
102has id => (
103 isa => 'Str',
104 is => 'ro',
105 default => '0 but true',
106);
107
108no 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}