X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F040_type_constraints%2F017_subtyping_union_types.t;h=830f1e8d55510e38d85e00ebda7073f7ecbc862d;hp=505e92cc29ef08c3d2e145d6cdf4ff3725656a55;hb=346a3ab8a10ac61eae8021ccfd068d80ccccd56a;hpb=267711f78bd79835875f805447d3ab802a18f0c4 diff --git a/t/040_type_constraints/017_subtyping_union_types.t b/t/040_type_constraints/017_subtyping_union_types.t index 505e92c..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 => 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'); -} - - +#!/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'); +} + +