From: Matt S Trout Date: Sun, 9 Sep 2012 18:31:59 +0000 (+0000) Subject: tests X-Git-Tag: v1.000000~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa8a151f675d6a3e4cbc29e6c4cbcf5d5df465c8;p=p5sagit%2Fcurry.git tests --- diff --git a/t/curry.t b/t/curry.t new file mode 100644 index 0000000..d643f88 --- /dev/null +++ b/t/curry.t @@ -0,0 +1,44 @@ +use strict; +use warnings FATAL => 'all'; +use Test::More qw(no_plan); +use Scalar::Util qw(weaken); +use curry; + +{ + package Foo; + + sub new { bless({}, shift) } + + sub foo { [@_] } +} + +my $foo = Foo->new; + +is_deeply($foo->foo(1), [ $foo, 1 ], 'Direct object call'); +is_deeply($foo->curry::foo->(1), [ $foo, 1 ], 'Curried object call'); + +weaken(my $weak_foo = $foo); + +my $curry = $foo->curry::foo; + +undef($foo); + +ok($weak_foo, 'Weakened object kept alive by curry'); + +undef($curry); + +ok(!$weak_foo, 'Weakened object dead'); + +$foo = Foo->new; + +$curry = $foo->curry::weak::foo; + +is_deeply($curry->(1), [ $foo, 1 ], 'Curried weak object call'); + +weaken($weak_foo = $foo); + +undef($foo); + +ok(!$weak_foo, 'Weak curry does not keep object alive'); + +is($curry->(1), undef, 'Weak curry returns undef after object is dead');