Ignore all .git.*
[gitmo/Class-MOP.git] / t / 000_load.t
CommitLineData
8b978dd5 1use strict;
2use warnings;
3
565f0cbb 4use Test::More tests => 42;
8b978dd5 5
6BEGIN {
1a7ebbb3 7 use_ok('Class::MOP');
b5fc2d24 8 use_ok('Class::MOP::Package');
9 use_ok('Class::MOP::Module');
8b978dd5 10 use_ok('Class::MOP::Class');
b5fc2d24 11 use_ok('Class::MOP::Immutable');
8b978dd5 12 use_ok('Class::MOP::Attribute');
b5fc2d24 13 use_ok('Class::MOP::Method');
14 use_ok('Class::MOP::Method::Wrapped');
15 use_ok('Class::MOP::Method::Generated');
16 use_ok('Class::MOP::Method::Accessor');
17 use_ok('Class::MOP::Method::Constructor');
18 use_ok('Class::MOP::Instance');
19 use_ok('Class::MOP::Object');
d41e86f2 20}
21
22# make sure we are tracking metaclasses correctly
23
b5ade142 24my @CLASS_MOP_CLASS_IMMUTABLE_CLASSES
25 = map { 'Class::MOP::Class::__ANON__::SERIAL::' . $_ } 1..11;
c23184fc 26
d41e86f2 27my %METAS = (
1f833546 28 'Class::MOP::Attribute' => Class::MOP::Attribute->meta,
29 'Class::MOP::Method::Generated' => Class::MOP::Method::Generated->meta,
30 'Class::MOP::Method::Accessor' => Class::MOP::Method::Accessor->meta,
31 'Class::MOP::Method::Constructor' =>
32 Class::MOP::Method::Constructor->meta,
33 'Class::MOP::Package' => Class::MOP::Package->meta,
34 'Class::MOP::Module' => Class::MOP::Module->meta,
35 'Class::MOP::Class' => Class::MOP::Class->meta,
36 'Class::MOP::Method' => Class::MOP::Method->meta,
37 'Class::MOP::Method::Wrapped' => Class::MOP::Method::Wrapped->meta,
38 'Class::MOP::Instance' => Class::MOP::Instance->meta,
39 'Class::MOP::Object' => Class::MOP::Object->meta,
d41e86f2 40);
41
b5fc2d24 42ok( Class::MOP::is_class_loaded($_), '... ' . $_ . ' is loaded' )
43 for keys %METAS;
448b6e55 44
b5fc2d24 45ok( $_->is_immutable(), '... ' . $_->name . ' is immutable' )
46 for values %METAS;
4d47b77f 47
d41e86f2 48is_deeply(
b5fc2d24 49 {Class::MOP::get_all_metaclasses},
c23184fc 50 {
51 %METAS,
b5ade142 52 map { $_ => $_->meta } @CLASS_MOP_CLASS_IMMUTABLE_CLASSES
c23184fc 53 },
b5fc2d24 54 '... got all the metaclasses'
55);
d41e86f2 56
57is_deeply(
b5fc2d24 58 [
59 sort { $a->name cmp $b->name } Class::MOP::get_all_metaclass_instances
60 ],
61 [
62 Class::MOP::Attribute->meta,
63 Class::MOP::Class->meta,
b5ade142 64 ( map { $_->meta } sort @CLASS_MOP_CLASS_IMMUTABLE_CLASSES ),
b5fc2d24 65 Class::MOP::Instance->meta,
2243a22b 66 Class::MOP::Method->meta,
d90b42a6 67 Class::MOP::Method::Accessor->meta,
b5fc2d24 68 Class::MOP::Method::Constructor->meta,
69 Class::MOP::Method::Generated->meta,
b6164407 70 Class::MOP::Method::Wrapped->meta,
b5fc2d24 71 Class::MOP::Module->meta,
72 Class::MOP::Object->meta,
73 Class::MOP::Package->meta,
2243a22b 74 ],
b5fc2d24 75 '... got all the metaclass instances'
76);
d41e86f2 77
78is_deeply(
be7677c7 79 [ sort { $a cmp $b } Class::MOP::get_all_metaclass_names() ],
b5fc2d24 80 [
81 sort qw/
82 Class::MOP::Attribute
83 Class::MOP::Class
84 Class::MOP::Instance
85 Class::MOP::Method
86 Class::MOP::Method::Accessor
87 Class::MOP::Method::Constructor
88 Class::MOP::Method::Generated
89 Class::MOP::Method::Wrapped
90 Class::MOP::Module
91 Class::MOP::Object
92 Class::MOP::Package
b5ade142 93 /, @CLASS_MOP_CLASS_IMMUTABLE_CLASSES
b5fc2d24 94 ],
95 '... got all the metaclass names'
96);
97
b1897d4d 98is_deeply(
b5fc2d24 99 [
100 map { $_->meta->identifier }
101 sort { $a cmp $b } Class::MOP::get_all_metaclass_names()
b1897d4d 102 ],
b5fc2d24 103 [
104 "Class::MOP::Attribute-"
105 . $Class::MOP::Attribute::VERSION
106 . "-cpan:STEVAN",
107 "Class::MOP::Class-" . $Class::MOP::Class::VERSION . "-cpan:STEVAN",
b5ade142 108 ( sort @CLASS_MOP_CLASS_IMMUTABLE_CLASSES ),
b5fc2d24 109 "Class::MOP::Instance-"
110 . $Class::MOP::Instance::VERSION
111 . "-cpan:STEVAN",
112 "Class::MOP::Method-" . $Class::MOP::Method::VERSION . "-cpan:STEVAN",
113 "Class::MOP::Method::Accessor-"
114 . $Class::MOP::Method::Accessor::VERSION
115 . "-cpan:STEVAN",
116 "Class::MOP::Method::Constructor-"
117 . $Class::MOP::Method::Constructor::VERSION
118 . "-cpan:STEVAN",
119 "Class::MOP::Method::Generated-"
120 . $Class::MOP::Method::Generated::VERSION
121 . "-cpan:STEVAN",
122 "Class::MOP::Method::Wrapped-"
123 . $Class::MOP::Method::Wrapped::VERSION
124 . "-cpan:STEVAN",
125 "Class::MOP::Module-" . $Class::MOP::Module::VERSION . "-cpan:STEVAN",
126 "Class::MOP::Object-" . $Class::MOP::Object::VERSION . "-cpan:STEVAN",
127 "Class::MOP::Package-"
128 . $Class::MOP::Package::VERSION
129 . "-cpan:STEVAN",
130 ],
131 '... got all the metaclass identifiers'
132);
dc76a410 133
b5fc2d24 134# testing the meta-circularity of the system
dc76a410 135
b5fc2d24 136is(
137 Class::MOP::Class->meta, Class::MOP::Class->meta->meta,
138 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta'
139);
dc76a410 140
b5fc2d24 141is(
142 Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta,
143 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta'
144);
dc76a410 145
b5fc2d24 146is(
147 Class::MOP::Class->meta, Class::MOP::Class->meta->meta->meta->meta,
148 '... Class::MOP::Class->meta == Class::MOP::Class->meta->meta->meta->meta'
149);
dc76a410 150