[Moscow.pm] Test::Deep:

me berekuk.ru
19 06:26:12 PDT 2012


19.07.2012, 14:43, "Maxim Vuets" <maxim.vuets  gmail.com>:
> !
>
> Test::Deep    . -,    
> ,     . -,   
>  .   :   ,   
>   (    defined).
>
>       ?
>
>   ۣ,    .
>
>   SC (special comparison) (,
> Test::Deep::RequiredOptional),      
>      :
>
> use Test::Deep::NoTest ':all';
> my ($ok, $stack) = cmp_details(
> {
> login => 'jsmith',
> #password => 'Hello1',
> age => 24,
> #some => 'rubbish',
> },
> req_opt(
> # Required keys
> {
> login => re(qr/^[a-z0-9]+$/i),
> #password => re(qr/^[\x21-\x7e]+$/),
> },
> # Optional keys
> {
> age => code(sub {(shift || 0) >= 18}),
> color => any(qw/red green blue/),
> }
> )
> );
> say $ok ? 'ok' : ('fail: ', deep_diag($stack));
>
>     SC   $expected (
>    )   :
>
> all(
> superhashof({
> login => re(qr/^[a-z0-9]+$/i),
> #password => re(qr/^[\x21-\x7e]+$/),
> }),
> subhashof({
> login => ignore(),
> #password => ignore(),
> age => code(sub {(shift || 0) >= 18}),
> color => any(qw/red green blue/),
> }),
> )
>
>  .      ,  
>  .     . 
>    --- Params::Validate. :  
>   ( ,    HASHREF, 
>   ).  Test::Deep- ---  
> .
>
> , , ?

.
  'undef | ...':

$ perl -le 'use Test::Deep::NoTest; print eq_deeply({a => 1}, subhashof({ a => undef | re(qr/\d/), b => undef | re(qr/^[XYZ]$/) }))'
1
$ perl -le 'use Test::Deep::NoTest; print eq_deeply({b => "X"}, subhashof({ a => undef | re(qr/\d/), b => undef | re(qr/^[XYZ]$/) }))'
1
$ perl -le 'use Test::Deep::NoTest; print eq_deeply({ a => undef, b => "X"}, subhashof({ a => undef | re(qr/\d/), b => undef | re(qr/^[XYZ]$/) }))'
Use of uninitialized value in pattern match (m//) at /usr/share/perl5/Test/Deep/Regexp.pm line 57.
1
$ perl -le 'use Test::Deep::NoTest; print eq_deeply({a => "blah", b => "X"}, subhashof({ a => undef | re(qr/\d/), b => undef | re(qr/^[XYZ]$/) }))'
0

(      ,     Test::Deep .)


Moscow-pm