X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F021-weak-ref.t;h=3f054c9610c17456e30ec0b1fc335741ba2df0d3;hb=8cbcbb47d0f02077d07873c553494a884d9c085f;hp=2276724be8539831f1a7b1203accccbfbff6be0e;hpb=3645b3164ce4e4fafa8ee65c515281175da0efe7;p=gitmo%2FMouse.git diff --git a/t/021-weak-ref.t b/t/021-weak-ref.t index 2276724..3f054c9 100644 --- a/t/021-weak-ref.t +++ b/t/021-weak-ref.t @@ -1,9 +1,9 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 21; + +use Test::More tests => 31; use Test::Exception; -use Scalar::Util 'isweak'; my %destroyed; @@ -26,7 +26,9 @@ do { $destroyed{ $self->type }++; } }; +}; +sub do_test{ my $self = Class->new(type => 'accessor'); $self->self($self); @@ -35,15 +37,26 @@ do { $self2->self($self3); for my $object ($self, $self2, $self3) { - ok(isweak($object->{self}), "weak reference"); + ok(Scalar::Util::isweak($object->{self}), "weak reference"); ok($object->self->self->self->self, "we've got circularity"); } -}; +} + +do_test(); is($destroyed{accessor}, 1, "destroyed from the accessor"); is($destroyed{constructor}, 1, "destroyed from the constructor"); is($destroyed{middle}, 1, "casuality of war"); +Class->meta->make_immutable(); +ok(Class->meta->is_immutable, 'make_immutable made it immutable'); +do_test(); + +is($destroyed{accessor}, 2, "destroyed from the accessor (after make_immutable)"); +is($destroyed{constructor}, 2, "destroyed from the constructor (after make_immutable)"); +is($destroyed{middle}, 2, "casuality of war (after make_immutable)"); + + ok(!Class->meta->get_attribute('type')->is_weak_ref, "type is not a weakref"); ok(Class->meta->get_attribute('self')->is_weak_ref, "self IS a weakref");