Merge branch 'bare_attribute'
[gitmo/Moose.git] / t / 040_type_constraints / 003_util_std_type_constraints.t
index 2961044..2457d50 100644 (file)
@@ -3,13 +3,13 @@
 use strict;
 use warnings;
 
-use Test::More tests => 271;
+use Test::More tests => 291;
 use Test::Exception;
 
 use Scalar::Util ();
 
 BEGIN {
-    use_ok('Moose::Util::TypeConstraints');           
+    use_ok('Moose::Util::TypeConstraints');
 }
 
 my $SCALAR_REF = \(my $var);
@@ -20,6 +20,8 @@ my $GLOB_REF   = \*GLOB_REF;
 my $fh;
 open($fh, '<', $0) || die "Could not open $0 for the test";
 
+my $fh_obj = bless {}, "IO::Handle"; # not really
+
 Moose::Util::TypeConstraints->export_type_constraints_as_functions();
 
 ok(defined Any(0),               '... Any accepts anything');
@@ -247,6 +249,7 @@ ok(!defined GlobRef(sub {}),           '... GlobRef rejects anything which is no
 ok(!defined GlobRef($SCALAR_REF),      '... GlobRef rejects anything which is not a GlobRef');
 ok(defined GlobRef($GLOB_REF),         '... GlobRef accepts anything which is a GlobRef');
 ok(defined GlobRef($fh),               '... GlobRef accepts anything which is a GlobRef');
+ok(!defined GlobRef($fh_obj),          '... GlobRef rejects anything which is not a GlobRef');
 ok(!defined GlobRef(qr/../),           '... GlobRef rejects anything which is not a GlobRef');
 ok(!defined GlobRef(bless {}, 'Foo'),  '... GlobRef rejects anything which is not a GlobRef');
 ok(!defined GlobRef(undef),            '... GlobRef rejects anything which is not a GlobRef');
@@ -261,6 +264,7 @@ ok(!defined FileHandle(sub {}),           '... FileHandle rejects anything which
 ok(!defined FileHandle($SCALAR_REF),      '... FileHandle rejects anything which is not a FileHandle');
 ok(!defined FileHandle($GLOB_REF),        '... FileHandle rejects anything which is not a FileHandle');
 ok(defined FileHandle($fh),               '... FileHandle accepts anything which is a FileHandle');
+ok(defined FileHandle($fh_obj),           '... FileHandle accepts anything which is a FileHandle');
 ok(!defined FileHandle(qr/../),           '... FileHandle rejects anything which is not a FileHandle');
 ok(!defined FileHandle(bless {}, 'Foo'),  '... FileHandle rejects anything which is not a FileHandle');
 ok(!defined FileHandle(undef),            '... FileHandle rejects anything which is not a FileHandle');
@@ -295,9 +299,9 @@ ok(!defined Role($SCALAR_REF),          '... Role rejects anything which is not
 ok(!defined Role($GLOB_REF),            '... Role rejects anything which is not a Role');
 ok(!defined Role($fh),                  '... Role rejects anything which is not a Role');
 ok(!defined Role(qr/../),               '... Role rejects anything which is not a Role');
-ok(!defined Role(bless {}, 'Foo'),      '... Role accepts anything which is not a Role');
-ok(defined Role(bless {}, 'My::Role'),  '... Role accepts anything which is not a Role');
-ok(!defined Role(undef),                 '... Role accepts anything which is not a Role');
+ok(!defined Role(bless {}, 'Foo'),      '... Role rejects anything which is not a Role');
+ok(defined Role(bless {}, 'My::Role'),  '... Role accepts anything which is a Role');
+ok(!defined Role(undef),                '... Role rejects anything which is not a Role');
 
 ok(!defined ClassName(0),               '... ClassName rejects anything which is not a ClassName');
 ok(!defined ClassName(100),             '... ClassName rejects anything which is not a ClassName');
@@ -324,4 +328,30 @@ ok(defined ClassName('UNIVERSAL'),      '... ClassName accepts anything which is
 ok(defined ClassName('Quux::Wibble'),      '... ClassName accepts anything which is a ClassName');
 ok(defined ClassName('Moose::Meta::TypeConstraint'), '... ClassName accepts anything which is a ClassName');
 
+ok(!defined RoleName(0),               '... RoleName rejects anything which is not a RoleName');
+ok(!defined RoleName(100),             '... RoleName rejects anything which is not a RoleName');
+ok(!defined RoleName(''),              '... RoleName rejects anything which is not a RoleName');
+ok(!defined RoleName('Baz'),           '... RoleName rejects anything which is not a RoleName');
+
+{
+  package Quux::Wibble::Role; # this makes Quux symbol table exist
+  use Moose::Role;
+  sub foo {}
+}
+
+ok(!defined RoleName('Quux'),           '... RoleName rejects anything which is not a RoleName');
+ok(!defined RoleName([]),              '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName({}),              '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName(sub {}),          '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName($SCALAR_REF),     '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName($fh),             '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName($GLOB_REF),       '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName(qr/../),          '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName(bless {}, 'Foo'), '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName(undef),           '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName('UNIVERSAL'),     '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName('Quux::Wibble'),  '... Rolename rejects anything which is not a RoleName');
+ok(!defined RoleName('Moose::Meta::TypeConstraint'),  '... RoleName accepts anything which is a RoleName');
+ok(defined RoleName('Quux::Wibble::Role'),      '... RoleName accepts anything which is a RoleName');
+
 close($fh) || die "Could not close the filehandle $0 for test";