File: 09poc01.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 (79 lines) | stat: -rw-r--r-- 2,326 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
67
68
69
70
71
72
73
74
75
76
77
78
79
#! perl

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

package POC::Report;

use base qw(Data::Report);

package POC::Report::Text;

use base qw(Data::Report::Plugin::Text);

sub _top_heading {
    my $self = shift;
    $self->_print("Title line 1\n");
    $self->_print("Title line 2\n");
    $self->_print("\n");
}

sub _std_stylist {
    my ($rep, $row, $col) = @_;

    if ( $col ) {
	return { line_after => "=" }
	  if $row eq "special" && $col =~ /^(deb|crd)$/;
    }
    else {
	return { line_after => 1 } if $row eq "total";
    }
    return;
}

package main;

my $rep = POC::Report::->create(type => "text");
isa_ok($rep, 'POC::Report::Text');

$rep->set_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 $out = "";
$rep->set_output(\$out);
$rep->start;

is($rep->get_stylist, \&POC::Report::Text::_std_stylist, "CB: stylist");
is($rep->get_topheading, \&POC::Report::Text::_top_heading, "CB: heading");

$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "special"});
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total"  });
$rep->finish;
$rep->close;

is($rep->{lines}, $= - 11, "linecount");

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

is($out, $ref, "contents");

__DATA__
Title line 1
Title line 2

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