use Test::More no_plan;
use Test::Deep;

my $expect = {
   name => re(qr/porky/),
   value => code(sub { $_[0] >= 0 && $_[0] < 10 || (0, "out of range [0,10)")}),
   spigot_state => 'active',
};

my $value = {
   name => 'My name is porky',
   value => 11,                                # <-- fails here
   spigot_state => 'active',
};

cmp_deeply( $value, $expect, 'Whoopee!');

although it looks like I have a bug in the diagnostic output, it shows
undef instead of 11,

F

On 05/08/07, Andy Armstrong <[EMAIL PROTECTED]> wrote:
> I'm sure I've recently seen a test that used something like this:
>
> my $expect = {
>     name => qr/porky/,
>     value => sub { $_[0] >= 0 && $_[0] < 10 },
>     spigot_state => 'active',
> };
>
> my $value = {
>     name => 'My name is porky',
>     value => 11,                                # <-- fails here
>     spigot_state => 'active',
> };
>
> is_magically( $value, $expect, 'Whoopee!');
>
> Where is_magically() tests a data structure against an 'active' data
> structure that can contain constant values, REs and code references.
> Everything compares literally unless it's a coderef or regexp - they
> are applied to the value under test.
>
> Did I imagine it?
>
> --
> Andy Armstrong, hexten.net
>
>

Reply via email to