forked from treyharris/Text-FormatTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
74 lines (66 loc) · 1.79 KB
/
test.pl
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
use Test;
BEGIN { plan tests => 5 };
use Text::FormatTable;
ok(1); # If we made it this far, we're ok.
use strict;
use warnings;
{
my $table = Text::FormatTable->new('r| l l');
$table->head('a', 'b', 'c');
$table->rule('=');
$table->row('this a test, a nice test', 'oh, cool, a test!', 'yep');
$table->rule;
$table->row('you mean it\'s really a test?', 'yes, it is.', 'z');
$table->rule('=');
my $is = $table->render(15);
my $shouldbe = <<'END';
a| b c
=================
this a| oh, yep
test,| cool,
a nice| a
test| test!
------+----------
you| yes, z
mean| it
it's| is.
really|
a|
test?|
=================
END
ok($is, $shouldbe);
}
# Test behavior with ANSI-colored header
{
my $colortable = Text::FormatTable->new('l l l');
my $RED = "\e[31m";
my $RESET = "\e[0m";
$colortable->head('foo', $RED . 'bar' . $RESET, 'bat');
$colortable->rule('=');
$colortable->row(qw(a b c));
my $output = $colortable->render();
my ($rule) = ($output =~ /(=+)/);
ok(length($rule), length("foo bar bat"));
}
# Test behavior with ANSI-colored row data
{
my $colortable = Text::FormatTable->new('l l l');
my $RED = "\e[31m";
my $RESET = "\e[0m";
$colortable->head('foo', 'bar', 'bat');
$colortable->rule('=');
$colortable->row('a', $RED . 'b' . $RESET, 'c');
my $output = $colortable->render();
my ($rule) = ($output =~ /(=+)/);
ok(length($rule), length("foo bar bat"));
}
# rt34546, warnings when column has zero length
{
my $warning;
local $SIG{__WARN__} = sub { $warning = $_[0] };
my $table = Text::FormatTable->new('l l');
$table->head('foo', q{});
my $output = $table->render();
ok(not defined $warning);
}