Debian Codegraph @

t/09poc01.t

raw
1 #! perl
2
3 use strict;
4 use warnings;
5 use Test::More qw(no_plan);
6
7 package POC::Report;
8
9 use base qw(Data::Report);
10
11 package POC::Report::Text;
12
13 use base qw(Data::Report::Plugin::Text);
14
15 sub _top_heading {
16 my $self = shift;
17 $self->_print("Title line 1\n");
18 $self->_print("Title line 2\n");
19 $self->_print("\n");
20 }
21
22 sub _std_stylist {
23 my ($rep, $row, $col) = @_;
24
25 if ( $col ) {
26 return { line_after => "=" }
27 if $row eq "special" && $col =~ /^(deb|crd)$/;
28 }
29 else {
30 return { line_after => 1 } if $row eq "total";
31 }
32 return;
33 }
34
35 package main;
36
37 my $rep = POC::Report::->create(type => "text");
38 isa_ok($rep, 'POC::Report::Text');
39
40 $rep->set_layout
41 ([ { name => "acct", title => "Acct", width => 6 },
42 { name => "desc", title => "Report", width => 40, align => "|" },
43 { name => "deb", title => "Debet", width => 10, align => "<" },
44 { name => "crd", title => "Credit", width => 10, align => ">" },
45 ]);
46
47 my $out = "";
48 $rep->set_output(\$out);
49 $rep->start;
50
51 is($rep->get_stylist, \&POC::Report::Text::_std_stylist, "CB: stylist");
52 is($rep->get_topheading, \&POC::Report::Text::_top_heading, "CB: heading");
53
54 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
55 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
56 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "special"});
57 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total" });
58 $rep->finish;
59 $rep->close;
60
61 is($rep->{lines}, $= - 11, "linecount");
62
63 my $ref; { undef $/; $ref = <DATA>; }
64 $ref =~ s/[\r\n]/\n/g;
65
66 is($out, $ref, "contents");
67
68 __DATA__
69 Title line 1
70 Title line 2
71
72 Acct Report Debet Credit
73 ------------------------------------------------------------------------
74 one two three four
75 one two three four
76 one two three four
77 ========== ==========
78 one two three four
79 ------------------------------------------------------------------------