t/10-usage.t
changeset 1 82e2b6a853a7
parent 0 f65c3dd5742a
child 4 0fc33e54b1c6
--- a/t/10-usage.t	Tue Jul 29 12:17:35 2014 +0200
+++ b/t/10-usage.t	Tue Jul 29 21:26:49 2014 +0200
@@ -6,16 +6,12 @@
 use Test::Exception;
 
 use_ok 'Scalar::RefType' or BAIL_OUT q{Can't load the module};
-isa_ok tie(my $h => 'Scalar::RefType', {}) => 'Scalar::RefType';
-isa_ok tie(my $a => 'Scalar::RefType', []) => 'Scalar::RefType';
-isa_ok tie(my $s => 'Scalar::RefType', \(undef)) => 'Scalar::RefType';
-isa_ok tie(my $p => 'Scalar::RefType', undef)    => 'Scalar::RefType';
 
 subtest 'NAMES' => sub {
     isa_ok tie(my $h => 'Scalar::RefType', ref {}) => 'Scalar::RefType';
     isa_ok tie(my $a => 'Scalar::RefType', ref []) => 'Scalar::RefType';
     isa_ok tie(my $s => 'Scalar::RefType', ref \(undef)) => 'Scalar::RefType';
-    isa_ok tie(my $p => 'Scalar::RefType', '') => 'Scalar::RefType';
+    isa_ok tie(my $p => 'Scalar::RefType', '')           => 'Scalar::RefType';
 
     is tied($h)->{type}, 'HASH'   => 'is a hash ref';
     is tied($a)->{type}, 'ARRAY'  => 'is a array ref';
@@ -24,6 +20,18 @@
 
 };
 
+subtest 'AUTO' => sub {
+    isa_ok tie(my $x => 'Scalar::RefType') => 'Scalar::RefType';
+    ok $x = {} => 'hash: assignment';
+    is tied($x)->{type}, 'HASH' => 'hash: type';
+    throws_ok { $x = [] } qr/invalid/ => 'invalid type assignment';
+};
+
+isa_ok tie(my $h => 'Scalar::RefType', {}) => 'Scalar::RefType';
+isa_ok tie(my $a => 'Scalar::RefType', []) => 'Scalar::RefType';
+isa_ok tie(my $s => 'Scalar::RefType', \(undef)) => 'Scalar::RefType';
+isa_ok tie(my $p => 'Scalar::RefType', undef)    => 'Scalar::RefType';
+
 is tied($h)->{type}, 'HASH'   => 'is a hash ref';
 is tied($a)->{type}, 'ARRAY'  => 'is a array ref';
 is tied($s)->{type}, 'SCALAR' => 'is a scalar';