est::Fatal;
use Class::MOP;
{
isnt( exception {
Class::MOP::Class->initialize();
}, undef, '... initialize requires a name parameter' );
isnt( exception {
Class::MOP::Cl
lid parameter' );
isnt( exception {
Class::MOP::Class->initialize(bless {} => 'Foo');
}, undef, '... initialize requires an unblessed parameter' );
}
{
isnt( exception {
isnt( exception {
Class::MOP::Class->_construct_class_instance(':package' => undef);
}, undef, '... _construct_class_instance requires a defined :package parameter' );
isnt( exc
;
isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
isnt( excep
isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
isnt( e
xception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
is( exc
e static
{
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => qr/hello (.*)/
));
}, undef, '... no refs for defaults' );
isnt( exception {
or defaults' );
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => {}
));
}, undef, '... no refs for defaults' );
isnt( exception {
ts' );
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => bless {} => 'Foo'
));
}, undef, '... no refs for defaults' );
}
{
isnt( exception
Foo->Undef' );
isnt( exception { $foo->vDefined(undef) }, undef, '... undef is NOT a Foo->Defined' );
isnt( exception { $foo->vInt(undef) }, undef, '... undef is NOT a Foo->Int' );
isnt( exception { $
Foo->Number' );
isnt( exception { $foo->vStr(undef) }, undef, '... undef is NOT a Foo->Str' );
isnt( exception { $foo->vString(undef) }, undef, '... undef is NOT a Foo->String' );
isnt( exception { $
ception { $foo->vStr(5) }, undef, '... 5 is a Foo->Str' );
isnt( exception { $foo->vString(5) }, undef, '... 5 is NOT a Foo->String' );
isnt( exception { $foo->vUndef(0.5) }, undef, '... 0.5 is NOT a
'... we can add the handles attribute option' );
# this one will *not* work here ....
::isnt( ::exception {
has '+blang' => (handles => ['hello']);
}, undef, '... we can not alte
Ref');
}, undef, '... can now create an attribute with an improper subtype relation' );
::isnt( ::exception {
has '+other_fail' => (trigger => sub {});
}, undef, '... cannot create
right value for foo');
isnt( exception { $foo->foo([]) }, undef, '... foo is not coercing (as expected)' );
is($foo->bar, 'Foo::bar', '... got the right default value');
isnt( exception { $foo->bar(
tch');
is( exception { $meta->remove_package_symbol('$ref') }, undef, '... removed it' );
isnt($meta->get_package_symbol('$ref'), $reef, '... values match');
ok( my @supers = $meta->su
, '... changed Baz to be immutable' );
isnt( exception { $meta->add_method('xyz', sub{'xxx'}) }, undef, '... exception thrown as expected' );
isnt( exception {
$meta->add_attribute('f
ption thrown as expected' );
isnt( exception { $meta->remove_attribute('fickle') }, undef, '... exception thrown as expected' );
my $reef = \ 'reef';
isnt( exception { $meta->add_package_
>is_stub,
'... the method is not a stub' );
isnt( exception { Class::MOP::Method->wrap }, undef, q{... can't call wrap() without some code} );
isnt( exception { Class::MOP::Method->wrap( [] ) },
't call wrap() without some code} );
isnt( exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, undef, q{... can't call wrap() without some code} );
isnt( exception { Class::MOP::Method->nam
f, q{... can't call name() as a class method} );
isnt( exception { Class::MOP::Method->body }, undef, q{... can't call body() as a class method} );
isnt( exception { Class::MOP::Method->package_name }
$foo->hash_int( {} );
is_deeply( $foo->hash_int, {}, "hash_int - correct contents" );
isnt( exception { $foo->set_hash_int( x => 'foo' ) }, undef, "hash_int - can't set wrong type" );
ents" );
}
{
isnt( exception { $foo->set_h1('foo') }, undef, "h1 - can't set onto undef" );
$foo->h1( {} );
is_deeply( $foo->h1, {}, "h1 - correct contents" );
isnt( exception { $fo
$foo->set_h1( x => 1 );
is_deeply( $foo->h1, { x => 1 }, "h1 - correct contents" );
}
{
isnt( exception { $foo->set_h2('foo') }, undef, "h2 - can't set onto undef" );
$foo->h2( {} );
.. got the right (changed) value for y' );
isnt(
exception {
$point->y('Foo');
},
undef,
'... cannot assign a non-Int to y'
);
isnt(
exception {
Point->new();
... can assign a 0 to x and y'
);
isnt(
exception {
Point->new( x => 10, y => 'Foo' );
},
undef,
'... cannot assign a non-Int to y'
);
isnt(
exception {
Point->ne
ht (cleared) value for z' );
isnt(
exception {
Point3D->new( x => 10, y => 'Foo', z => 3 );
},
undef,
'... cannot assign a non-Int to y'
);
isnt(
exception {
Poin
$foo->array_int( [] );
is_deeply( $foo->array_int, [], "array_int - correct contents" );
isnt( exception { $foo->push_array_int('foo') }, undef, "array_int - can't push wrong type" );
is_
nts" );
}
{
isnt( exception { $foo->push_a1('foo') }, undef, "a1 - can't push onto undef" );
$foo->a1( [] );
is_deeply( $foo->a1, [], "a1 - correct contents" );
isnt( exception { $f
ents" );
$foo->push_a1(1);
is_deeply( $foo->a1, [1], "a1 - correct contents" );
}
{
isnt( exception { $foo->push_a2('foo') }, undef, "a2 - can't push onto undef" );
$foo->a2( [] );
'... set bar successfully with a HASH ref' );
isnt( exception {
$foo->bar(100)
}, undef, '... couldnt set bar successfully with a number' );
isnt( exception {
$foo->bar(sub {})
}, undef, '.
th bar successfully set with a HASH ref' );
isnt( exception {
Foo->new(bar => 50)
}, undef, '... didnt create a new Foo with bar as a number' );
isnt( exception {
Foo->new(bar => sub {})
},
set baz successfully with a CODE ref' );
isnt( exception {
$bar->baz(\(my $var1))
}, undef, '... couldnt set baz successfully with a SCALAR ref' );
isnt( exception {
$bar->baz({})
}, undef,
est::More;
use Test::Fatal;
use Class::MOP;
use Class::MOP::Attribute;
use Class::MOP::Method;
isnt( exception { Class::MOP::Attribute->name }, undef, q{... can't call name() as a class method} );
}
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
is($attr->associated_class, $at
}
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
is($attr->associated_class, $at
error conditions for the subtypes
isnt(
exception {
Address->new( street => {} ),;
},
undef,
'... we die correctly with bad args'
);
isnt(
exception {
Address->n
ew( city => {} ),;
},
undef,
'... we die correctly with bad args'
);
isnt(
exception {
Address->new( state => 'British Columbia' ),;
},
undef,
'... we die correctl
>new( state => 'Connecticut' ),;
},
undef,
'... we live correctly with good args'
);
isnt(
exception {
Address->new( zip_code => 'AF5J6$' ),;
},
undef,
'... we die
tly');
isnt( exception {
$foo->bar([]);
}, undef, '... validation failed correctly' );
isnt( exception {
$foo->bar({ foo => 3 });
}, undef, '... validation failed correctly' );
isnt( except
});
}, undef, '... validation failed correctly' );
isnt( exception {
$foo->baz([ "foo" ]);
}, undef, '... validation failed correctly' );
isnt( exception {
$foo->baz({});
}, undef, '... vali
=> 'text/plain' } );
my $header2 = $r->headers;
isa_ok( $header2, 'HTTP::Headers' );
isnt( $header, $header2, '... created a new HTTP::Header object' );
is( $header2->content_type, '
=> 'text/html' ] );
my $header3 = $r->headers;
isa_ok( $header3, 'HTTP::Headers' );
isnt( $header2, $header3, '... created a new HTTP::Header object' );
is( $header3->content_type,
;
isnt( $header3, $header4, '... created a new HTTP::Header object' );
is( $header4->content_type, 'application/pdf',
'... got the right content type in the header' );
isnt(
( $foobar_class_meta, 'Moose::Meta::Class' );
isnt( exception {
$foo_class_meta->does_role();
}, undef, '... does_role requires a role name' );
isnt( exception {
$foo_class_meta->add_role();
}, undef, '... apply_role requires a role' );
isnt( exception {
$foo_class_meta->add_role( bless( {} => 'Fail' ) );
}, undef, '... apply_role requires a role' );
ok( $foo_class_meta->does_role(
$foo->bar ), '... $foo->bar is undefined' );
isnt( exception {
$foo->baz(1);
}, undef, '... baz is a read-only accessor' );
isnt( exception {
$foo->bar(1);
}, undef,
red attr' );
isa_ok( $anon, 'My::Metaclass' );
cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' );
isnt( exception {
$anon = My::Metaclass->create_anon_class();
}, undef, 'failed to create anon cla
t', 'foo is that' );
cmp_ok( $meta->name, 'eq', 'Class::Name1', 'for the correct class' );
isnt( exception {
$meta
= My::Metaclass->initialize( 'Class::Name2' );
}, undef, 'failed t
'foo is another' );
cmp_ok( $meta->name, 'eq', 'Class::Name3', 'for the correct class' );
isnt( exception {
eval qq{
package Class::Name4;
use metaclass 'My::Metaclass';
isnt( exception {
$foo->bar($foo);
}, undef, '... foo did not pass the type constraint okay' );
is( exception {
$foo->baz($bar);
}, undef, '... baz passed the type constraint okay' );
isnt(
hen see if Class->does(Role)
# if it does not,.. we have a conflict... so we die loudly
::isnt( ::exception {
has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class');
}, undef, '.
hen see if Class->does(Role)
# if it does not,.. we have a conflict... so we die loudly
::isnt( ::exception {
has 'foo' => (isa => 'Bling', does => 'Bar::Class');
}, undef, '... ca
{$obj->_foo(1)}, undef, "$class->_foo is writer" );
is($obj->foo(), 1, "$class->foo is reader");
isnt( exception {$obj->foo(2)}, undef, "$class->foo is not writer" ); # this should fail
ok(!defined $
foo is writer" );
is($obj->foo(), 1, "$class->foo is reader");
isnt( exception {$obj->foo(1)}, undef, "$class->foo is not writer" );
isnt($obj->_foo(), 1, "$class->_foo is not reader");
$class = make
$obj->_foo(1)}, undef, "$class->_foo is writer" );
is($obj->_foo(), 1, "$class->foo is reader");
isnt( exception { make_class('ro', 'accessor', "Test::Class::AccessorRO"); }, undef, "Cant define attr
[], bar => Bar->new);
}, undef, '... Bar->new isa Bar' );
isnt( exception {
Foo->new(arr => [], bar => undef);
}, undef, '... undef isnta Bar' );
is( exception {
Foo->new(arr => [], maybe_ba
ybe_bar => undef);
}, undef, '... undef isa maybe(Bar)' );
isnt( exception {
Foo->new(arr => [], maybe_bar => 1);
}, undef, '... 1 isnta maybe(Bar)' );
is( exception {
Foo->new(arr => []);
}
Foo->new(arr => undef);
}, undef, '... it worked!' );
isnt( exception {
Foo->new(arr => 100);
}, undef, '... failed the type check' );
isnt( exception {
Foo->new(arr => 'hello world');
}, un