Debian Codegraph @

t/02html03.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 $out = "";
10
11 my $rep = Data::Report::->create
12 (type => "html",
13 layout => [ { name => "acct", title => "Acct", width => 6 },
14 { name => "desc", title => "Report", width => 40, align => "|" },
15 { name => "deb", title => "Debet", width => 10, align => "<" },
16 { name => "crd", title => "Credit", width => 10, align => ">" },
17 ],
18 );
19
20 $rep->set_stylist( sub {
21 my ($rep, $row, $col) = @_;
22 return unless $col;
23
24 return { class => "bar" }
25 if $row && $row eq "_head" && $col && $col eq "deb";
26 return { class => "foo" }
27 if $col eq "deb";
28 return;
29 } );
30
31 $rep->set_output(\$out);
32 $rep->start;
33 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
34 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "xyz" });
35 $rep->finish;
36 $rep->close;
37
38 my $ref; { undef $/; $ref = <DATA> }
39 $ref =~ s/[\r\n]/\n/g;
40 $out =~ s/[\r\n]/\n/g;
41
42 is($out, $ref);
43
44 __DATA__
45 <table class="main">
46 <tr class="head">
47 <th align="left" class="h_acct">Acct</th>
48 <th align="center" class="h_desc">Report</th>
49 <th align="left" class="bar">Debet</th>
50 <th align="right" class="h_crd">Credit</th>
51 </tr>
52 <tr>
53 <td align="left" class="c_acct">one</td>
54 <td align="center" class="c_desc">two</td>
55 <td align="left" class="foo">three</td>
56 <td align="right" class="c_crd">four</td>
57 </tr>
58 <tr class="r_xyz">
59 <td align="left" class="c_acct">one</td>
60 <td align="center" class="c_desc">two</td>
61 <td align="left" class="foo">three</td>
62 <td align="right" class="c_crd">four</td>
63 </tr>
64 </table>