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