|
Packit |
37d9e7 |
#!/usr/bin/perl
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
use strict;
|
|
Packit |
37d9e7 |
BEGIN {
|
|
Packit |
37d9e7 |
$| = 1;
|
|
Packit |
37d9e7 |
$^W = 1;
|
|
Packit |
37d9e7 |
$ENV{PERL_PARAMS_UTIL_PP} ||= 1;
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
use Test::More tests => 632;
|
|
Packit |
37d9e7 |
use File::Spec::Functions ':ALL';
|
|
Packit |
37d9e7 |
use Scalar::Util 'refaddr';
|
|
Packit |
37d9e7 |
use Params::Util ();
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Utility functions
|
|
Packit |
37d9e7 |
sub true { is( shift, 1, shift || () ) }
|
|
Packit |
37d9e7 |
sub false { is( shift, '', shift || () ) }
|
|
Packit |
37d9e7 |
sub null { is( shift, undef, shift || () ) }
|
|
Packit |
37d9e7 |
sub dies {
|
|
Packit |
37d9e7 |
my ($code, $regexp, $message) = @_;
|
|
Packit |
37d9e7 |
eval "$code";
|
|
Packit |
37d9e7 |
ok( (defined($@) and length($@)), $message );
|
|
Packit |
37d9e7 |
if ( defined $regexp ) {
|
|
Packit |
37d9e7 |
like( $@, $regexp, '... with expected error message' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _STRING
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_STRING()", qr/Not enough arguments/, '...::_STRING() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING(undef), '...::_STRING(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING(''), '...::_STRING(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING({ foo => 1 }), '...::_STRING(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING(sub () { 1 }), '...::_STRING(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING([]), '...::_STRING(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING(\""), '...::_STRING(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_STRING(\"foo"), '...::_STRING(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{0 1 foo _foo foo1 __foo_1 Foo::Bar}, ' ', ' foo' ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_STRING($ident), $ident, "...::_STRING('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_STRING' );
|
|
Packit |
37d9e7 |
ok( defined *_STRING{CODE}, '_STRING imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_STRING()", qr/Not enough arguments/, '...::_STRING() dies' );
|
|
Packit |
37d9e7 |
null( _STRING(undef), '_STRING(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING(''), '_STRING(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING({ foo => 1 }), '_STRING(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING(sub () { 1 }), '_STRING(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING([]), '_STRING(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING(\""), '_STRING(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _STRING(\"foo"), '_STRING(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{0 1 foo _foo foo1 __foo_1 Foo::Bar}, ' ', ' foo' ) {
|
|
Packit |
37d9e7 |
is( _STRING($ident), $ident, "...::_STRING('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _IDENTIFIER
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_IDENTIFIER()", qr/Not enough arguments/, '...::_IDENTIFIER() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(undef), '...::_IDENTIFIER(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(''), '...::_IDENTIFIER(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(1), '...::_IDENTIFIER(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(' foo'), '...::_IDENTIFIER(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER({ foo => 1 }), '...::_IDENTIFIER(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(sub () { 1 }), '...::_IDENTIFIER(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER([]), '...::_IDENTIFIER(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(\""), '...::_IDENTIFIER(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER(\"foo"), '...::_IDENTIFIER(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER("Foo::Bar"), '...::_IDENTIFIER(CLASS) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_IDENTIFIER("foo\n"), '...::_IDENTIFIER(BAD) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{foo _foo foo1 __foo_1} ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_IDENTIFIER($ident), $ident, "...::_IDENTIFIER('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_IDENTIFIER' );
|
|
Packit |
37d9e7 |
ok( defined *_IDENTIFIER{CODE}, '_IDENTIFIER imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_IDENTIFIER()", qr/Not enough arguments/, '...::_IDENTIFIER() dies' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(undef), '_IDENTIFIER(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(''), '_IDENTIFIER(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(1), '_IDENTIFIER(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(' foo'), '_IDENTIFIER(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER({ foo => 1 }), '_IDENTIFIER(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(sub () { 1 }), '_IDENTIFIER(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER([]), '_IDENTIFIER(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(\""), '_IDENTIFIER(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER(\"foo"), '_IDENTIFIER(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER("Foo::Bar"), '_IDENTIFIER(CLASS) returns undef' );
|
|
Packit |
37d9e7 |
null( _IDENTIFIER("foo\n"), '_IDENTIFIER(BAD) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{foo _foo foo1 __foo_1} ) {
|
|
Packit |
37d9e7 |
is( _IDENTIFIER($ident), $ident, "...::_IDENTIFIER('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _CLASS
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_CLASS()", qr/Not enough arguments/, '...::_CLASS() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(undef), '...::_CLASS(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(''), '...::_CLASS(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(1), '...::_CLASS(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(' foo'), '...::_CLASS(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS({ foo => 1 }), '...::_CLASS(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(sub () { 1 }), '...::_CLASS(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS([]), '...::_CLASS(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(\""), '...::_CLASS(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS(\"foo"), '...::_CLASS(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS("D'oh"), '...::_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS("::Foo"), '...::_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CLASS("1::X"), '...::_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{foo _foo foo1 __foo_1 Foo::Bar _Foo::Baaar::Baz X::1} ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_CLASS($ident), $ident, "...::_CLASS('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_CLASS' );
|
|
Packit |
37d9e7 |
ok( defined *_CLASS{CODE}, '_CLASS imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_CLASS()", qr/Not enough arguments/, '_CLASS() dies' );
|
|
Packit |
37d9e7 |
null( _CLASS(undef), '_CLASS(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(''), '_CLASS(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(1), '_CLASS(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(' foo'), '_CLASS(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS({ foo => 1 }), '_CLASS(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(sub () { 1 }), '_CLASS(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS([]), '_CLASS(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(\""), '_CLASS(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS(\"foo"), '_CLASS(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS("D'oh"), '_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS("::Foo"), '_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( _CLASS("1::X"), '_CLASS(bad class) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $ident ( qw{foo _foo foo1 __foo_1 Foo::Bar _Foo::Baaar::Baz X::1} ) {
|
|
Packit |
37d9e7 |
is( _CLASS($ident), $ident, "_CLASS('$ident') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _NUMBER
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_NUMBER()", qr/Not enough arguments/, '...::_NUMBER() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(undef), '...::_NUMBER(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(''), '...::_NUMBER(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(' foo'), '...::_NUMBER(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER({ foo => 1 }), '...::_NUMBER(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(sub () { 1 }), '...::_NUMBER(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER([]), '...::_NUMBER(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(\""), '...::_NUMBER(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER(\"foo"), '...::_NUMBER(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NUMBER("D'oh"), '...::_NUMBER(bad class) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{1 2 10 123456789 -1 0 +1 02 .1 0.013e-3 1e1} ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_NUMBER($id), $id, "...::_NUMBER('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_NUMBER' );
|
|
Packit |
37d9e7 |
ok( defined *_NUMBER{CODE}, '_NUMBER imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_NUMBER()", qr/Not enough arguments/, '_NUMBER() dies' );
|
|
Packit |
37d9e7 |
null( _NUMBER(undef), '_NUMBER(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER(''), '_NUMBER(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER(' foo'), '_NUMBER(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER({ foo => 1 }), '_NUMBER(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER(sub () { 1 }), '_NUMBER(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER([]), '_NUMBER(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER(\""), '_NUMBER(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER(\"foo"), '_NUMBER(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _NUMBER("D'oh"), '_NUMBER(bad class) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{1 2 10 123456789 -1 0 +1 02 .1 0.013e-3 1e1} ) {
|
|
Packit |
37d9e7 |
is( _NUMBER($id), $id, "_NUMBER('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _POSINT
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_POSINT()", qr/Not enough arguments/, '...::_POSINT() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(undef), '...::_POSINT(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(''), '...::_POSINT(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(' foo'), '...::_POSINT(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT({ foo => 1 }), '...::_POSINT(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(sub () { 1 }), '...::_POSINT(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT([]), '...::_POSINT(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(\""), '...::_POSINT(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(\"foo"), '...::_POSINT(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT("D'oh"), '...::_POSINT(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(-1), '...::_POSINT(negative) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT(0), '...::_POSINT(zero) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT("+1"), '...::_POSINT(explicit positive) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_POSINT("02"), '...::_POSINT(zero lead) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{1 2 10 123456789} ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_POSINT($id), $id, "...::_POSINT('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_POSINT' );
|
|
Packit |
37d9e7 |
ok( defined *_POSINT{CODE}, '_POSINT imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_POSINT()", qr/Not enough arguments/, '_POSINT() dies' );
|
|
Packit |
37d9e7 |
null( _POSINT(undef), '_POSINT(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(''), '_POSINT(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(' foo'), '_POSINT(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT({ foo => 1 }), '_POSINT(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(sub () { 1 }), '_POSINT(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT([]), '_POSINT(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(\""), '_POSINT(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(\"foo"), '_POSINT(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT("D'oh"), '_POSINT(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(-1), '_POSINT(negative) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT(0), '_POSINT(zero) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT("+1"), '_POSINT(explicit positive) returns undef' );
|
|
Packit |
37d9e7 |
null( _POSINT("02"), '_POSINT(zero lead) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{1 2 10 123456789} ) {
|
|
Packit |
37d9e7 |
is( _POSINT($id), $id, "_POSINT('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _NONNEGINT
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_NONNEGINT()", qr/Not enough arguments/, '...::_NONNEGINT() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(undef), '...::_NONNEGINT(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(''), '...::_NONNEGINT(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(' foo'), '...::_NONNEGINT(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT({ foo => 1 }), '...::_NONNEGINT(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(sub () { 1 }), '...::_NONNEGINT(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT([]), '...::_NONNEGINT(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(\""), '...::_NONNEGINT(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(\"foo"), '...::_NONNEGINT(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT("D'oh"), '...::_NONNEGINT(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT(-1), '...::_NONNEGINT(negative) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT("+1"), '...::_NONNEGINT(explicit positive) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_NONNEGINT("02"), '...::_NONNEGINT(zero lead) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{0 1 2 10 123456789} ) {
|
|
Packit |
37d9e7 |
is( Params::Util::_NONNEGINT($id), $id, "...::_NONNEGINT('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_NONNEGINT' );
|
|
Packit |
37d9e7 |
ok( defined *_NONNEGINT{CODE}, '_NONNEGINT imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_NONNEGINT()", qr/Not enough arguments/, '_NONNEGINT() dies' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(undef), '_NONNEGINT(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(''), '_NONNEGINT(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(' foo'), '_NONNEGINT(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT({ foo => 1 }), '_NONNEGINT(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(sub () { 1 }), '_NONNEGINT(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT([]), '_NONNEGINT(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(\""), '_NONNEGINT(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(\"foo"), '_NONNEGINT(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT("D'oh"), '_NONNEGINT(bad class) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT(-1), '_NONNEGINT(negative) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT("+1"), '_NONNEGINT(explicit positive) returns undef' );
|
|
Packit |
37d9e7 |
null( _NONNEGINT("02"), '_NONNEGINT(zero lead) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
foreach my $id ( qw{0 1 2 10 123456789} ) {
|
|
Packit |
37d9e7 |
is( _NONNEGINT($id), $id, "_NONNEGINT('$id') returns ok" );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _SCALAR
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $foo = "foo";
|
|
Packit |
37d9e7 |
my $scalar = \$foo;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SCALAR()", qr/Not enough arguments/, '...::_SCALAR() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(undef), '...::_SCALAR(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(\undef), '...::_SCALAR(\undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(''), '...::_SCALAR(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(1), '...::_SCALAR(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR('foo'), '...::_SCALAR(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR({ foo => 1 }), '...::_SCALAR(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(sub () { 1 }), '...::_SCALAR(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR([]), '...::_SCALAR(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR(\""), '...::_SCALAR(null constant) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR(\"foo")), 'SCALAR', '...::_SCALAR(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR($scalar)), 'SCALAR', "...::_SCALAR(['foo']) returns true" );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_SCALAR($scalar)), refaddr($scalar),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_SCALAR' );
|
|
Packit |
37d9e7 |
ok( defined *_SCALAR{CODE}, '_SCALAR imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the imported function
|
|
Packit |
37d9e7 |
dies( "_SCALAR()", qr/Not enough arguments/, '...::_SCALAR() dies' );
|
|
Packit |
37d9e7 |
null( _SCALAR(undef), '...::_SCALAR(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR(\undef), '...::_SCALAR(\undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR(''), '...::_SCALAR(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR(1), '...::_SCALAR(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR('foo'), '...::_SCALAR(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR({ foo => 1 }), '...::_SCALAR(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR(sub () { 1 }), '...::_SCALAR(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR([]), '...::_SCALAR(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR(\""), '...::_SCALAR(null constant) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_SCALAR(\"foo")), 'SCALAR', '...::_SCALAR(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_SCALAR($scalar)), 'SCALAR', "...::_SCALAR(SCALAR) returns true" );
|
|
Packit |
37d9e7 |
is( refaddr(_SCALAR($scalar)), refaddr($scalar),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _SCALAR0
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $null = "";
|
|
Packit |
37d9e7 |
my $scalar0 = \$null;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SCALAR0()", qr/Not enough arguments/, '...::_SCALAR0() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0(undef), '...::_SCALAR0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0(''), '...::_SCALAR0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0(1), '...::_SCALAR0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0('foo'), '...::_SCALAR0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0({ foo => 1 }), '...::_SCALAR0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0(sub () { 1 }), '...::_SCALAR0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SCALAR0([]), '...::_SCALAR0(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR0(\"foo")), 'SCALAR', '...::_SCALAR0(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR0(\"")), 'SCALAR', '...::_SCALAR0(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR0(\undef)), 'SCALAR', '...::_SCALAR0(\undef) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR0($scalar)), 'SCALAR', "...::_SCALAR0(constant) returns true" );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_SCALAR0($scalar0)), 'SCALAR', "...::_SCALAR0(constant) returns true" );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_SCALAR0($scalar)), refaddr($scalar),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_SCALAR0($scalar0)), refaddr($scalar0),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_SCALAR0' );
|
|
Packit |
37d9e7 |
ok( defined *_SCALAR0{CODE}, '_SCALAR0 imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the imported function
|
|
Packit |
37d9e7 |
dies( "_SCALAR0()", qr/Not enough arguments/, '...::_SCALAR0() dies' );
|
|
Packit |
37d9e7 |
null( _SCALAR0(undef), '...::_SCALAR0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0(''), '...::_SCALAR0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0(1), '...::_SCALAR0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0('foo'), '...::_SCALAR0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0({ foo => 1 }), '...::_SCALAR0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0(sub () { 1 }), '...::_SCALAR0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _SCALAR0([]), '...::_SCALAR0(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_SCALAR0(\"foo")), 'SCALAR', '...::_SCALAR0(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_SCALAR0(\"")), 'SCALAR', '...::_SCALAR0(constant) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_SCALAR0(\undef)), 'SCALAR', '...::_SCALAR0(\undef) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_SCALAR0($scalar)), 'SCALAR', "...::_SCALAR0(constant) returns true" );
|
|
Packit |
37d9e7 |
is( ref(_SCALAR0($scalar0)), 'SCALAR', "...::_SCALAR0(constant) returns true" );
|
|
Packit |
37d9e7 |
is( refaddr(_SCALAR0($scalar)), refaddr($scalar),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
is( refaddr(_SCALAR0($scalar0)), refaddr($scalar0),
|
|
Packit |
37d9e7 |
'...::_SCALAR returns the same SCALAR reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _ARRAY
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $array = [ 'foo', 'bar' ];
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_ARRAY()", qr/Not enough arguments/, '...::_ARRAY() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY(undef), '...::_ARRAY(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY(''), '...::_ARRAY(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY(1), '...::_ARRAY(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY('foo'), '...::_ARRAY(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY(\'foo'), '...::_ARRAY(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY({ foo => 1 }), '...::_ARRAY(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY(sub () { 1 }), '...::_ARRAY(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY([]), '...::_ARRAY(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY([ undef ])), 'ARRAY', '...::_ARRAY([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY([ 'foo' ])), 'ARRAY', "...::_ARRAY(['foo']) returns true" );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY($array)), 'ARRAY', '...::_ARRAY returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_ARRAY($array)), refaddr($array),
|
|
Packit |
37d9e7 |
'...::_ARRAY($array) returns the same ARRAY reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_ARRAY' );
|
|
Packit |
37d9e7 |
ok( defined *_ARRAY{CODE}, '_ARRAY imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_ARRAY();", qr/Not enough arguments/, '_ARRAY() dies' );
|
|
Packit |
37d9e7 |
null( _ARRAY(undef), '_ARRAY(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY(''), '_ARRAY(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY(1), '_ARRAY(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY('foo'), '_ARRAY(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY(\'foo'), '_ARRAY(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY({ foo => 1 }), '_ARRAY(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY(sub () { 1 }), '_ARRAY(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY([]), '_ARRAY(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_ARRAY([ undef ])), 'ARRAY', '_ARRAY([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_ARRAY([ 'foo' ])), 'ARRAY', "_ARRAY(['foo']) returns true" );
|
|
Packit |
37d9e7 |
is( ref(_ARRAY($array)), 'ARRAY', '_ARRAY returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is( refaddr(_ARRAY($array)), refaddr($array),
|
|
Packit |
37d9e7 |
'_ARRAY($array) returns the same ARRAY reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _ARRAY0
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_ARRAY0();", qr/Not enough arguments/, '...::_ARRAY0() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0(undef), '...::_ARRAY0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0(''), '...::_ARRAY0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0(1), '...::_ARRAY0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0('foo'), '...::_ARRAY0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0(\'foo'), '...::_ARRAY0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0({ foo => 1 }), '...::_ARRAY0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_ARRAY0(sub () { 1 }), '...::_ARRAY0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY0([])), 'ARRAY', '...::_ARRAY0(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY0([ undef ])), 'ARRAY', '...::_ARRAY0([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY0([ 'foo' ])), 'ARRAY', "...::_ARRAY0(['foo']) returns true" );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_ARRAY0($array)), 'ARRAY', '...::_ARRAY0 returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_ARRAY0($array)), refaddr($array),
|
|
Packit |
37d9e7 |
'...::_ARRAY0($array) returns the same ARRAY reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_ARRAY0' );
|
|
Packit |
37d9e7 |
ok( defined *_ARRAY0{CODE}, '_ARRAY0 imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_ARRAY0();", qr/Not enough arguments/, '_ARRAY0() dies' );
|
|
Packit |
37d9e7 |
null( _ARRAY0(undef), '_ARRAY0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0(''), '_ARRAY0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0(1), '_ARRAY0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0('foo'), '_ARRAY0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0(\'foo'), '_ARRAY0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0({ foo => 1 }), '_ARRAY0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _ARRAY0(sub () { 1 }), '_ARRAY0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_ARRAY0([])), 'ARRAY', '_ARRAY0(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
is( ref(_ARRAY0([ undef ])), 'ARRAY', '_ARRAY0([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_ARRAY0([ 'foo' ])), 'ARRAY', "_ARRAY0(['foo']) returns true" );
|
|
Packit |
37d9e7 |
is( ref(_ARRAY0($array)), 'ARRAY', '_ARRAY0 returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is( refaddr(_ARRAY0($array)), refaddr($array),
|
|
Packit |
37d9e7 |
'_ARRAY0($array) returns the same reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _HASH
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $hash = { 'foo' => 'bar' };
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_HASH();", qr/Not enough arguments/, '...::_HASH() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH(undef), '...::_HASH(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH(''), '...::_HASH(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH(1), '...::_HASH(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH('foo'), '...::_HASH(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH(\'foo'), '...::_HASH(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH([ 'foo' ]), '...::_HASH(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH(sub () { 1 }), '...::_HASH(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH({}), '...::_HASH(empty HASH) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_HASH({ foo => 1 })), 'HASH', '...::_HASH([undef]) returns ok' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_HASH($hash)), 'HASH', '...::_HASH returns an HASH ok' );
|
|
Packit |
37d9e7 |
is(
|
|
Packit |
37d9e7 |
refaddr(Params::Util::_HASH($hash)),
|
|
Packit |
37d9e7 |
refaddr($hash),
|
|
Packit |
37d9e7 |
'...::_HASH($hash) returns the same reference',
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_HASH' );
|
|
Packit |
37d9e7 |
ok( defined *_HASH{CODE}, '_HASH imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_HASH();", qr/Not enough arguments/, '_HASH() dies' );
|
|
Packit |
37d9e7 |
null( _HASH(undef), '_HASH(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH(''), '_HASH(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH(1), '_HASH(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH('foo'), '_HASH(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH(\'foo'), '_HASH(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH([]), '_HASH(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH(sub () { 1 }), '_HASH(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH({}), '...::_HASH(empty HASH) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_HASH({ foo => 1 })), 'HASH', '_HASH([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_HASH($hash)), 'HASH', '_HASH returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is(
|
|
Packit |
37d9e7 |
refaddr(_HASH($hash)),
|
|
Packit |
37d9e7 |
refaddr($hash),
|
|
Packit |
37d9e7 |
'_HASH($hash) returns the same reference',
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _HASH0
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_HASH0();", qr/Not enough arguments/, '...::_HASH0() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0(undef), '...::_HASH0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0(''), '...::_HASH0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0(1), '...::_HASH0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0('foo'), '...::_HASH0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0(\'foo'), '...::_HASH0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0([ 'foo' ]), '...::_HASH0(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_HASH0(sub () { 1 }), '...::_HASH0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_HASH0({})), 'HASH', '...::_HASH0(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_HASH0({ foo => 1 })), 'HASH', '...::_HASH0([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_HASH0($hash)), 'HASH', '...::_HASH0 returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is(
|
|
Packit |
37d9e7 |
refaddr(Params::Util::_HASH0($hash)),
|
|
Packit |
37d9e7 |
refaddr($hash),
|
|
Packit |
37d9e7 |
'...::_HASH0($hash) returns the same reference',
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_HASH0' );
|
|
Packit |
37d9e7 |
ok( defined *_HASH0{CODE}, '_HASH0 imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_HASH0();", qr/Not enough arguments/, '_HASH0() dies' );
|
|
Packit |
37d9e7 |
null( _HASH0(undef), '_HASH0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0(''), '_HASH0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0(1), '_HASH0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0('foo'), '_HASH0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0(\'foo'), '_HASH0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0([]), '_HASH0(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _HASH0(sub () { 1 }), '_HASH0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function (carefully)
|
|
Packit |
37d9e7 |
is( ref(_HASH0({})), 'HASH', '_HASH0(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
is( ref(_HASH0({ foo => 1 })), 'HASH', '_HASH0([undef]) returns true' );
|
|
Packit |
37d9e7 |
is( ref(_HASH0($hash)), 'HASH', '_HASH0 returns an ARRAY ok' );
|
|
Packit |
37d9e7 |
is(
|
|
Packit |
37d9e7 |
refaddr(_HASH0($hash)),
|
|
Packit |
37d9e7 |
refaddr($hash),
|
|
Packit |
37d9e7 |
'_HASH0($hash) returns the same reference',
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _CODE
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $code = sub () { 1 };
|
|
Packit |
37d9e7 |
sub testcode { 3 };
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_CODE' );
|
|
Packit |
37d9e7 |
ok( defined *_CODE{CODE}, '_CODE imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_CODE();", qr/Not enough arguments/, '...::_CODE() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE(undef), '...::_CODE(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE(''), '...::_CODE(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE(1), '...::_CODE(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE('foo'), '...::_CODE(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE(\'foo'), '...::_CODE(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE([ 'foo' ]), '...::_CODE(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_CODE({}), '...::_CODE(empty HASH) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_CODE();", qr/Not enough arguments/, '_CODE() dies' );
|
|
Packit |
37d9e7 |
null( _CODE(undef), '_CODE(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE(''), '_CODE(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE(1), '_CODE(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE('foo'), '_CODE(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE(\'foo'), '_CODE(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE([]), '_CODE(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _CODE({}), '...::_CODE(empty HASH) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the actual function
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_CODE(sub { 2 })), 'CODE', '...::_CODE(anon) returns ok' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_CODE($code)), 'CODE', '...::_CODE(ref) returns ok' );
|
|
Packit |
37d9e7 |
is( ref(Params::Util::_CODE(\&testsub)), 'CODE', '...::_CODE(\&func) returns ok' );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_CODE($code)), refaddr($code),
|
|
Packit |
37d9e7 |
'...::_CODE(ref) returns the same reference');
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_CODE(\&testsub)), refaddr(\&testsub),
|
|
Packit |
37d9e7 |
'...::_CODE(\&func) returns the same reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test good things against the imported function
|
|
Packit |
37d9e7 |
is( ref(_CODE(sub { 2 })), 'CODE', '_CODE(anon) returns ok' );
|
|
Packit |
37d9e7 |
is( ref(_CODE($code)), 'CODE', '_CODE(ref) returns ok' );
|
|
Packit |
37d9e7 |
is( ref(_CODE(\&testsub)), 'CODE', '_CODE(\&func) returns ok' );
|
|
Packit |
37d9e7 |
is( refaddr(_CODE($code)), refaddr($code),
|
|
Packit |
37d9e7 |
'_CODE(ref) returns the same reference');
|
|
Packit |
37d9e7 |
is( refaddr(_CODE(\&testsub)), refaddr(\&testsub),
|
|
Packit |
37d9e7 |
'_CODE(\&func) returns the same reference');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _INSTANCE
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my $s1 = "foo";
|
|
Packit |
37d9e7 |
my $s2 = "bar";
|
|
Packit |
37d9e7 |
my $s3 = "baz";
|
|
Packit |
37d9e7 |
my $scalar1 = \$s1;
|
|
Packit |
37d9e7 |
my $scalar2 = \$s2;
|
|
Packit |
37d9e7 |
my $scalar3 = \$s3;
|
|
Packit |
37d9e7 |
my @objects = (
|
|
Packit |
37d9e7 |
bless( {}, 'Foo'),
|
|
Packit |
37d9e7 |
bless( [], 'Foo'),
|
|
Packit |
37d9e7 |
bless( $scalar1, 'Foo'),
|
|
Packit |
37d9e7 |
bless( {}, 'Bar'),
|
|
Packit |
37d9e7 |
bless( [], 'Bar'),
|
|
Packit |
37d9e7 |
bless( $scalar1, 'Bar'),
|
|
Packit |
37d9e7 |
bless( {}, 'Baz'),
|
|
Packit |
37d9e7 |
bless( [], 'Baz'),
|
|
Packit |
37d9e7 |
bless( $scalar3, 'Baz'),
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_INSTANCE()", qr/Not enough arguments/, '...::_INSTANCE() dies' );
|
|
Packit |
37d9e7 |
dies( "Params::Util::_INSTANCE(bless {}, 'Foo')", qr/Not enough arguments/, '...::_INSTANCE(object) dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(undef, 'Foo'), '...::_INSTANCE(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE('', 'Foo'), '...::_INSTANCE(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(1, 'Foo'), '...::_INSTANCE(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE('foo', 'Foo'), '...::_INSTANCE(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE({ foo => 1 }, 'Foo'), '...::_INSTANCE(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(sub () { 1 }, 'Foo'), '...::_INSTANCE(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE([], 'Foo'), '...::_INSTANCE(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(\"", 'Foo'), '...::_INSTANCE(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(\"foo", 'Foo'), '...::_INSTANCE(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_INSTANCE(bless({},'Bad'), 'Foo'), '...::_INSTANCE(bad object) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_INSTANCE' );
|
|
Packit |
37d9e7 |
ok( defined *_INSTANCE{CODE}, '_INSTANCE imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_INSTANCE()", qr/Not enough arguments/, '_INSTANCE() dies' );
|
|
Packit |
37d9e7 |
dies( "_INSTANCE(bless {}, 'Foo')", qr/Not enough arguments/, '_INSTANCE(object) dies' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(undef, 'Foo'), '_INSTANCE(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE('', 'Foo'), '_INSTANCE(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(1, 'Foo'), '_INSTANCE(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE('foo', 'Foo'), '_INSTANCE(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE({ foo => 1 }, 'Foo'), '_INSTANCE(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(sub () { 1 }, 'Foo'), '_INSTANCE(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE([], 'Foo'), '_INSTANCE(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(\"", 'Foo'), '_INSTANCE(null constant) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(\"foo", 'Foo'), '_INSTANCE(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _INSTANCE(bless({},'Bad'), 'Foo'), '_INSTANCE(bad object) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Testing good things is a little more complicated in this case,
|
|
Packit |
37d9e7 |
# so lets do the basic ones first.
|
|
Packit |
37d9e7 |
foreach my $object ( @objects ) {
|
|
Packit |
37d9e7 |
ok( Params::Util::_INSTANCE($object, 'Foo'), '...::_INSTANCE(object, class) returns true when expected' );
|
|
Packit |
37d9e7 |
is( refaddr(Params::Util::_INSTANCE($object, 'Foo')), refaddr($object), '...::_INSTANCE(object, class) returns the same object' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Testing good things is a little more complicated in this case,
|
|
Packit |
37d9e7 |
# so lets do the basic ones first.
|
|
Packit |
37d9e7 |
foreach my $object ( @objects ) {
|
|
Packit |
37d9e7 |
ok( _INSTANCE($object, 'Foo'), '_INSTANCE(object, class) returns true when expected' );
|
|
Packit |
37d9e7 |
is( refaddr(_INSTANCE($object, 'Foo')), refaddr($object), '_INSTANCE(object, class) returns the same object' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
SKIP: {
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_INSTANCEDOES' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
skip "DOES tests do not make sense on perls before 5.10", 19
|
|
Packit |
37d9e7 |
unless $] >= 5.010;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
null( _INSTANCEDOES(bless({},'Bad'), 'Foo'), '_INSTANCEDOES(bad object) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
foreach my $object ( @objects ) {
|
|
Packit |
37d9e7 |
ok( _INSTANCEDOES($object, 'Foo'), '_INSTANCEDOES(object, class) returns true when expected' );
|
|
Packit |
37d9e7 |
is( refaddr(_INSTANCEDOES($object, 'Foo')), refaddr($object), '_INSTANCEDOES(object, class) returns the same object' );
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _REGEX
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_REGEX();", qr/Not enough arguments/, '...::_REGEX() dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX(undef), '...::_REGEX(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX(''), '...::_REGEX(STRING0) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX(1), '...::_REGEX(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX('foo'), '...::_REGEX(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX(\'foo'), '...::_REGEX(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX([ 'foo' ]), '...::_REGEX(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX(sub () { 1 }), '...::_REGEX(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX({}), '...::_REGEX(HASH0) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_REGEX({ foo => 1 }), '...::_REGEX(HASH) returns undef' );
|
|
Packit |
37d9e7 |
ok( Params::Util::_REGEX(qr//), '...::_REGEX(qr//) ok' );
|
|
Packit |
37d9e7 |
ok( Params::Util::_REGEX(qr/foo/), '...::_REGEX(qr//) ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_REGEX' );
|
|
Packit |
37d9e7 |
ok( defined *_REGEX{CODE}, '_REGEX imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_REGEX();", qr/Not enough arguments/, '_REGEX() dies' );
|
|
Packit |
37d9e7 |
null( _REGEX(undef), '_REGEX(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX(''), '_REGEX(STRING0) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX(1), '_REGEX(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX('foo'), '_REGEX(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX(\'foo'), '_REGEX(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX([]), '_REGEX(ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX(sub () { 1 }), '_REGEX(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX({}), 'REGEX(HASH0) returns undef' );
|
|
Packit |
37d9e7 |
null( _REGEX({ foo => 1 }), 'REGEX(HASH) returns undef' );
|
|
Packit |
37d9e7 |
ok( _REGEX(qr//), '_REGEX(qr//) ok' );
|
|
Packit |
37d9e7 |
ok( _REGEX(qr/foo/), '_REGEX(qr//) ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _SET
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
my %set = (
|
|
Packit |
37d9e7 |
good => [ map { bless {} => 'Foo' } qw(1..3) ],
|
|
Packit |
37d9e7 |
mixed => [ map { bless {} => "Foo$_" } qw(1..3) ],
|
|
Packit |
37d9e7 |
unblessed => [ map { {} } qw(1..3) ],
|
|
Packit |
37d9e7 |
);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SET()", qr/Not enough arguments/, '...::_SET() dies' );
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SET([])", qr/Not enough arguments/, '...::_SET(single) dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET(undef, 'Foo'), '...::_SET(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET('', 'Foo'), '...::_SET(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET(1, 'Foo'), '...::_SET(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET('foo', 'Foo'), '...::_SET(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET(\'foo', 'Foo'), '...::_SET(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET({ foo => 1 }, 'Foo'), '...::_SET(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET(sub () { 1 }, 'Foo'), '...::_SET(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET([], 'Foo'), '...::_SET(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
ok( Params::Util::_SET($set{good}, 'Foo'), '...::_SET(homogenous ARRAY) returns true' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET($set{mixed}, 'Foo'), '...::_SET(mixed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET($set{unblessed}, 'Foo'), '...::_SET(unblessed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_SET' );
|
|
Packit |
37d9e7 |
ok( defined *_SET{CODE}, '_SET imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_SET()", qr/Not enough arguments/, '_SET() dies' );
|
|
Packit |
37d9e7 |
dies( "_SET([])", qr/Not enough arguments/, '_SET(single) dies' );
|
|
Packit |
37d9e7 |
null( _SET(undef, 'Foo'), '_SET(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET('', 'Foo'), '_SET(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET(1, 'Foo'), '_SET(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET('foo', 'Foo'), '_SET(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET(\'foo', 'Foo'), '_SET(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET({ foo => 1 }, 'Foo'), '_SET(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET(sub () { 1 }, 'Foo'), '_SET(CODE) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET([], 'Foo'), '_SET(empty ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
ok( _SET($set{good}, 'Foo'), '_SET(homogenous ARRAY) returns true');
|
|
Packit |
37d9e7 |
null( _SET($set{mixed}, 'Foo'), '_SET(mixed ARRAY) returns undef');
|
|
Packit |
37d9e7 |
null( _SET($set{unblessed}, 'Foo'), '_SET(unblessed ARRAY) returns undef');
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
#####################################################################
|
|
Packit |
37d9e7 |
# Tests for _SET0
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SET0()", qr/Not enough arguments/, '...::_SET0() dies' );
|
|
Packit |
37d9e7 |
dies( "Params::Util::_SET0([])", qr/Not enough arguments/, '...::_SET0(single) dies' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0(undef, 'Foo'), '...::_SET0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0('', 'Foo'), '...::_SET0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0(1, 'Foo'), '...::_SET0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0('foo', 'Foo'), '...::_SET0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0(\'foo', 'Foo'), '...::_SET0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0({ foo => 1 }, 'Foo'), '...::_SET0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0(sub () { 1 }, 'Foo'), '...::_SET0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
ok( Params::Util::_SET0([], 'Foo'), '...::_SET0(empty ARRAY) returns true' );
|
|
Packit |
37d9e7 |
ok( Params::Util::_SET0($set{good}, 'Foo'), '...::_SET0(homogenous ARRAY) returns true' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0($set{mixed}, 'Foo'), '...::_SET0(mixed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( Params::Util::_SET0($set{unblessed}, 'Foo'), '...::_SET0(unblessed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Import the function
|
|
Packit |
37d9e7 |
use_ok( 'Params::Util', '_SET0' );
|
|
Packit |
37d9e7 |
ok( defined *_SET0{CODE}, '_SET0 imported ok' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Test bad things against the actual function
|
|
Packit |
37d9e7 |
dies( "_SET0()", qr/Not enough arguments/, '_SET0() dies' );
|
|
Packit |
37d9e7 |
dies( "_SET0([])", qr/Not enough arguments/, '_SET0(single) dies' );
|
|
Packit |
37d9e7 |
null( _SET0(undef, 'Foo'), '_SET0(undef) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0('', 'Foo'), '_SET0(nullstring) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0(1, 'Foo'), '_SET0(number) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0('foo', 'Foo'), '_SET0(string) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0(\'foo', 'Foo'), '_SET0(SCALAR) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0({ foo => 1 }, 'Foo'), '_SET0(HASH) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0(sub () { 1 }, 'Foo'), '_SET0(CODE) returns undef' );
|
|
Packit |
37d9e7 |
ok( _SET0([], 'Foo'), '_SET0(empty ARRAY) returns true' );
|
|
Packit |
37d9e7 |
ok( _SET0($set{good}, 'Foo'), '_SET0(homogenous ARRAY) returns true' );
|
|
Packit |
37d9e7 |
null( _SET0($set{mixed}, 'Foo'), '_SET0(mixed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
null( _SET0($set{unblessed}, 'Foo'), '_SET0(unblessed ARRAY) returns undef' );
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
exit(0);
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Base class
|
|
Packit |
37d9e7 |
package Foo;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
sub foo { 1 }
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Normal inheritance
|
|
Packit |
37d9e7 |
package Bar;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
use vars qw{@ISA};
|
|
Packit |
37d9e7 |
BEGIN {
|
|
Packit |
37d9e7 |
@ISA = 'Foo';
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Coded isa
|
|
Packit |
37d9e7 |
package Baz;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
sub isa {
|
|
Packit |
37d9e7 |
return 1 if $_[1] eq 'Foo';
|
|
Packit |
37d9e7 |
shift->SUPER::isa(@_);
|
|
Packit |
37d9e7 |
}
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
# Not a subclass
|
|
Packit |
37d9e7 |
package Bad;
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
sub bad { 1 }
|
|
Packit |
37d9e7 |
|
|
Packit |
37d9e7 |
1;
|