Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (27 sloc) 0.822 kb
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
#!/usr/bin/env perl

use perl5i::latest;

use lib 't/lib';

use Test::More;
use Test::perl5i;

{
    # Error checking

    my $h;

    is_deeply $h = { a => 1 }->intersect, { a => 1 };
    is_deeply $h = {}->intersect(), {};
    is_deeply $h = {}->intersect( {} ), {};
    throws_ok { $h = {}->intersect('foo') } qr/Arguments must be/;
}

{
    my %first = ( foo => 1, bar => 2, baz => 3 );

    my %second = (foo => 1, baz => 2);

    my %intersect = %first->intersect(\%second);

    is_deeply \%intersect, { foo => 1 };
}

{
    my %first = ( foo => { bar => 1 }, baz => 3 );
    my %second = ( foo => { bar => 1 }, baz => 3 );
    my %third = ( foo => { bar => 1 }, quux => [ 'hai' ] );

    my %intersect = %first->intersect(\%second, \%third);

    is_deeply \%intersect, { foo => { bar => 1 } };
}

done_testing;
Something went wrong with that request. Please try again.