File: 03csv02.t

package info (click to toggle)
libdata-report-perl 1.001-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 1,972; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! perl

################################################################
####                                                        ####
####        BIG FAT WARNING         BIG FAT WARNING         ####
####                                                        ####
################################################################
####
#### This test is for the Data::Report internals only. It contains
#### trickery that is not suitable for end users. Please do not attempt
#### to borrow any of these tricks.
####
#### In particular, the method _set_csv_method exists only for this
#### test and should never be used for other purposes. You have been
#### warned.


use strict;
use warnings;
use Test::More qw(no_plan);

use Data::Report;

my $rep = Data::Report::->create
  (type => "csv",
   layout => [ { name => "acct", title => "Acct",   width => 6  },
	       { name => "desc", title => "Report", width => 40, align => "|" },
	       { name => "deb",  title => "Debet",  width => 10, align => "<" },
	       { name => "crd",  title => "Credit", width => 10, align => ">" },
	     ],
  );

my $ref; { undef $/; $ref = <DATA> }
$ref =~ s/[\r\n]/\n/g;

my $out;

SKIP: {
    skip "Text::CSV_XS not found", 1
      unless eval { require Text::CSV_XS };
    dotest(Text::CSV_XS::);
}

SKIP: {
    skip "Text::CSV not found", 1
      unless eval { require Text::CSV };
    dotest(Text::CSV::);
}

dotest();

sub dotest {
    my ($cls) = shift;
    $out = "";
    $rep->set_output(\$out);
    $rep->start;
    $rep->_set_csv_method($cls);
    $rep->add({ acct => 1234, desc => "two two", deb => "th,ree", crd => '"four"' });
    $rep->finish;
    $out =~ s/[\r\n]/\n/g;
    is($out, $ref);
}

__DATA__
"Acct","Report","Debet","Credit"
"1234","two two","th,ree","""four"""