~ubuntu-branches/ubuntu/trusty/libperl5i-perl/trusty-proposed

« back to all changes in this revision

Viewing changes to t/hash-diff.t

  • Committer: Bazaar Package Importer
  • Author(s): Ivan Kohler
  • Date: 2010-05-08 17:42:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100508174200-7ogg0zrimh9gvcuw
Tags: upstream-2.1.1
ImportĀ upstreamĀ versionĀ 2.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
use perl5i::latest;
 
4
 
 
5
use lib 't/lib';
 
6
 
 
7
use Test::More;
 
8
use Test::perl5i;
 
9
 
 
10
{
 
11
    # Error checking
 
12
 
 
13
    my $h;
 
14
 
 
15
    is_deeply $h = { a => 1 }->diff, { a => 1 };
 
16
    is_deeply $h = {}->diff(), {};
 
17
    is_deeply $h = {}->diff( {} ), {};
 
18
    throws_ok { $h = {}->diff('foo') } qr/Arguments must be/;
 
19
}
 
20
 
 
21
{
 
22
    my %first = ( foo => 1, bar => 2, baz => 3 );
 
23
 
 
24
    my %second = (foo => 1, baz => 2);
 
25
 
 
26
    my %diff = %first->diff(\%second);
 
27
 
 
28
    is_deeply \%diff, { bar => 2, baz => 3 };
 
29
}
 
30
 
 
31
{
 
32
    my %first  = ( foo => { bar => 1 }, baz => 3 );
 
33
    my %second = ( foo => 2, baz => 3 );
 
34
    my %third  = ( foo => { bar => 2 }, quux => [ 'hai' ] );
 
35
 
 
36
    my %diff = %first->diff(\%second, \%third);
 
37
 
 
38
    is_deeply \%diff, { foo => { bar => 1 } };
 
39
}
 
40
 
 
41
done_testing;