Debian Codegraph @

t/03csv03.t

raw
1 #! perl
2
3 use strict;
4 use warnings;
5 use Test::More qw(no_plan);
6
7 use Data::Report;
8
9 my $rep = Data::Report::->create
10 (type => "csv",
11 layout => [ { name => "acct", title => "Acct", width => 6 },
12 { name => "desc", title => "Report", width => 40, align => "|" },
13 { name => "deb", title => "Debet", width => 10, align => "<" },
14 { name => "crd", title => "Credit", width => 10, align => ">" },
15 ],
16 );
17
18 my $out = "";
19 $rep->set_stylist(sub {
20 my ($self, $row, $col) = @_;
21 return { ignore => 1 } if $row && $row eq "total" && !$col;
22 return;
23 });
24 $rep->set_output(\$out);
25 $rep->start;
26 $rep->add({ acct => 1234, desc => "two", deb => "three", crd => "four" });
27 $rep->add({ acct => 1235, desc => "two", deb => "three", crd => "four" });
28 $rep->add({ acct => 1236, desc => "two", deb => "three", crd => "four" });
29 $rep->add({ desc => "total", deb => "three", crd => "four", _style => "total" });
30 $rep->finish;
31 $rep->close;
32
33 my $ref; { undef $/; $ref = <DATA> }
34 $ref =~ s/[\r\n]/\n/g;
35 $out =~ s/[\r\n]/\n/g;
36 is($out, $ref);
37
38 __DATA__
39 "Acct","Report","Debet","Credit"
40 "1234","two","three","four"
41 "1235","two","three","four"
42 "1236","two","three","four"