Debian Codegraph @

cpan/Test2-Suite/t/modules/Compare/Base.t

raw
1 use Test2::Bundle::Extended -target => 'Test2::Compare::Base';
2
3 my $one = $CLASS->new();
4 isa_ok($one, $CLASS);
5
6 is($one->delta_class, 'Test2::Compare::Delta', "Got expected delta class");
7
8 is([$one->deltas], [], "no deltas");
9 is([$one->got_lines], [], "no lines");
10
11 is($one->operator, '', "no default operator");
12
13 like(dies { $one->verify }, qr/unimplemented/, "unimplemented");
14 like(dies { $one->name }, qr/unimplemented/, "unimplemented");
15
16 {
17 no warnings 'redefine';
18 *Test2::Compare::Base::name = sub { 'bob' };
19 *Test2::Compare::Base::verify = sub { shift; my %p = @_; $p{got} eq 'xxx' };
20 }
21
22 is($one->render, 'bob', "got name");
23
24 is(
25 [$one->run(id => 'xxx', got => 'xxx', convert => sub { $_[-1] }, seen => {})],
26 [],
27 "Valid"
28 );
29
30 is(
31 [$one->run(id => [META => 'xxx'], got => 'xxy', convert => sub { $_[-1] }, seen => {})],
32 [
33 {
34 verified => '',
35 id => [META => 'xxx'],
36 got => 'xxy',
37 chk => {%$one},
38 children => [],
39 }
40 ],
41 "invalid"
42 );
43
44 $one = $CLASS->new;
45 is($one->lines, [], "no lines");
46
47 my $line1 = __LINE__ + 1;
48 $one = $CLASS->new(builder => sub {
49 print "A";
50 print "B";
51 });
52 my $line2 = __LINE__ - 1;
53
54 is($one->lines, [$line1, $line2], "got lines from builder.");
55
56 $one = $CLASS->new(called => ['foo', 'bar', 42]);
57 is($one->lines, [42], "got line from caller");
58
59 done_testing;