From: Toby Inkster Date: Fri, 19 Oct 2012 13:51:47 +0000 (+0100) Subject: tests for DOES X-Git-Tag: v1.002000~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=296fbb69cb2de5c9cfe48a18b14a8ef23676258f;p=gitmo%2FRole-Tiny.git tests for DOES --- diff --git a/t/does-Moo.t b/t/does-Moo.t new file mode 100644 index 0000000..a064384 --- /dev/null +++ b/t/does-Moo.t @@ -0,0 +1,61 @@ +use Test::More; +BEGIN { + plan skip_all => 'requires Moo' + unless eval { require Moo; require Moo::Role; 1 }; + plan tests => 14; +} + +BEGIN { + package Local::Role1; + use Moo::Role; +} + +BEGIN { + package Local::Role2; + use Moo::Role; +} + +BEGIN { + package Local::Class1; + use Moo; + with qw( + Local::Role1 + Local::Role2 + ); +} + +BEGIN { + package Local::Class2; + use Moo; + with qw( Local::Role1 ); + with qw( Local::Role2 ); +} + +BEGIN { + package Local::Class3; + use Moo; + with qw( Local::Role1 ); + with qw( Local::Role2 ); + sub DOES { + my ($proto, $role) = @_; + return 1 if $role eq 'Local::Role3'; + return $proto->does($role); + } +} + +for my $c (1 .. 3) { + my $class = "Local::Class$c"; + for my $r (1 .. 2) { + my $role = "Local::Role$r"; + ok($class->does($role), "$class\->does($role)"); + ok($class->DOES($role), "$class\->DOES($role)"); + } +} + +{ + my $class = "Local::Class3"; + my $role = "Local::Role3"; + ok( ! $class->does($role), "$class\->does($role)"); + ok( $class->DOES($role), "$class\->DOES($role)"); +} + diff --git a/t/does.t b/t/does.t new file mode 100644 index 0000000..c17ebfd --- /dev/null +++ b/t/does.t @@ -0,0 +1,55 @@ +use Test::More tests => 14; + +BEGIN { + package Local::Role1; + use Role::Tiny; +} + +BEGIN { + package Local::Role2; + use Role::Tiny; +} + +BEGIN { + package Local::Class1; + use Role::Tiny::With; + with qw( + Local::Role1 + Local::Role2 + ); +} + +BEGIN { + package Local::Class2; + use Role::Tiny::With; + with qw( Local::Role1 ); + with qw( Local::Role2 ); +} + +BEGIN { + package Local::Class3; + use Role::Tiny::With; + with qw( Local::Role1 ); + with qw( Local::Role2 ); + sub DOES { + my ($proto, $role) = @_; + return 1 if $role eq 'Local::Role3'; + return $proto->Role::Tiny::does_role($role); + } +} + +for my $c (1 .. 3) { + my $class = "Local::Class$c"; + for my $r (1 .. 2) { + my $role = "Local::Role$r"; + ok($class->does($role), "$class\->does($role)"); + ok($class->DOES($role), "$class\->DOES($role)"); + } +} + +{ + my $class = "Local::Class3"; + my $role = "Local::Role3"; + ok( ! $class->does($role), "$class\->does($role)"); + ok( $class->DOES($role), "$class\->DOES($role)"); +}