fix types with stringifyable TC objects
[gitmo/Moose.git] / t / 040_type_constraints / 010_misc_type_tests.t
CommitLineData
86629f93 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
9c434902 6use Test::More tests => 8;
86629f93 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose::Util::TypeConstraints');
11}
12
13# subtype 'aliasing' ...
14
15lives_ok {
16 subtype 'Numb3rs' => as 'Num';
17} '... create bare subtype fine';
18
19my $numb3rs = find_type_constraint('Numb3rs');
9c434902 20isa_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
33ok my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new
34 => "Created Instance";
35
36isa_ok $dummy_instance, 'Test::Moose::Meta::TypeConstraint::Union'
37 => 'isa correct type';
38
39is "$dummy_instance", "Broken|Test"
40 => "Got expected stringification result";
41
42ok my $subtype1 = subtype('New1', as $dummy_instance)
43 => "made a subtype";
44
45ok my $subtype2 = subtype('New2', as $subtype1)
46 => "made another subtype";