| 12
 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
 
 | #!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Catmandu::Fix::set_field;
my $pkg;
BEGIN {
    $pkg = 'Catmandu::Fix::Condition::in';
    use_ok $pkg;
}
my $cond = $pkg->new('foo', 'bar');
$cond->pass_fixes([Catmandu::Fix::set_field->new('test', 'pass')]);
$cond->fail_fixes([Catmandu::Fix::set_field->new('test', 'fail')]);
# Integers
is_deeply $cond->fix({foo => 1, bar => 1}),
    {foo => 1, bar => 1, test => 'pass'};
is_deeply $cond->fix({foo => 1, bar => 2}),
    {foo => 1, bar => 2, test => 'fail'};
# Strings
is_deeply $cond->fix({foo => "hotel", bar => "hotel"}),
    {foo => "hotel", bar => "hotel", test => 'pass'};
is_deeply $cond->fix({foo => "hotel", bar => "tango"}),
    {foo => "hotel", bar => "tango", test => 'fail'};
# Empty fields
is_deeply $cond->fix({foo => "", bar => ""}),
    {foo => "", bar => "", test => 'pass'};
is_deeply $cond->fix({foo => undef, bar => undef}),
    {foo => undef, bar => undef, test => 'pass'};
is_deeply $cond->fix({}), {test => 'fail'};
# Arrays
is_deeply $cond->fix({foo => [1, 2, 3], bar => [1, 2, 3]}),
    {foo => [1, 2, 3], bar => [1, 2, 3], test => 'pass'};
is_deeply $cond->fix({foo => [1, 2, 3], bar => [3, 2, 1]}),
    {foo => [1, 2, 3], bar => [3, 2, 1], test => 'fail'};
is_deeply $cond->fix({foo => [1, 2, 3], bar => [1, 2, 3, 4]}),
    {foo => [1, 2, 3], bar => [1, 2, 3, 4], test => 'fail'};
is_deeply $cond->fix({foo => [], bar => []}),
    {foo => [], bar => [], test => 'pass'};
# Hashes
is_deeply $cond->fix({foo => {a => 'b'}, bar => {a => 'b'}}),
    {foo => {a => 'b'}, bar => {a => 'b'}, test => 'pass'};
# ... perl weirdnes ...
is_deeply $cond->fix({foo => {a => 'b'}, bar => ['a', 'b']}),
    {foo => {a => 'b'}, bar => ['a', 'b'], test => 'pass'};
is_deeply $cond->fix(
    {foo => {a => 'b', c => [0, 1]}, bar => {a => 'b', c => [0, 1]}}),
    {
    foo  => {a => 'b', c => [0, 1]},
    bar  => {a => 'b', c => [0, 1]},
    test => 'pass'
    };
done_testing 15;
 |