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