]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/table.t
tag properly
[git.ikiwiki.info.git] / t / table.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Cwd qw(getcwd);
5 use Test::More;
6 use IkiWiki;
8 my $installed = $ENV{INSTALLED_TESTS};
10 my @command;
11 if ($installed) {
12         @command = qw(ikiwiki);
13 }
14 else {
15         ok(! system("make -s ikiwiki.out"));
16         @command = ("perl", "-I".getcwd, qw(./ikiwiki.out
17                 --underlaydir=underlays/basewiki
18                 --set underlaydirbase=underlays
19                 --templatedir=templates));
20 }
22 push @command, qw(--set usedirs=0 --plugin table
23         --url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi
24         t/tmp/in t/tmp/out --verbose);
26 my $blob;
28 ok(! system("rm -rf t/tmp"));
29 ok(! system("mkdir t/tmp"));
31 sub write_old_file {
32         my $name = shift;
33         my $content = shift;
35         writefile($name, "t/tmp/in", $content);
36         ok(utime(333333333, 333333333, "t/tmp/in/$name"));
37 }
39 write_old_file("csv.mdwn",
40 '[[!table format="csv" data="""
41 Key,Value
42 "ASCII","hello"
43 "Not ASCII","¬"
44 """]]');
45 write_old_file("dsv.mdwn",
46 '[[!table format="dsv" data="""
47 Key       | Value
48 ASCII     | hello
49 Not ASCII | ¬
50 """]]');
51 write_old_file("jon.mdwn",
52 '(See doc/bugs/table_can_not_deal_with_Chinese.mdwn)
54 [[!table class=fullwidth_table delimiter="      " data="""
55 Number  Title   Own?    Read?
56 I (HB1), 70 (PB1), 5 (PB50)     Dune    O       ✓"""]]');
58 ok(! system(@command));
59 ok(! system(@command, "--refresh"));
61 $blob = readfile("t/tmp/out/dsv.html");
62 like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
63 like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
64 like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);
66 SKIP: {
67         skip "Text::CSV unavailable", 0 unless eval q{use Text::CSV; 1};
69         $blob = readfile("t/tmp/out/jon.html");
70         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);
71         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);
73         $blob = readfile("t/tmp/out/csv.html");
74         like($blob, qr{<th>\s*Key\s*</th>.*<th>\s*Value\s*</th>}s);
75         like($blob, qr{<td>\s*ASCII\s*</td>.*<td>\s*hello\s*</td>}s);
76         like($blob, qr{<td>\s*Not ASCII\s*</td>.*<td>\s*¬\s*</td>}s);
77 }
79 done_testing;