changelog
[gitmo/Package-Stash-XS.git] / t / 07-edge-cases.t
CommitLineData
25c87f5c 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
6use Package::Stash;
7
8{
9 package Foo;
10 use constant FOO => 1;
11 use constant BAR => \1;
12 use constant BAZ => [];
13 use constant QUUX => {};
14 use constant QUUUX => sub { };
15 sub normal { }
16 sub stub;
17 sub normal_with_proto () { }
18 sub stub_with_proto ();
19
20 our $SCALAR;
f7543739 21 our $SCALAR_WITH_VALUE = 1;
25c87f5c 22 our @ARRAY;
23 our %HASH;
24}
25
26my $stash = Package::Stash->new('Foo');
d551a208 27{ local $TODO = $] < 5.010 ? "undef scalars aren't visible on 5.8" : undef;
15c104e2 28ok($stash->has_symbol('$SCALAR'), '$SCALAR');
d551a208 29}
15c104e2 30ok($stash->has_symbol('$SCALAR_WITH_VALUE'), '$SCALAR_WITH_VALUE');
31ok($stash->has_symbol('@ARRAY'), '@ARRAY');
32ok($stash->has_symbol('%HASH'), '%HASH');
25c87f5c 33is_deeply(
15c104e2 34 [sort $stash->list_all_symbols('CODE')],
25c87f5c 35 [qw(BAR BAZ FOO QUUUX QUUX normal normal_with_proto stub stub_with_proto)],
36 "can see all code symbols"
37);
38
15c104e2 39$stash->add_symbol('%added', {});
40ok(!$stash->has_symbol('$added'), '$added');
41ok(!$stash->has_symbol('@added'), '@added');
42ok($stash->has_symbol('%added'), '%added');
f7543739 43
15c104e2 44my $constant = $stash->get_symbol('&FOO');
cb4df463 45is(ref($constant), 'CODE', "expanded a constant into a coderef");
46
25c87f5c 47done_testing;