Test::Deep::This - Test::Deep extension to check predicates on plain scalars
use Test::Deep; use Test::Deep::This qw(this); # exported by default actually cmp_deeply( [0, 1], [!this, this] ); # passes: 0 is false, 1 is true. cmp_deeply( [5, 9], [abs(this - 4) < 2, 10 - sqrt(this) < this * 2], ); # passes: abs(5 - 4) < 2 and 10 - sqrt(9) < 9 * 2. cmp_deeply( { a => 1 }, { a => 10 - sqrt(this) < this * 2 } ); # fails: 10 - sqrt(1) == 9 > 2 == 1 * 2 cmp_deeply( ["123"], [re(qr/^\d+(\d)$/, [this < 4]) & this > 100] ); # passes: 3 < 4 while 123 > 100
Test::Deep::This module extends Test::Deep framework with a new this keyword to denote a "current" nested scalar. Standard unary and binary perl operators can be applied to this to construct some complex predicate expressions. Those predicates are completely interoperable with other Test::Deep comparison operations like re.
Test::Deep::This
this
re
Some native Test::Deep comparators may be expressed via this in a somewhat native manner. For example bool(1) is just this and bool(0) is !this. num(10, 0.01) might be written as abs(this - 10) < 0.01. Any expression of this could be expressed using the Test::Deep code functor, but the later lacks proper diagnostics when the test check fails.
Test::Deep
bool(1)
bool(0)
!this
num(10, 0.01)
abs(this - 10) < 0.01
code
Andrei Mischchenko <me@druxa.ru>
To install Test::Deep::This, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Deep::This
CPAN shell
perl -MCPAN -e shell install Test::Deep::This
For more information on module installation, please visit the detailed CPAN module installation guide.