1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Ause Test::More tests => 19;
1N/A
1N/ABEGIN { $_ = 'foo'; } # because Symbol used to clobber $_
1N/A
1N/Ause Symbol;
1N/A
1N/Aok( $_ eq 'foo', 'check $_ clobbering' );
1N/A
1N/A
1N/A# First test gensym()
1N/A$sym1 = gensym;
1N/Aok( ref($sym1) eq 'GLOB', 'gensym() returns a GLOB' );
1N/A
1N/A$sym2 = gensym;
1N/A
1N/Aok( $sym1 ne $sym2, 'gensym() returns a different GLOB' );
1N/A
1N/Aungensym $sym1;
1N/A
1N/A$sym1 = $sym2 = undef;
1N/A
1N/A# Test geniosym()
1N/A
1N/Ause Symbol qw(geniosym);
1N/A
1N/A$sym1 = geniosym;
1N/Alike( $sym1, qr/=IO\(/, 'got an IO ref' );
1N/A
1N/A$FOO = 'Eymascalar';
1N/A*FOO = $sym1;
1N/A
1N/Ais( $sym1, *FOO{IO}, 'assigns into glob OK' );
1N/A
1N/Ais( $FOO, 'Eymascalar', 'leaves scalar alone' );
1N/A
1N/A{
1N/A local $^W=1; # 5.005 compat.
1N/A my $warn;
1N/A local $SIG{__WARN__} = sub { $warn .= "@_" };
1N/A readline FOO;
1N/A like( $warn, qr/unopened filehandle/, 'warns like an unopened filehandle' );
1N/A}
1N/A
1N/A# Test qualify()
1N/Apackage foo;
1N/A
1N/Ause Symbol qw(qualify); # must import into this package too
1N/A
1N/A::ok( qualify("x") eq "foo::x", 'qualify() with a simple identifier' );
1N/A::ok( qualify("x", "FOO") eq "FOO::x", 'qualify() with a package' );
1N/A::ok( qualify("BAR::x") eq "BAR::x",
1N/A 'qualify() with a qualified identifier' );
1N/A::ok( qualify("STDOUT") eq "main::STDOUT",
1N/A 'qualify() with a reserved identifier' );
1N/A::ok( qualify("ARGV", "FOO") eq "main::ARGV",
1N/A 'qualify() with a reserved identifier and a package' );
1N/A::ok( qualify("_foo") eq "foo::_foo",
1N/A 'qualify() with an identifier starting with a _' );
1N/A::ok( qualify("^FOO") eq "main::\cFOO",
1N/A 'qualify() with an identifier starting with a ^' );
1N/A
1N/A# tests for delete_package
1N/Apackage main;
1N/A$Transient::variable = 42;
1N/Aok( exists $::{'Transient::'}, 'transient stash exists' );
1N/Aok( defined $Transient::{variable}, 'transient variable in stash' );
1N/ASymbol::delete_package('Transient');
1N/Aok( !exists $Transient::{variable}, 'transient variable no longer in stash' );
1N/Ais( scalar(keys %Transient::), 0, 'transient stash is empty' );
1N/Aok( !exists $::{'Transient::'}, 'no transient stash' );