19199856eb2b01cabde08bbfc48538209d73983d
[gitmo/Moose.git] / t / 070_attribute_helpers / 208_trait_bool.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7 use Moose::AttributeHelpers;
8
9 {
10
11     package Room;
12     use Moose;
13     has 'is_lit' => (
14         traits  => ['Bool'],
15         is      => 'rw',
16         isa     => 'Bool',
17         default => 0,
18         handles => {
19             illuminate  => 'set',
20             darken      => 'unset',
21             flip_switch => 'toggle',
22             is_dark     => 'not',
23         },
24         )
25 }
26
27 my $room = Room->new;
28 $room->illuminate;
29 ok( $room->is_lit, 'set is_lit to 1 using ->illuminate' );
30 ok( !$room->is_dark, 'check if is_dark does the right thing' );
31
32 $room->darken;
33 ok( !$room->is_lit, 'set is_lit to 0 using ->darken' );
34 ok( $room->is_dark, 'check if is_dark does the right thing' );
35
36 $room->flip_switch;
37 ok( $room->is_lit, 'toggle is_lit back to 1 using ->flip_switch' );
38 ok( !$room->is_dark, 'check if is_dark does the right thing' );
39
40 $room->flip_switch;
41 ok( !$room->is_lit, 'toggle is_lit back to 0 again using ->flip_switch' );
42 ok( $room->is_dark, 'check if is_dark does the right thing' );
43