File: 10.table-custom.t

package info (click to toggle)
liblatex-table-perl 1.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 784 kB
  • sloc: perl: 2,421; makefile: 2
file content (66 lines) | stat: -r--r--r-- 1,452 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
use Test::More tests => 3;
use Test::NoWarnings;

use strict;
use warnings;

use LaTeX::Table;


my $header = [
    [ 'Item:2c', '' ],
    ['\cmidrule(r){1-2}'],
    [ 'Animal', 'Description', 'Price' ]
];

my $data = [
    [ 'Gnat',      'per gram', '13.65' ],
    [ '',          'each',      '0.01' ],
    [ 'Gnu',       'stuffed',  '92.59' ],
    [ 'Emu',       'stuffed',  '33.33' ],
    [ 'Armadillo', 'frozen',    '8.99' ],
];


my $table = LaTeX::Table->new(
{   
    filename    => 'prices.tex',
    maincaption => 'Price List',
    caption     => 'Try our special offer today!',
    label       => 'table:prices',
    position    => 'htb',
    header      => $header,
    data        => $data,
    theme       => 'Meyrin',
    custom_template => '[% DATA_CODE %]',
}
);

my $expected_output =<<'EOT'
Gnat      & per gram & 13.65 \\
          & each     & 0.01  \\
Gnu       & stuffed  & 92.59 \\
Emu       & stuffed  & 33.33 \\
Armadillo & frozen   & 8.99  \\
\bottomrule
EOT
;

my $output = $table->generate_string();
is_deeply([ split("\n",$output) ], [split("\n",$expected_output)], 
    'BODY_CODE');

$table->set_custom_template('[% HEADER_CODE %]');

$expected_output =<<'EOT'
\toprule
\multicolumn{2}{c}{Item} &             \\
\cmidrule(r){1-2}
Animal                   & Description & Price \\
\midrule
EOT
;

$output = $table->generate_string();
is_deeply([ split("\n",$output) ], [split("\n",$expected_output)], 
    'HEADER_CODE');