Skip to content

Commit

Permalink
add some method alias, slots and required method tests for MOP::Class
Browse files Browse the repository at this point in the history
  • Loading branch information
lharey authored and stevan committed Dec 11, 2017
1 parent c45b172 commit cb8952d
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions t/020-class/001-basic.t
Expand Up @@ -10,15 +10,6 @@ BEGIN {
use_ok('MOP::Class');
}

=pod
TODO:
- test method aliases
- test slots
- test required methods
=cut

{
package Foo;
use strict;
Expand All @@ -27,7 +18,23 @@ TODO:
our $VERSION = '0.01';
our $AUTHORITY = 'cpan:STEVAN';

our %HAS;
BEGIN {
%HAS = (
doh => sub { 'doh::doh' }
)
};

sub bar { 'Foo::Bar' }

package Bar;
use strict;
use warnings;

our %HAS;
BEGIN { %HAS = ( %Foo::HAS ) };

sub bobbins;
}

my %cases = (
Expand All @@ -52,6 +59,49 @@ foreach my $case ( keys %cases ) {
};
}

subtest '... method alias' => sub {
my $c = MOP::Class->new( name => 'Foo' );

ok(!$c->has_method_alias('foobar'), '... the foobar method is not an alias');
is(scalar $c->aliased_methods(),0,'... there are no aliased methods');

$c->alias_method('foobar' => sub { 'foobar' });

ok($c->has_method_alias('foobar'), '... foobar method is now an alias');
isa_ok($c->get_method_alias('foobar'), 'MOP::Method');
is(scalar $c->aliased_methods(),1,'... there is now 1 aliased method');

$c->delete_method_alias('foobar');
ok(!$c->has_method_alias('foobar'), '... delete_method_alias has removed the foobar alias');
};

subtest '... slots' => sub {
my $c = MOP::Class->new( name => 'Foo' );

is(scalar $c->all_slots,1,'... class foo has 1 slot');
is(scalar $c->slots,1,'... class foo has 1 regular slot');
is(scalar $c->aliased_slots,0,'... class foo has no aliased slots');

ok($c->has_slot('doh'), '... class foo has slot doh');
ok($c->get_slot('doh'), '... class foo can get slot doh');

my $bar = MOP::Class->new( name => 'Bar' );

is(scalar $bar->all_slots,1,'... class bar has 1 slot');
is(scalar $bar->slots,0,'... class bar has 1 regular slot');
is(scalar $bar->aliased_slots,1,'... class bar has 1 aliased slot');

ok(!$bar->has_slot('doh'), '... class bar does not have slot doh');
ok(!$bar->get_slot('doh'), '... class bar can not get the doh attribute');
ok($bar->has_slot_alias('doh'), '... class bar has slot alias doh');
ok($bar->get_slot_alias('doh'), '... class bar can get the doh alias');
};

subtest '... required methods' => sub {
ok(! MOP::Class->new( name => 'Foo' )->requires_method('bar'), '... bar method is not required');
ok(MOP::Class->new( name => 'Bar' )->requires_method('bobbins'), '... bobbins method is required');
};

done_testing;


Expand Down

0 comments on commit cb8952d

Please sign in to comment.