Util-Underscore
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/01-scalars.t view on Meta::CPAN
plan tests => 5;
my $untainted = 42;
ok !_::is_tainted $untainted, "untainted variable is untainted";
ok !_::is_tainted, "untainted implicit variable is untainted";
_find_tainted_hash_entries(
\my @tainted_env_keys,
\my @untainted_env_keys,
\%ENV,
);
ok 0+@tainted_env_keys, "environment variables are tainted"
or do {
diag("Tainted ENV variables: [@tainted_env_keys]");
diag("Untainted ENV variables: [@untainted_env_keys]");
};
my ($taint_key) = @tainted_env_keys;
my $tainted = $ENV{$taint_key};
ok _::is_tainted $tainted, "tainted variable is tainted";
ok _::is_tainted, "tainted implicit variable is tainted" for $tainted;
};
subtest '_::alias' => sub {
## no critic (ProhibitStringyEval)
if (not eval q{ require Data::Alias; 1 }) {
plan skip_all => q(Data::Alias not installed);
}
# In case Data::Alias doesn't exist, the below calls to _::alias will fail
# to compile. Therefore, optionally inject this stand-in.
BEGIN {
*_::alias = sub { die "_::alias not available" } if not *_::alias{CODE};
}
plan tests => 4;
my $orig = 42;
_::alias my $alias = $orig;
my $copy = $orig;
is $alias, $orig, "positive alias value comparison";
is $copy, $orig, "positive copy value comparison";
is \$alias, \$orig, "positive alias reference comparison";
isnt \$copy, \$orig, "negative copy reference comparison";
};
BEGIN {
package Local::Stringy;
use overload '""' => sub {
my ($self) = @_;
return $$self;
};
sub new {
my ($class, $val) = @_;
return bless \$val => $class;
}
}
my $stringy = Local::Stringy->new("foo");
subtest '_::is_plain' => sub {
plan tests => 7;
ok _::is_plain 42, "positive number";
ok _::is_plain "foo", "positive string";
ok !_::is_plain [], "negative ref";
ok !_::is_plain undef, "negative undef";
ok !_::is_plain $stringy, "negative stringy object";
ok _::is_plain, "positive implicit argument" for "foo";
ok !_::is_plain, "negative implicit argument" for undef;
};
subtest '_::is_string' => sub {
plan tests => 7;
ok _::is_string 42, "positive number";
ok _::is_string "foo", "positive string";
ok !_::is_string [], "negative ref";
ok !_::is_string undef, "negative undef";
ok _::is_string $stringy, "positive stringy object";
ok _::is_string, "positive implicit argument" for "foo";
ok !_::is_string, "negative implicit argument" for undef;
};
{
package Local::IsBool;
use overload bool => sub { 1 };
}
{
package Local::IsString;
use overload q[""] => sub { "foo" };
# While a "bool" method is autogenerated, this doesn't show the intent
# to overload "bool". Therefore, a Local::IsString instance won't be
# considered to be a boolean by "_::is_bool".
# Also, overload::Method doesn't return autogenerated methods.
}
{
package Local::OrdinaryObject;
1;
}
subtest '_::is_bool' => sub {
plan tests => 10;
ok _::is_bool undef, "positive undef";
ok _::is_bool 1, "positive number 1";
ok _::is_bool 0, "positive number 0";
ok _::is_bool "foo", "positive string";
ok !_::is_bool [], "negative reference";
my $booly = bless [] => 'Local::IsBool';
my $stringy = bless [] => 'Local::IsString';
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.541 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )