pod
[gitmo/MooseX-Emulate-Class-Accessor-Fast.git] / t / accessors.t
CommitLineData
c5a105b3 1#!perl
2use strict;
3use Test::More tests => 32;
4
5#1
6require_ok("MooseX::Adopt::Class::Accessor::Fast");
7
8my $class = "Testing::Class::Accessor::Fast";
9
10{
11 no strict 'refs';
12 @{"${class}::ISA"} = ('Class::Accessor::Fast');
13 *{"${class}::car"} = sub { shift->_car_accessor(@_); };
14 *{"${class}::mar"} = sub { return "Overloaded"; };
15
16 $class->mk_accessors(qw( foo bar yar car mar ));
17 $class->mk_ro_accessors(qw(static unchanged));
18 $class->mk_wo_accessors(qw(sekret double_sekret));
19 $class->follow_best_practice;
20 $class->mk_accessors(qw( best));
21}
22
23my %attrs = map{$_->name => $_} $class->meta->compute_all_applicable_attributes;
24
25#2
26is(keys %attrs, 10, 'Correct number of attributes');
27
28#3-12
29ok(exists $attrs{$_}, "Attribute ${_} created")
30 for qw( foo bar yar car mar static unchanged sekret double_sekret best );
31
32#13-21
33ok($class->can("_${_}_accessor"), "Attribute ${_} created")
34 for qw( foo bar yar car mar static unchanged sekret double_sekret );
35
36#22-24
37is( $attrs{$_}->accessor, $_, "Accessor ${_} created" )
38 for qw( foo bar yar);
39
40#25,26
41ok( !$attrs{$_}->has_accessor, "Accessor ${_} not created" )
42 for qw( car mar);
43
44#27,28
45is( $attrs{$_}->reader, $_, "Reader ${_} created")
46 for qw( static unchanged );
47
48#29,30
49is( $attrs{$_}->writer, $_, "Writer ${_} created")
50 for qw(sekret double_sekret);
51
52#31,32
53is( $attrs{'best'}->reader, 'get_best', "Reader get_best created");
54is( $attrs{'best'}->writer, 'set_best', "Writer set_best created");