Debian Codegraph @

t/03csv02.t

raw
1 #! perl
2
3 ################################################################
4 #### ####
5 #### BIG FAT WARNING BIG FAT WARNING ####
6 #### ####
7 ################################################################
8 ####
9 #### This test is for the Data::Report internals only. It contains
10 #### trickery that is not suitable for end users. Please do not attempt
11 #### to borrow any of these tricks.
12 ####
13 #### In particular, the method _set_csv_method exists only for this
14 #### test and should never be used for other purposes. You have been
15 #### warned.
16
17
18 use strict;
19 use warnings;
20 use Test::More qw(no_plan);
21
22 use Data::Report;
23
24 my $rep = Data::Report::->create
25 (type => "csv",
26 layout => [ { name => "acct", title => "Acct", width => 6 },
27 { name => "desc", title => "Report", width => 40, align => "|" },
28 { name => "deb", title => "Debet", width => 10, align => "<" },
29 { name => "crd", title => "Credit", width => 10, align => ">" },
30 ],
31 );
32
33 my $ref; { undef $/; $ref = <DATA> }
34 $ref =~ s/[\r\n]/\n/g;
35
36 my $out;
37
38 SKIP: {
39 skip "Text::CSV_XS not found", 1
40 unless eval { require Text::CSV_XS };
41 dotest(Text::CSV_XS::);
42 }
43
44 SKIP: {
45 skip "Text::CSV not found", 1
46 unless eval { require Text::CSV };
47 dotest(Text::CSV::);
48 }
49
50 dotest();
51
52 sub dotest {
53 my ($cls) = shift;
54 $out = "";
55 $rep->set_output(\$out);
56 $rep->start;
57 $rep->_set_csv_method($cls);
58 $rep->add({ acct => 1234, desc => "two two", deb => "th,ree", crd => '"four"' });
59 $rep->finish;
60 $out =~ s/[\r\n]/\n/g;
61 is($out, $ref);
62 }
63
64 __DATA__
65 "Acct","Report","Debet","Credit"
66 "1234","two two","th,ree","""four"""