The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Deep::This - Test::Deep extension to check predicates on plain scalars

SYNOPSIS

  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

DESCRIPTION

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.

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.

SEE ALSO

Test::Deep

MAINTAINER and AUTHOR

  Andrei Mischchenko <me@druxa.ru>