File: 01text02.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 (63 lines) | stat: -rw-r--r-- 1,524 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
#! perl

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

use Data::Report;

my $data = "01text.out";
$data = "t/$data" if -d "t";

my $rep = Data::Report::->create
  (type => "text",
   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 => ">" },
	     ],
  );

$rep->set_output($data);
$rep->start;
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
$rep->finish;
$rep->close;

undef $/;
my $ref = <DATA>;
open(my $fh, "<", $data);
my $out = <$fh>;
close($fh);
$ref =~ s/[\r\n]/\n/g;
$out =~ s/[\r\n]/\n/g;
is($out, $ref);
unlink($data) if $out eq $ref;

# Same, capturing output in a scalar.
$out = "";
$rep->set_output(\$out);
$rep->start;
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
$rep->finish;
$rep->close;

$out =~ s/[\r\n]/\n/g;
is($out, $ref);

# Same, capturing output in an array.
my @out;
$rep->set_output(\@out);
$rep->start;
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four" });
$rep->finish;
$rep->close;

$out = join("", @out);
$out =~ s/[\r\n]/\n/g;
is($out, $ref);

__DATA__
Acct                                      Report  Debet           Credit
------------------------------------------------------------------------
one                                          two  three             four