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
|
#!/usr/bin/perl
# vim: set ft=perl:
# $Id: 03.t,v 1.1.1.1 2005/10/04 16:39:58 dlc Exp $
# Yes, this is the same test file (almost) as 01.t, but
# this one tests resetting the object, and there needs to
# be an object with data in order to test resetting it.
use strict;
use Text::TabularDisplay;
use Test;
BEGIN {
plan tests => 6;
}
my @data = (
[ qw(id name phone) ],
[ 1, "Tom Jones", "(666) 555-1212" ],
[ 2, "Barnaby Jones", "(666) 555-1212" ],
[ 3, "Bridget Jones", "(666) 555-1212" ],
[ 4, "Quincy Jones", "(666) 555-1212" ],
);
my $t;
ok(1); # loaded...
$t = Text::TabularDisplay->new;
ok(2); # instantiated...
my @columns = @{ shift @data };
$t->columns(@columns);
ok(scalar @columns, scalar $t->columns); # columns gets/sets correctly
for (@data) {
$t->add(@$_);
}
# How's this for an ugly test?
ok($t->render,
"+----+---------------+----------------+
| id | name | phone |
+----+---------------+----------------+
| 1 | Tom Jones | (666) 555-1212 |
| 2 | Barnaby Jones | (666) 555-1212 |
| 3 | Bridget Jones | (666) 555-1212 |
| 4 | Quincy Jones | (666) 555-1212 |
+----+---------------+----------------+");
# Reset instance
$t->reset(@columns);
# Ensure that new columns resets instance
ok($t->render,
"+----+------+-------+
| id | name | phone |
+----+------+-------+
+----+------+-------+");
for (@data) {
$t->add(@$_);
}
# ...And repeat the ugly test, to ensure that a re-instanted
# object renders the same way.
ok($t->render,
"+----+---------------+----------------+
| id | name | phone |
+----+---------------+----------------+
| 1 | Tom Jones | (666) 555-1212 |
| 2 | Barnaby Jones | (666) 555-1212 |
| 3 | Bridget Jones | (666) 555-1212 |
| 4 | Quincy Jones | (666) 555-1212 |
+----+---------------+----------------+");
|