Comparisons
NAME
Test::Declare::Comparisons - fuzzy comparators for Test::Declare
SYNOPSIS
expected => {
return-value => roughly(&[>], 10), # we'll get back a number bigger than 10
}
expected => {
return-value => superhashof({ foo => 1, bar => 2 }),
}
DESCRIPTION
When writing tests using Test::Declare, exact comparisons may not always be
suitable or even possible. In such cases you can use roughly
to change the
test behaviour to something more fuzzy. The syntax is:
return-value => roughly($operator, $right-hand-side)
For example:
# I don't know what the value is, only that it's less than 10
return-value => roughly(&[<], 10),
$operator
is typically intended to be one of the builtin infix operators but
any Sub which takes 2 positional arguments should do. roughly
works on all
expectations which involve data, i.e. return-value/stdout/stderr/mutates
.
Some Test::Deep style operators are also exported from here:
subhashof({some => 'hash'}),
superhashof({some => hash', with => 'more', data => 'then we want to test'})
Note that unlike Test::Deep these are not (currently?) available at arbitrary depths, only as a top-level construct.