1use Test;
2BEGIN { plan tests => 5 };
3use Text::FormatTable;
4ok(1); # If we made it this far, we're ok.
5
6use strict;
7use warnings;
8
9{
10    my $table = Text::FormatTable->new('r| l l');
11$table->head('a', 'b', 'c');
12    $table->rule('=');
13    $table->row('this a test, a nice test', 'oh, cool, a test!', 'yep');
14    $table->rule;
15    $table->row('you mean it\'s really a test?', 'yes, it is.', 'z');
16    $table->rule('=');
17    my $is = $table->render(15);
18
19    my $shouldbe = <<'END';
20     a| b     c
21=================
22this a| oh,   yep
23 test,| cool,
24a nice| a
25  test| test!
26------+----------
27   you| yes,  z
28  mean| it
29  it's| is.
30really|
31     a|
32 test?|
33=================
34END
35
36    ok($is, $shouldbe);
37}
38
39# Test behavior with ANSI-colored header
40{
41    my $colortable = Text::FormatTable->new('l l l');
42    my $RED = "\e[31m";
43    my $RESET = "\e[0m";
44    $colortable->head('foo', $RED . 'bar' . $RESET, 'bat');
45    $colortable->rule('=');
46    $colortable->row(qw(a b c));
47    my $output = $colortable->render();
48    my ($rule) = ($output =~ /(=+)/);
49    ok(length($rule), length("foo bar bat"));
50}
51
52# Test behavior with ANSI-colored row data
53{
54    my $colortable = Text::FormatTable->new('l l l');
55    my $RED = "\e[31m";
56    my $RESET = "\e[0m";
57    $colortable->head('foo', 'bar', 'bat');
58    $colortable->rule('=');
59    $colortable->row('a', $RED . 'b' . $RESET, 'c');
60    my $output = $colortable->render();
61    my ($rule) = ($output =~ /(=+)/);
62    ok(length($rule), length("foo bar bat"));
63}
64
65# rt34546, warnings when column has zero length
66{
67    my $warning;
68    local $SIG{__WARN__} = sub { $warning = $_[0] };
69
70    my $table = Text::FormatTable->new('l l');
71    $table->head('foo', q{});
72    my $output = $table->render();
73    ok(not defined $warning);
74}
75