root/branches/release-40/t/lib/Test/Deep/Any.pm @ 2583

Revision 2583, 0.8 kB (checked in by mpaschal, 18 months ago)

Add Test::Deep to t/lib, since we already use it in driver-tests.pl
BugzID: 79953

Line 
1use strict;
2use warnings;
3
4package Test::Deep::Any;
5
6use Test::Deep::Cmp;
7
8use overload
9        '&' => \&add,
10        fallback => 1,
11;
12
13sub init
14{
15        my $self = shift;
16
17        my @list = map {Test::Deep::wrap($_)} @_;
18
19        $self->{val} = \@list;
20}
21
22sub descend
23{
24        my $self = shift;
25        my $got = shift;
26
27        foreach my $cmp (@{$self->{val}})
28        {
29                return 1 if Test::Deep::eq_deeply_cache($got, $cmp);
30        }
31
32        return 0;
33}
34
35sub diagnostics
36{
37        my $self = shift;
38        my ($where, $last) = @_;
39
40        my $expect = $self->{val};
41
42        my $got = $self->renderGot($last->{got});
43        my $things = join(", ", map {$_->renderExp} @$expect);
44
45        my $diag = <<EOM;
46Comparing $where with Any
47got      : $got
48expected : Any of ( $things )
49EOM
50
51        $diag =~ s/\n+$/\n/;
52        return $diag;
53}
54
55sub add
56{
57        my $self = shift;
58        my $expect = shift;
59
60        push(@{$self->{val}}, Test::Deep::wrap($expect));
61
62        return $self;
63}
64
651;
Note: See TracBrowser for help on using the browser.