File: basic.t

package info (click to toggle)
libmoox-thunking-perl 0.08-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 112 kB
  • sloc: perl: 79; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use Test::More;

package Thunking;
use Moo;
use Test::More; BEGIN { use_ok('MooX::Thunking') }
use Types::Standard -all;
use Types::TypeTiny -all;
has children => (
  is => 'thunked',
  isa => ArrayRef[InstanceOf['Thunking']],
  required => 1,
);

package main;
my $obj;
$obj = Thunking->new(children => sub { [$obj] });
is_deeply $obj->children, [ $obj ];

$obj = Thunking->new(children => [$obj]);
$@ = '';
is_deeply $obj->children, [ $obj ];
is $@, '', '$@ still empty';

$obj = Thunking->new(children => sub { { key => 'delayed wrong type' } });
eval { $obj->children };
isnt $@, '', 'exception on wrong type from thunk';

eval { Thunking->new(children => { key => 'wrong type' }) };
isnt $@, '', 'exception on wrong type';

done_testing;