68a0ae509e2641b4eaf8e8ce65c8a5fa36630228
[gitmo/Role-Tiny.git] / t / accessor-reader-writer.t
1 use strictures 1;
2 use Test::More;
3
4 my @result;
5
6 {
7   package Foo;
8
9   use Moo;
10
11   has one => (
12     is     => 'rw',
13     reader => 'get_one',
14     writer => 'set_one',
15   );
16 }
17
18 {
19   package Bar;
20
21   use Moo;
22
23   has two => (
24     is     => 'rw',
25     accessor => 'TWO',
26   );
27 }
28
29 my $foo = Foo->new(one => 'lol');
30 my $bar = Bar->new(two => '...');
31
32 is( $foo->get_one, 'lol', 'reader works' );
33 $foo->set_one('rofl');
34 is( $foo->get_one, 'rofl', 'writer works' );
35
36 ok( !eval { $foo->get_one('blah'); 1 }, 'reader dies on write' );
37
38 is( $bar->TWO, '...', 'accessor works for reading' );
39 $bar->TWO('!!!');
40 is( $bar->TWO, '!!!', 'accessor works for writing' );
41
42 done_testing;