Add a test for a problem that the Moose tests were running into when
[gitmo/Class-MOP.git] / t / 084_get_method_map.t
1 use strict;
2 use warnings;
3
4 use Test::More 'no_plan';
5
6
7 {
8     package Foo;
9
10     use metaclass;
11
12     sub foo { }
13 }
14
15 {
16     my $map = Foo->meta->get_method_map;
17
18     is( scalar keys %{$map}, 2,
19         'method map for Foo has two key' );
20     ok( $map->{foo}, '... has a foo method in the map' );
21     ok( $map->{meta}, '... has a meta method in the map' );
22 }
23
24
25 Foo->meta->add_method( bar => sub { } );
26
27 {
28     my $map = Foo->meta->get_method_map;
29     is( scalar keys %{$map}, 3,
30         'method map for Foo has three keys' );
31     ok( $map->{foo}, '... has a foo method in the map' );
32     ok( $map->{bar}, '... has a bar method in the map' );
33     ok( $map->{meta}, '... has a meta method in the map' );
34 }
35
36 # Tests a bug where after a metaclass object was recreated, methods
37 # added via add_method were not showing up in the map, but only with
38 # the non-XS version of the code.
39 Class::MOP::remove_metaclass_by_name('Foo');
40
41 {
42     my $map = Foo->meta->get_method_map;
43     is( scalar keys %{$map}, 3,
44         'method map for Foo has three keys' );
45     ok( $map->{foo}, '... has a foo method in the map' );
46     ok( $map->{bar}, '... has a bar method in the map' );
47     ok( $map->{meta}, '... has a meta method in the map' );
48 }