Zoffix has asked for the wisdom of the Perl Monks concerning the following question:
Solution: http://perlmonks.org/?node_id=1068407
---- Hey, I have a nested structure that I want to test. The problem that I'm having is I can't figure out how to tell Test::Deep to use a regex for hashref keys. In the example below, the "markets" hashref's keys can be any string, and ideally I want something like re('.') for the key.EDIT: { There seems to be some confusion here. The only reason I said I wanted a re('.') for the key is because the key can be anything and I need to tell Test::Deep to inspect the value of that key. }
How do I tell it to do each hashref's value, akin to the array_each() for arrays? I'm not set in stone regarding a module, so if anyone has better suggestions to accomplish this, please tell me.{ 'markets' => { re('.') => { 'primaryname' => re('.'), 'volume' => re('^[-+.\d]+$'), 'lasttradeprice' => re('^[-+.\d]+$'), 'marketid' => re('^\d+$'), 'secondarycode' => re('.'), 'primarycode' => re('.'), 'lasttradetime' => re('.'), 'label' => re('.'), 'secondaryname' => re('.'), 'buyorders' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), }, ), 'sellorders' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), }, ), 'recenttrades' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), 'id' => re('.'), 'time' => re('.'), }, ), }, }, }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Test::Deep regex on hash keys
by CountZero (Bishop) on Dec 26, 2013 at 09:06 UTC | |
|
Re: Test::Deep regex on hash keys
by LanX (Saint) on Dec 26, 2013 at 08:58 UTC | |
by Zoffix (Acolyte) on Dec 26, 2013 at 09:14 UTC | |
|
Re: Test::Deep regex on hash keys
by Zoffix (Acolyte) on Dec 26, 2013 at 09:44 UTC |