X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F040_type_constraints%2F017_subtyping_union_types.t;h=830f1e8d55510e38d85e00ebda7073f7ecbc862d;hb=45eea07f4090ae7ed7a6556bfa5897f34155b489;hp=ff8d90dab3529bca045114440ac411fe05178852;hpb=a254bf514576f3d4a5bcde5a0db4d4ced9ad566b;p=gitmo%2FMouse.git diff --git a/t/040_type_constraints/017_subtyping_union_types.t b/t/040_type_constraints/017_subtyping_union_types.t index ff8d90d..830f1e8 100755 --- a/t/040_type_constraints/017_subtyping_union_types.t +++ b/t/040_type_constraints/017_subtyping_union_types.t @@ -1,69 +1,69 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Test::More tests => 21; -use Test::Exception; - -BEGIN { - use_ok("Moose::Util::TypeConstraints"); -} - -lives_ok { - subtype 'MyCollections' => as 'ArrayRef | HashRef'; -} '... created the subtype special okay'; - -{ - my $t = find_type_constraint('MyCollections'); - isa_ok($t, 'Moose::Meta::TypeConstraint'); - - is($t->name, 'MyCollections', '... name is correct'); - - my $p = $t->parent; - isa_ok($p, 'Moose::Meta::TypeConstraint::Union'); - isa_ok($p, 'Moose::Meta::TypeConstraint'); - - is($p->name, 'ArrayRef|HashRef', '... parent name is correct'); - - ok($t->check([]), '... validated it correctly'); - ok($t->check({}), '... validated it correctly'); - ok(!$t->check(1), '... validated it correctly'); -} - -lives_ok { - subtype 'MyCollectionsExtended' - => as 'ArrayRef|HashRef' - => where { - if (ref($_) eq 'ARRAY') { - return if scalar(@$_) < 2; - } - elsif (ref($_) eq 'HASH') { - return if scalar(keys(%$_)) < 2; - } - 1; - }; -} '... created the subtype special okay'; - -{ - my $t = find_type_constraint('MyCollectionsExtended'); - isa_ok($t, 'Moose::Meta::TypeConstraint'); - - is($t->name, 'MyCollectionsExtended', '... name is correct'); - - my $p = $t->parent; - isa_ok($p, 'Moose::Meta::TypeConstraint::Union'); - isa_ok($p, 'Moose::Meta::TypeConstraint'); - - is($p->name, 'ArrayRef|HashRef', '... parent name is correct'); - - ok(!$t->check([]), '... validated it correctly'); - ok($t->check([1, 2]), '... validated it correctly'); - - ok(!$t->check({}), '... validated it correctly'); - ok($t->check({ one => 1, two => 2 }), '... validated it correctly'); - - ok(!$t->check(1), '... validated it correctly'); -} - - +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 19; +use Test::Exception; + +BEGIN { + use_ok("Mouse::Util::TypeConstraints"); +} + +lives_ok { + subtype 'MyCollections' => as 'ArrayRef | HashRef'; +} '... created the subtype special okay'; + +{ + my $t = find_type_constraint('MyCollections'); + isa_ok($t, 'Mouse::Meta::TypeConstraint'); + + is($t->name, 'MyCollections', '... name is correct'); + + my $p = $t->parent; +# isa_ok($p, 'Mouse::Meta::TypeConstraint::Union'); + isa_ok($p, 'Mouse::Meta::TypeConstraint'); + + is($p->name, 'ArrayRef|HashRef', '... parent name is correct'); + + ok($t->check([]), '... validated it correctly'); + ok($t->check({}), '... validated it correctly'); + ok(!$t->check(1), '... validated it correctly'); +} + +lives_ok { + subtype 'MyCollectionsExtended' + => as 'ArrayRef|HashRef' + => where { + if (ref($_) eq 'ARRAY') { + return if scalar(@$_) < 2; + } + elsif (ref($_) eq 'HASH') { + return if scalar(keys(%$_)) < 2; + } + 1; + }; +} '... created the subtype special okay'; + +{ + my $t = find_type_constraint('MyCollectionsExtended'); + isa_ok($t, 'Mouse::Meta::TypeConstraint'); + + is($t->name, 'MyCollectionsExtended', '... name is correct'); + + my $p = $t->parent; +# isa_ok($p, 'Mouse::Meta::TypeConstraint::Union'); + isa_ok($p, 'Mouse::Meta::TypeConstraint'); + + is($p->name, 'ArrayRef|HashRef', '... parent name is correct'); + + ok(!$t->check([]), '... validated it correctly'); + ok($t->check([1, 2]), '... validated it correctly'); + + ok(!$t->check({}), '... validated it correctly'); + ok($t->check({ one => 1, two => 2 }), '... validated it correctly'); + + ok(!$t->check(1), '... validated it correctly'); +} + +