diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-06 17:50:16 +0000 |
commit | 5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch) | |
tree | 298c3d2f08bdfe5689998b11892d72a897985be1 /t/moose_util/ensure_all_roles.t | |
download | Moose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz |
Moose-2.1405HEADMoose-2.1405master
Diffstat (limited to 't/moose_util/ensure_all_roles.t')
-rw-r--r-- | t/moose_util/ensure_all_roles.t | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/t/moose_util/ensure_all_roles.t b/t/moose_util/ensure_all_roles.t new file mode 100644 index 0000000..9888bfb --- /dev/null +++ b/t/moose_util/ensure_all_roles.t @@ -0,0 +1,62 @@ +use strict; +use warnings; + +use Test::More; + +use Moose::Util ':all'; + +{ + package Foo; + use Moose::Role; +} + +{ + package Bar; + use Moose::Role; +} + +{ + package Quux; + use Moose; +} + +is_deeply( + Quux->meta->roles, + [], + "no roles yet", +); + +Foo->meta->apply(Quux->meta); + +is_deeply( + Quux->meta->roles, + [ Foo->meta ], + "applied Foo", +); + +Foo->meta->apply(Quux->meta); +Bar->meta->apply(Quux->meta); +is_deeply( + Quux->meta->roles, + [ Foo->meta, Foo->meta, Bar->meta ], + "duplicated Foo", +); + +is(does_role('Quux', 'Foo'), 1, "Quux does Foo"); +is(does_role('Quux', 'Bar'), 1, "Quux does Bar"); +ensure_all_roles('Quux', qw(Foo Bar)); +is_deeply( + Quux->meta->roles, + [ Foo->meta, Foo->meta, Bar->meta ], + "unchanged, since all roles are already applied", +); + +my $obj = Quux->new; +ensure_all_roles($obj, qw(Foo Bar)); +is_deeply( + $obj->meta->roles, + [ Foo->meta, Foo->meta, Bar->meta ], + "unchanged, since all roles are already applied", +); + +done_testing; |