File: simple.t

package info (click to toggle)
libcatmandu-exporter-table-perl 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 71; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;

BEGIN { use_ok 'Catmandu::Exporter::Table'; }
require_ok 'Catmandu::Exporter::Table';

my ($got, $expect);

sub export_table(@) {
    my ($data, %config) = @_;
    $got = "";
    my $exporter = Catmandu::Exporter::Table->new(%config, file => \$got);
    isa_ok $exporter, 'Catmandu::Exporter::Table';
    $exporter->add($_) for @$data;
    $exporter->commit;
    is($exporter->count, scalar @$data, "Count ok");
}

export_table [{'a' => 'moose', b => '1'}, 
              {'a' => "p\nony", b => '2'}, 
              {'a' => 'shr|mp', b => '3'}];

$expect = <<TABLE;
| a      | b |
|--------|---|
| moose  | 1 |
| p ony  | 2 |
| shr mp | 3 |
TABLE

is($got, $expect, "MultiMarkdown format ok");
 

export_table [ { a => 'Hello', b => 'World' } ],
             fields => { a => 'Longname', x => 'X' };
$expect = <<TABLE;
| Longname | X |
|----------|---|
| Hello    |   |
TABLE
is $got, $expect, 'custom column names as HASH';


export_table [ { a => 'Hi', b => 'World', c => 'long value' } ],
             widths => '5,3,6';
$expect = <<TABLE;
| a     | b   | c      |
|-------|-----|--------|
| Hi    | Wor | lon... |
TABLE

is $got, $expect, 'custom column width / truncation';

done_testing;