summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-11-28 16:41:38 -0600
committerJesse Luehrs <doy@tozt.net>2011-11-28 16:42:13 -0600
commit8642531f61a9909d1e43cbe77887927c7cc5e517 (patch)
tree9c7c685482d1e07cf50ddd7a993d7dad6f49d51c /t
parent91a618191f37e1b9cceb9823cbbef257d7e834ad (diff)
downloadpackage-stash-8642531f61a9909d1e43cbe77887927c7cc5e517.tar.gz
package-stash-8642531f61a9909d1e43cbe77887927c7cc5e517.zip
initial tests for anonymous packages
Diffstat (limited to 't')
-rw-r--r--t/anon.t45
1 files changed, 45 insertions, 0 deletions
diff --git a/t/anon.t b/t/anon.t
new file mode 100644
index 0000000..bdfbe42
--- /dev/null
+++ b/t/anon.t
@@ -0,0 +1,45 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+use lib 't/lib';
+
+use Test::Requires 'Package::Anon';
+
+use Package::Stash;
+use Symbol;
+
+my $anon = Package::Anon->new;
+my $stash = Package::Stash->new($anon);
+my $obj = $anon->bless({});
+
+{
+ my $code = sub { 'FOO' };
+ $stash->add_symbol('&foo' => $code);
+ is($stash->get_symbol('&foo'), $code);
+ is($obj->foo, 'FOO');
+}
+
+{
+ $anon->{bar} = \123;
+
+ my $code = $stash->get_symbol('&bar');
+ is(ref($code), 'CODE');
+ is($code->(), 123);
+
+ is($obj->bar, 123);
+}
+
+{
+ $anon->{baz} = -1;
+
+ my $code = $stash->get_symbol('&baz');
+ is(ref($code), 'CODE');
+ like(
+ exception { $code->() },
+ qr/Undefined subroutine \&__ANON__::baz called/
+ );
+}
+
+done_testing;