diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-07-15 15:33:32 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-07-15 15:33:32 -0400 |
commit | e565af54b1ebba7c6c9e69a984e739f57c12135a (patch) | |
tree | a22fa984fc7bae8d2fd06491efbac43b8e1a45b5 /t/magic.t | |
parent | fad76cca11cf9061a190e14eb7e2c4fa4f1747f2 (diff) | |
download | package-stash-e565af54b1ebba7c6c9e69a984e739f57c12135a.tar.gz package-stash-e565af54b1ebba7c6c9e69a984e739f57c12135a.zip |
sync test suite
Diffstat (limited to 't/magic.t')
-rw-r--r-- | t/magic.t | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -29,4 +29,52 @@ use Package::Stash; is(eval q["@foo"], 'a-b-c'); } +SKIP: { + skip "only need to test for magic in the xs version", 10 + unless $Package::Stash::IMPLEMENTATION eq 'XS'; + skip "magic stashes require perl 5.10+", 10 + unless $] >= 5.010; + skip "magic stashes require Variable::Magic", 10 + unless eval { require Variable::Magic; 1 }; + + my ($fetch, $store); + my $wiz = Variable::Magic::wizard( + fetch => sub { $fetch++ }, + store => sub { $store++ }, + ); + Variable::Magic::cast(\%MagicStashTest::, $wiz); + + my $stash = Package::Stash->new('MagicStashTest'); + + $fetch = 0; + $store = 0; + $stash->get_symbol('@foo'); + is($fetch, 1, "get_symbol fetches (empty slot)"); + is($store, 0, "get_symbol stores (empty slot)"); + + $fetch = 0; + $store = 0; + $stash->get_or_add_symbol('@bar'); + is($fetch, 0, "get_or_add_symbol fetches (empty slot)"); + is($store, 1, "get_or_add_symbol stores (empty slot)"); + + $fetch = 0; + $store = 0; + $stash->add_symbol('@baz', ['baz']); + is($fetch, 0, "add_symbol fetches"); + is($store, 1, "add_symbol stores"); + + $fetch = 0; + $store = 0; + $stash->get_symbol('@baz'); + is($fetch, 1, "get_symbol fetches (populated slot)"); + is($store, 0, "get_symbol stores (populated slot)"); + + $fetch = 0; + $store = 0; + $stash->get_or_add_symbol('@baz'); + is($fetch, 1, "get_or_add_symbol fetches (populated slot)"); + is($store, 0, "get_or_add_symbol stores (populated slot)"); +} + done_testing; |