http://www.perlmonks.org?node_id=839657


in reply to Problem defining a Test::Deep structure to match this arrayref

Wouldn't
cmp_deeply($x, any([11,22,[[1],[-1]]], [11,[[1]]), 'test1'); cmp_deeply($y, any([11,22,[[1],[-1]]], [11,[[1]]), 'test2');
do the trick?
  • Comment on Re: Problem defining a Test::Deep structure to match this arrayref
  • Download Code

Replies are listed 'Best First'.
Re^2: Problem defining a Test::Deep structure to match this arrayref
by mje (Curate) on May 12, 2010 at 15:19 UTC

    JavaFan yes it does. I guess I just got lost trying to do it with one structure. Would still be interested if anyone spots a way of doing it without specifying two patterns.

    Working version using JavaFan's suggestion:

    use Test::More tests => 2; use Test::Deep; my $id_re = re('^\d+$'); my $vpt_re = re('^-?1$'); my $x = [ '11', '22', [ [ '-1', ], [ # '1', # only present if '22' above present ] # ] ]; my $y = [ '11', [ [ '-1', ], ] ]; my $comp1 = [ $id_re, [[$vpt_re]] ]; my $comp2 = [ $id_re, $id_re, [[$vpt_re], [$vpt_re]] ]; cmp_deeply($x, any($comp1, $comp2), 'test1'); cmp_deeply($y, any($comp1, $comp2), 'test2');