Spell can't correctly
[gitmo/Class-MOP.git] / t / 030_method.t
CommitLineData
cbd9f942 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
b38f3848 6use Test::More tests => 28;
cbd9f942 7use Test::Exception;
8
9BEGIN {
727919c5 10 use_ok('Class::MOP');
cbd9f942 11 use_ok('Class::MOP::Method');
12}
13
b38f3848 14my $method = Class::MOP::Method->wrap(
15 sub { 1 },
16 package_name => 'main',
17 name => '__ANON__',
18);
de19f115 19is($method->meta, Class::MOP::Method->meta, '... instance and class both lead to the same meta');
20
21is($method->package_name, 'main', '... our package is main::');
22is($method->name, '__ANON__', '... our sub name is __ANON__');
d41e86f2 23is($method->fully_qualified_name, 'main::__ANON__', '... our subs full name is main::__ANON__');
22286063 24
bf3db0fb 25dies_ok { Class::MOP::Method->wrap } q{... can't call wrap() without some code};
26dies_ok { Class::MOP::Method->wrap([]) } q{... can't call wrap() without some code};
27dies_ok { Class::MOP::Method->wrap(bless {} => 'Fail') } q{... can't call wrap() without some code};
8048fe76 28
bf3db0fb 29dies_ok { Class::MOP::Method->name } q{... can't call name() with a class};
30dies_ok { Class::MOP::Method->package_name } q{... can't call package_name() with a class};
31dies_ok { Class::MOP::Method->fully_qualified_name } q{... can't call fully_qualified_name() with a class};
8048fe76 32
cbd9f942 33my $meta = Class::MOP::Method->meta;
34isa_ok($meta, 'Class::MOP::Class');
35
de19f115 36foreach my $method_name (qw(
a4258ffd 37 wrap
de19f115 38 package_name
39 name
40 )) {
41 ok($meta->has_method($method_name), '... Class::MOP::Method->has_method(' . $method_name . ')');
42 my $method = $meta->get_method($method_name);
43 is($method->package_name, 'Class::MOP::Method', '... our package is Class::MOP::Method');
44 is($method->name, $method_name, '... our sub name is "' . $method_name . '"');
cbd9f942 45}
46
47dies_ok {
a4258ffd 48 Class::MOP::Method->wrap()
cbd9f942 49} '... bad args for &wrap';
50
51dies_ok {
a4258ffd 52 Class::MOP::Method->wrap('Fail')
cbd9f942 53} '... bad args for &wrap';
54
55dies_ok {
a4258ffd 56 Class::MOP::Method->wrap([])
b38f3848 57} '... bad args for &wrap';
58
59dies_ok {
60 Class::MOP::Method->wrap(sub { 'FAIL' })
61} '... bad args for &wrap';
62
63dies_ok {
64 Class::MOP::Method->wrap(sub { 'FAIL' }, package_name => 'main')
65} '... bad args for &wrap';
66
67dies_ok {
68 Class::MOP::Method->wrap(sub { 'FAIL' }, name => '__ANON__')
69} '... bad args for &wrap';
70
71
72
73
74