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