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