1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
use Test2::Bundle::Extended -target => 'Test2::Compare::Meta';
local *convert = Test2::Compare->can('strict_convert');
subtest simple => sub {
my $one = $CLASS->new();
isa_ok($one, $CLASS, 'Test2::Compare::Base');
is($one->items, [], "generated an empty items array");
is($one->name, '<META CHECKS>', "sane name");
is($one->verify(exists => 0), 0, "Does not verify for non-existant values");
is($one->verify(exists => 1), 1, "always verifies for existing values");
ok(defined $CLASS->new(items => []), "Can provide items");
};
subtest add_prop => sub {
my $one = $CLASS->new();
like(
dies { $one->add_prop(undef, convert(1)) },
qr/prop name is required/,
"property name is required"
);
like(
dies { $one->add_prop('fake' => convert(1)) },
qr/'fake' is not a known property/,
"Must use valid property"
);
like(
dies { $one->add_prop('blessed') },
qr/check is required/,
"Must use valid property"
);
ok($one->add_prop('blessed' => convert('xxx')), "normal");
};
{
package FooBase;
package Foo;
our @ISA = 'FooBase';
}
subtest deltas => sub {
my $one = $CLASS->new();
my $it = bless {a => 1, b => 2, c => 3}, 'Foo';
$one->add_prop('blessed' => 'Foo');
$one->add_prop('reftype' => 'HASH');
$one->add_prop('isa' => 'FooBase');
$one->add_prop('this' => exact_ref($it));
$one->add_prop('size' => 3);
is(
[$one->deltas(got => $it, convert => \&convert, seen => {})],
[],
"Everything matches"
);
my $not_it = bless ['a'], 'Bar';
like(
[$one->deltas(got => $not_it, convert => \&convert, seen => {})],
[
{ verified => F(), got => 'Bar' },
{ verified => F(), got => 'ARRAY' },
{ verified => F(), got => $not_it },
{ verified => F(), got => $not_it },
{ verified => F(), got => 1 },
],
"Nothing matches"
);
like(
[$one->deltas(got => 'a', convert => \&convert, seen => {})],
[
{ verified => F(), got => undef },
{ verified => F(), got => undef },
{ verified => F(), got => 'a' },
{ verified => F(), got => 'a' },
{ verified => F(), got => undef },
],
"Nothing matches, wrong everything"
);
};
done_testing;
|