Fix prototype on message {...}
[gitmo/Mouse.git] / t / 008-default.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 18;
5
6do {
7 package Class;
8 use Mouse;
9
10 has 'x' => (
11 is => 'rw',
12 default => 10,
13 );
14
15 has 'y' => (
16 is => 'rw',
17 default => 20,
18 );
19
20 has 'z' => (
21 is => 'rw',
22 );
23};
24
25my $object = Class->new;
26is($object->x, 10, "attribute has a default of 10");
27is($object->y, 20, "attribute has a default of 20");
28is($object->z, undef, "attribute has no default");
29
30is($object->x(5), 5, "setting a new value");
31is($object->y(25), 25, "setting a new value");
32is($object->z(125), 125, "setting a new value");
33
34is($object->x, 5, "setting a new value does not trigger default");
35is($object->y, 25, "setting a new value does not trigger default");
36is($object->z, 125, "setting a new value does not trigger default");
37
38my $object2 = Class->new(x => 50);
39is($object2->x, 50, "attribute was initialized to 50");
40is($object2->y, 20, "attribute has a default of 20");
41is($object2->z, undef, "attribute has no default");
42
43is($object2->x(5), 5, "setting a new value");
44is($object2->y(25), 25, "setting a new value");
45is($object2->z(125), 125, "setting a new value");
46
47is($object2->x, 5, "setting a new value does not trigger default");
48is($object2->y, 25, "setting a new value does not trigger default");
49is($object2->z, 125, "setting a new value does not trigger default");
50