Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Problem defining a Test::Deep structure to match this arrayref

by JavaFan (Canon)
on May 12, 2010 at 15:04 UTC ( #839657=note: print w/replies, xml ) Need Help??


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');

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2019-10-23 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?