#!/usr/bin/env perl
our
(
$mydir
,
$myname
);
BEGIN {
my
$location
= (-l $0) ? abs_path($0) : $0;
$location
=~ /(.*?)([^\/]+?)_?\z/s or
die
"?"
;
(
$mydir
,
$myname
) = ($1, $2);
}
{
BEGIN {
*is_age
= both \
&is_natural0
,
sub
{
$_
[0] < 130 }
}
use
FP::Struct [[\
&is_string
,
"name"
], [\
&is_age
,
"age"
]];
_END_
}
{
[both(\
&is_natural0
, less_than 130),
"age"
]];
_END_
}
sub
test {
my
(
$class
) =
@_
;
my
$f
=
$class
->new(
"Heinz"
, 105);
TEST {
$f
->age }
105;
TEST {
$f
->can(
"is_age"
)
}
undef
;
TEST_EXCEPTION {
$f
=
$class
->new(
"Maria"
, 1300) }
'unacceptable value for field \'age\': 1300'
;
TEST_EXCEPTION {
$f
=
$class
->new(
"Maria"
, 104.5) }
'unacceptable value for field \'age\': \'104.5\''
;
}
test
"Foo"
;
test
"Bar"
;
TEST { is_pure 11 }
1;
TEST {
my
$x
= 11;
$x
++; is_pure
$x
}
1;
TEST {
my
$x
= 11;
$x
++; is_pure_object
$x
}
undef
;
TEST { is_pure cons 1, 2 }
1;
TEST { is_pure_object cons 1, 2 }
1;
TEST { is_pure [1, 2] }
''
;
TEST { is_pure purearray 1, 2 }
1;
TEST {
is_pure lazy { cons 1, 2 }
}
0;
my
$a
= [1, 2];
TEST { is_pure(FP::OrderedCollection->unsafe_new_from_array(
$a
)) }
1;
TEST { is_pure(FP::OrderedCollection->new_from_array(
$a
)) }
1;
perhaps_run_tests
"main"
or
do
{
FP::Repl::repl();
}