Added latest bugfix to Changes.
[gitmo/Mouse.git] / t / 100-meta-class.t
CommitLineData
c3398f5b 1#!/usr/bin/env perl
2use strict;
3use warnings;
c68b4110 4use Test::More tests => 15;
c3398f5b 5
6do {
7 package Class;
8 use Mouse;
9
10 has pawn => (
11 is => 'rw',
12 predicate => 'has_pawn',
13 );
14
15 no Mouse;
16};
17
18my $meta = Class->meta;
306290e8 19isa_ok($meta, 'Mouse::Meta::Class');
c3398f5b 20
21is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mouse::Object");
22
23my $meta2 = Class->meta;
24is($meta, $meta2, "same metaclass instance");
25
c68b4110 26can_ok($meta, 'name', 'get_attribute_map', 'get_attribute_list');
c3398f5b 27
986ff64a 28ok($meta->has_attribute('pawn'));
c3398f5b 29my $attr = $meta->get_attribute('pawn');
306290e8 30isa_ok($attr, 'Mouse::Meta::Attribute');
c3398f5b 31is($attr->name, 'pawn', 'got the correct attribute');
32
33my $map = $meta->get_attribute_map;
34is_deeply($map, { pawn => $attr }, "attribute map");
35
c68b4110 36my $list = [$meta->get_attribute_list];
37is_deeply($list, [ 'pawn' ], "attribute list");
38
986ff64a 39ok(!$meta->has_attribute('nonexistent_attribute'));
40
c3398f5b 41eval "
42 package Class;
43 use Mouse;
44 no Mouse;
45";
46
47my $meta3 = Class->meta;
48is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again");
49
50is($meta->name, 'Class', "name for the metaclass");
51
52do {
53 package Child;
54 use Mouse;
55 extends 'Class';
56};
57
58my $child_meta = Child->meta;
306290e8 59isa_ok($child_meta, 'Mouse::Meta::Class');
c3398f5b 60
61isnt($meta, $child_meta, "different metaclass instances for the two classes");
62
63is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses");