Debian Codegraph @

t/01text02.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 $data = "01text.out";
10 $data = "t/$data" if -d "t";
11
12 my $rep = Data::Report::->create
13 (type => "text",
14 layout => [ { name => "acct", title => "Acct", width => 6 },
15 { name => "desc", title => "Report", width => 40, align => "|" },
16 { name => "deb", title => "Debet", width => 10, align => "<" },
17 { name => "crd", title => "Credit", width => 10, align => ">" },
18 ],
19 );
20
21 $rep->set_output($data);
22 $rep->start;
23 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
24 $rep->finish;
25 $rep->close;
26
27 undef $/;
28 my $ref = <DATA>;
29 open(my $fh, "<", $data);
30 my $out = <$fh>;
31 close($fh);
32 $ref =~ s/[\r\n]/\n/g;
33 $out =~ s/[\r\n]/\n/g;
34 is($out, $ref);
35 unlink($data) if $out eq $ref;
36
37 # Same, capturing output in a scalar.
38 $out = "";
39 $rep->set_output(\$out);
40 $rep->start;
41 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
42 $rep->finish;
43 $rep->close;
44
45 $out =~ s/[\r\n]/\n/g;
46 is($out, $ref);
47
48 # Same, capturing output in an array.
49 my @out;
50 $rep->set_output(\@out);
51 $rep->start;
52 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
53 $rep->finish;
54 $rep->close;
55
56 $out = join("", @out);
57 $out =~ s/[\r\n]/\n/g;
58 is($out, $ref);
59
60 __DATA__
61 Acct Report Debet Credit
62 ------------------------------------------------------------------------
63 one two three four