BEGIN {
do
'./t/lib/testutil.pl'
//
do
'./lib/testutil.pl'
//
die
"Can't load testutil.pl"
;
}
my
$apply_ref
= [
[
'a'
,
'q '
],
[
' b '
,
' r'
,
"\rx"
,
undef
],
[
undef
,
"s\n"
,
'y '
],
[
'd '
,
' t '
,
undef
,
'z'
],
];
my
$apply_onerow_ref
= [ [
'd '
,
' t '
,
undef
,
'z'
], ];
my
$apply_onecol_ref
= [ [
'a'
], [
' b '
], [
undef
], [
'd '
] ];
my
$apply_coderef
=
sub
{
tr
/arty/ARTY/
if
defined
(
$_
) };
my
%defaults
= (
apply
=> {
test_procedure
=>
'contextual'
,
arguments
=>
$apply_coderef
,
test_array
=>
$apply_ref
,
check_blessing
=>
'always'
,
},
trim
=> {
test_procedure
=>
'contextual'
,
test_array
=>
$apply_ref
,
check_blessing
=>
'always'
,
},
trim_right
=> {
test_procedure
=>
'contextual'
,
test_array
=>
$apply_ref
,
check_blessing
=>
'always'
,
},
define
=> {
test_procedure
=>
'contextual'
,
test_array
=>
$apply_ref
,
check_blessing
=>
'always'
,
},
);
my
@tests
= (
apply
=> [
{
description
=>
'an array'
,
expected
=> [
[
'A'
,
'q '
],
[
' b '
,
' R'
,
"\rx"
,
undef
],
[
undef
,
"s\n"
,
'Y '
],
[
'd '
,
' T '
,
undef
,
'z'
],
],
},
{
description
=>
'a one-row array'
,
expected
=> [ [
'd '
,
' T '
,
undef
,
'z'
], ],
test_array
=>
$apply_onerow_ref
,
},
{
description
=>
'a one-column array'
,
expected
=> [ [
'A'
], [
' b '
], [
undef
], [
'd '
], ],
test_array
=>
$apply_onecol_ref
,
},
{
description
=>
'an empty array'
,
expected
=> [],
test_array
=> [],
}
],
trim
=> [
{
description
=>
'an array'
,
expected
=> [
[
'a'
,
'q'
],
[
'b'
,
'r'
,
'x'
,
undef
],
[
undef
,
's'
,
'y'
],
[
'd'
,
't'
,
undef
,
'z'
],
],
},
{
description
=>
'a one-row array'
,
expected
=> [ [
'd'
,
't'
,
undef
,
'z'
], ],
test_array
=>
$apply_onerow_ref
,
},
{
description
=>
'a one-column array'
,
expected
=> [ [
'a'
], [
'b'
], [
undef
], [
'd'
], ],
test_array
=>
$apply_onecol_ref
,
},
{
description
=>
'an empty array'
,
expected
=> [],
test_array
=> [],
}
],
trim_right
=> [
{
description
=>
'an array'
,
expected
=> [
[
'a'
,
'q'
],
[
' b'
,
' r'
,
"\rx"
,
undef
],
[
undef
,
's'
,
'y'
],
[
'd'
,
' t'
,
undef
,
'z'
],
],
},
{
description
=>
'a one-row array'
,
expected
=> [ [
'd'
,
' t'
,
undef
,
'z'
], ],
test_array
=>
$apply_onerow_ref
,
},
{
description
=>
'a one-column array'
,
expected
=> [ [
'a'
], [
' b'
], [
undef
], [
'd'
], ],
test_array
=>
$apply_onecol_ref
,
},
{
description
=>
'an empty array'
,
expected
=> [],
test_array
=> [],
}
],
define
=> [
{
description
=>
'an array'
,
expected
=> [
[
'a'
,
'q '
],
[
' b '
,
' r'
,
"\rx"
,
''
],
[
''
,
"s\n"
,
'y '
],
[
'd '
,
' t '
,
''
,
'z'
],
],
},
{
description
=>
'a one-row array'
,
expected
=> [ [
'd '
,
' t '
,
''
,
'z'
], ],
test_array
=>
$apply_onerow_ref
,
},
{
description
=>
'a one-column array'
,
expected
=> [ [
'a'
], [
' b '
], [
''
], [
'd '
], ],
test_array
=>
$apply_onecol_ref
,
},
{
description
=>
'an empty array'
,
expected
=> [],
test_array
=> [],
}
],
);
plan_and_run_generic_tests(\
@tests
, \
%defaults
);