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