aboutsummaryrefslogtreecommitdiff
path: root/t/table.t
blob: a7bbc06bf93bea35147f066e5235133698b00d0a (plain)
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
77
78
79
#!/usr/bin/perl
use warnings;
use strict;
use Cwd qw(getcwd);
use Test::More;
use IkiWiki;

my $installed = $ENV{INSTALLED_TESTS};

my @command;
if ($installed) {
	@command = qw(ikiwiki);
}
else {
	ok(! system("make -s ikiwiki.out"));
	@command = ("perl", "-I".getcwd, qw(./ikiwiki.out
		--underlaydir=underlays/basewiki
		--set underlaydirbase=underlays
		--templatedir=templates));
}

push @command, qw(--set usedirs=0 --plugin table
	--url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi
	t/tmp/in t/tmp/out --verbose);

my $blob;

ok(! system("rm -rf t/tmp"));
ok(! system("mkdir t/tmp"));

sub write_old_file {
	my $name = shift;
	my $content = shift;

	writefile($name, "t/tmp/in", $content);
	ok(utime(333333333, 333333333, "t/tmp/in/$name"));
}

write_old_file("csv.mdwn",
'[[!table format="csv" data="""
Key,Value
"ASCII","hello"
"Not ASCII","¬"
"""]]');
write_old_file("dsv.mdwn",
'[[!table format="dsv" data="""
Key       | Value
ASCII     | hello
Not ASCII | ¬
"""]]');
write_old_file("jon.mdwn",
'(See doc/bugs/table_can_not_deal_with_Chinese.mdwn)

[[!table class=fullwidth_table delimiter="	" data="""
Number	Title	Own?	Read?
I (HB1), 70 (PB1), 5 (PB50)	Dune	O	✓"""]]');

ok(! system(@command));
ok(! system(@command, "--refresh"));

$blob = readfile("t/tmp/out/dsv.html");
like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);

SKIP: {
	skip "Text::CSV unavailable", 0 unless eval q{use Text::CSV; 1};

	$blob = readfile("t/tmp/out/jon.html");
	like($blob, qr{<th>\s*Number\s*</th>\s*<th>\s*Title\s*</th>\s*<th>\s*Own\?\s*</th>\s*<th>\s*Read\?\s*</th>}s);
	like($blob, qr{<td>\s*I \(HB1\), 70 \(PB1\), 5 \(PB50\)\s*</td>\s*<td>\s*Dune\s*</td>\s*<td>\s*O\s*</td>\s*<td>\s*✓\s*</td>}s);

	$blob = readfile("t/tmp/out/csv.html");
	like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
	like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
	like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);
}

done_testing;