4 use warnings; |
4 use warnings; |
5 use Test::More; |
5 use Test::More; |
6 use Test::Exception; |
6 use Test::Exception; |
7 |
7 |
8 use_ok 'Scalar::RefType' or BAIL_OUT q{Can't load the module}; |
8 use_ok 'Scalar::RefType' or BAIL_OUT q{Can't load the module}; |
9 isa_ok tie(my $h => 'Scalar::RefType', {}) => 'Scalar::RefType'; |
|
10 isa_ok tie(my $a => 'Scalar::RefType', []) => 'Scalar::RefType'; |
|
11 isa_ok tie(my $s => 'Scalar::RefType', \(undef)) => 'Scalar::RefType'; |
|
12 isa_ok tie(my $p => 'Scalar::RefType', undef) => 'Scalar::RefType'; |
|
13 |
9 |
14 subtest 'NAMES' => sub { |
10 subtest 'NAMES' => sub { |
15 isa_ok tie(my $h => 'Scalar::RefType', ref {}) => 'Scalar::RefType'; |
11 isa_ok tie(my $h => 'Scalar::RefType', ref {}) => 'Scalar::RefType'; |
16 isa_ok tie(my $a => 'Scalar::RefType', ref []) => 'Scalar::RefType'; |
12 isa_ok tie(my $a => 'Scalar::RefType', ref []) => 'Scalar::RefType'; |
17 isa_ok tie(my $s => 'Scalar::RefType', ref \(undef)) => 'Scalar::RefType'; |
13 isa_ok tie(my $s => 'Scalar::RefType', ref \(undef)) => 'Scalar::RefType'; |
18 isa_ok tie(my $p => 'Scalar::RefType', '') => 'Scalar::RefType'; |
14 isa_ok tie(my $p => 'Scalar::RefType', '') => 'Scalar::RefType'; |
19 |
15 |
20 is tied($h)->{type}, 'HASH' => 'is a hash ref'; |
16 is tied($h)->{type}, 'HASH' => 'is a hash ref'; |
21 is tied($a)->{type}, 'ARRAY' => 'is a array ref'; |
17 is tied($a)->{type}, 'ARRAY' => 'is a array ref'; |
22 is tied($s)->{type}, 'SCALAR' => 'is a scalar'; |
18 is tied($s)->{type}, 'SCALAR' => 'is a scalar'; |
23 is tied($p)->{type}, '' => 'is a "plain"'; |
19 is tied($p)->{type}, '' => 'is a "plain"'; |
24 |
20 |
25 }; |
21 }; |
|
22 |
|
23 subtest 'AUTO' => sub { |
|
24 isa_ok tie(my $x => 'Scalar::RefType') => 'Scalar::RefType'; |
|
25 ok $x = {} => 'hash: assignment'; |
|
26 is tied($x)->{type}, 'HASH' => 'hash: type'; |
|
27 throws_ok { $x = [] } qr/invalid/ => 'invalid type assignment'; |
|
28 }; |
|
29 |
|
30 isa_ok tie(my $h => 'Scalar::RefType', {}) => 'Scalar::RefType'; |
|
31 isa_ok tie(my $a => 'Scalar::RefType', []) => 'Scalar::RefType'; |
|
32 isa_ok tie(my $s => 'Scalar::RefType', \(undef)) => 'Scalar::RefType'; |
|
33 isa_ok tie(my $p => 'Scalar::RefType', undef) => 'Scalar::RefType'; |
26 |
34 |
27 is tied($h)->{type}, 'HASH' => 'is a hash ref'; |
35 is tied($h)->{type}, 'HASH' => 'is a hash ref'; |
28 is tied($a)->{type}, 'ARRAY' => 'is a array ref'; |
36 is tied($a)->{type}, 'ARRAY' => 'is a array ref'; |
29 is tied($s)->{type}, 'SCALAR' => 'is a scalar'; |
37 is tied($s)->{type}, 'SCALAR' => 'is a scalar'; |
30 is tied($p)->{type}, '' => 'is a "plain"'; |
38 is tied($p)->{type}, '' => 'is a "plain"'; |