merge trunk to pluggable errors
[gitmo/Moose.git] / t / 040_type_constraints / 010_misc_type_tests.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose::Util::TypeConstraints');           
11 }
12
13 # subtype 'aliasing' ...
14
15 lives_ok {
16     subtype 'Numb3rs' => as 'Num';
17 } '... create bare subtype fine';
18
19 my $numb3rs = find_type_constraint('Numb3rs');
20 isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
21
22 # subtype with unions
23
24 {
25     package Test::Moose::Meta::TypeConstraint::Union;
26
27     use overload '""' => sub {'Broken|Test'}, fallback => 1;
28     use Moose;
29
30     extends 'Moose::Meta::TypeConstraint';
31 }
32
33 my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new;
34
35 ok $dummy_instance => "Created Instance";
36
37 isa_ok $dummy_instance,
38     'Test::Moose::Meta::TypeConstraint::Union' => 'isa correct type';
39
40 is "$dummy_instance", "Broken|Test" =>
41     'Got expected stringification result';
42
43 my $subtype1 = subtype 'New1' => as $dummy_instance;
44
45 ok $subtype1 => 'made a subtype from our type object';
46
47 my $subtype2 = subtype 'New2' => as $subtype1;
48
49 ok $subtype2 => 'made a subtype of our subtype';