| File: | t/20-moo.t |
| Coverage: | 100.0% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!perl | ||||||
| 2 | |||||||
| 3 | 3 3 3 | 6802 139077 11 | use Test::Most; | ||||
| 4 | |||||||
| 5 | 3 3 3 | 50179 984 9 | use lib 't/lib'; | ||||
| 6 | 3 3 3 | 589 5 3888 | use MooTest; | ||||
| 7 | |||||||
| 8 | 3 | 181113 | ok my $o = MooTest->new; | ||||
| 9 | |||||||
| 10 | lives_ok { | ||||||
| 11 | 3 | 104 | ++$o->foo->[0]; | ||||
| 12 | 3 | 1042 | } 'allowed change of array element'; | ||||
| 13 | |||||||
| 14 | 3 | 757 | is $o->foo->[0] => 2, 'element was changed'; | ||||
| 15 | |||||||
| 16 | dies_ok { | ||||||
| 17 | 3 | 116 | ++$o->bar->[0]; | ||||
| 18 | 3 | 665 | } 'disallowed change of array element'; | ||||
| 19 | |||||||
| 20 | 3 | 613 | is $o->bar->[0] => 1, 'element was not changed'; | ||||
| 21 | |||||||
| 22 | lives_ok { | ||||||
| 23 | |||||||
| 24 | 3 | 130 | $o->bo( { a => 1, b => 2 } ); | ||||
| 25 | |||||||
| 26 | 3 | 623 | } 'set a write-once attribute'; | ||||
| 27 | |||||||
| 28 | dies_ok { | ||||||
| 29 | |||||||
| 30 | 3 | 121 | ++$o->bo->{a}; | ||||
| 31 | |||||||
| 32 | 3 | 2531 | } 'cannot write again to a write-once attribute'; | ||||
| 33 | |||||||
| 34 | 3 | 657 | done_testing; | ||||