aboutsummaryrefslogtreecommitdiff
path: root/t/index.t
blob: 392a167e9747131dbcd065b022a725ebf35f16d2 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/perl
use warnings;
use strict;
use IkiWiki;

package IkiWiki; # use internal variables
use Test::More tests => 31;

$config{wikistatedir}="/tmp/ikiwiki-test.$$";
system "rm -rf $config{wikistatedir}";

ok(! loadindex(), "loading nonexistent index file");

# Load standard plugins.
ok(loadplugin("meta"), "meta plugin loaded");
ok(loadplugin("mdwn"), "mdwn plugin loaded");

# Set up a default state.
$pagesources{"Foo"}="Foo.mdwn";
$pagesources{"bar"}="bar.mdwn";
$pagesources{"bar.png"}="bar.png";
my $now=time();
$pagemtime{"Foo"}=$now;
$pagemtime{"bar"}=$now-1000;
$pagemtime{"bar.png"}=$now;
$pagectime{"Foo"}=$now;
$pagectime{"bar"}=$now-100000;
$pagectime{"bar.png"}=$now-100000;
$renderedfiles{"Foo"}=["Foo.html"];
$renderedfiles{"bar"}=["bar.html", "bar.rss", "sparkline-foo.gif"];
$renderedfiles{"bar.png"}=["bar.png"];
$links{"Foo"}=["bar.png"];
$links{"bar"}=["Foo", "new-page"];
$typedlinks{"bar"}={tag => {"Foo" => 1}};
$links{"bar.png"}=[];
$depends{"Foo"}={};
$depends{"bar"}={"foo*" => 1};
$depends{"bar.png"}={};
$pagestate{"bar"}{meta}{title}="a page about bar";
$pagestate{"bar"}{meta}{moo}="mooooo";
# only loaded plugins save state, so this should not be saved out
$pagestate{"bar"}{nosuchplugin}{moo}="mooooo";

ok(saveindex(), "save index");
ok(-s "$config{wikistatedir}/indexdb", "index file created");

# Clear state.
%oldrenderedfiles=%pagectime=();
%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
%destsources=%renderedfiles=%pagecase=%pagestate=();

ok(loadindex(), "load index");
is_deeply(\%pagesources, {
	Foo => "Foo.mdwn",
	bar => "bar.mdwn",
	"bar.png" => "bar.png",
}, "%pagesources loaded correctly");
is_deeply(\%pagemtime, {
	Foo => $now,
	bar => $now-1000,
	"bar.png" => $now,
}, "%pagemtime loaded correctly");
is_deeply(\%pagectime, {
	Foo => $now,
	bar => $now-100000,
	"bar.png" => $now-100000,
}, "%pagemtime loaded correctly");
is_deeply(\%renderedfiles, {
	Foo => ["Foo.html"],
	bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
	"bar.png" => ["bar.png"],
}, "%renderedfiles loaded correctly");
is_deeply(\%oldrenderedfiles, {
	Foo => ["Foo.html"],
	bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
	"bar.png" => ["bar.png"],
}, "%oldrenderedfiles loaded correctly");
is_deeply(\%links, {
	Foo => ["bar.png"],
	bar => ["Foo", "new-page"],
	"bar.png" => [],
}, "%links loaded correctly");
is_deeply(\%depends, {
	Foo => {},
	bar => {"foo*" => 1},
	"bar.png" => {},
}, "%depends loaded correctly");
is_deeply(\%pagestate, {
	bar => {
		meta => {
			title => "a page about bar",
			moo => "mooooo",
		},
	},
}, "%pagestate loaded correctly");
is_deeply(\%pagecase, {
	foo => "Foo",
	bar => "bar",
	"bar.png" => "bar.png"
}, "%pagecase generated correctly");
is_deeply(\%destsources, {
	"Foo.html" => "Foo",
	"bar.html" => "bar",
	"bar.rss" => "bar",
	"sparkline-foo.gif" => "bar",
	"bar.png" => "bar.png",
}, "%destsources generated correctly");
is_deeply(\%typedlinks, {
	bar => {tag => {"Foo" => 1}},
}, "%typedlinks loaded correctly");
is_deeply(\%oldtypedlinks, {
	bar => {tag => {"Foo" => 1}},
}, "%oldtypedlinks loaded correctly");

# Clear state.
%oldrenderedfiles=%pagectime=();
%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
%destsources=%renderedfiles=%pagecase=%pagestate=();

# When state is loaded for a wiki rebuild, only ctime, oldrenderedfiles,
# and pagesources are retained.
$config{rebuild}=1;
ok(loadindex(), "load index");
is_deeply(\%pagesources, {
	Foo => "Foo.mdwn",
	bar => "bar.mdwn",
	"bar.png" => "bar.png",
}, "%pagesources loaded correctly");
is_deeply(\%pagemtime, {
}, "%pagemtime loaded correctly");
is_deeply(\%pagectime, {
	Foo => $now,
	bar => $now-100000,
	"bar.png" => $now-100000,
}, "%pagemtime loaded correctly");
is_deeply(\%renderedfiles, {
}, "%renderedfiles loaded correctly");
is_deeply(\%oldrenderedfiles, {
	Foo => ["Foo.html"],
	bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
	"bar.png" => ["bar.png"],
}, "%oldrenderedfiles loaded correctly");
is_deeply(\%links, {
}, "%links loaded correctly");
is_deeply(\%depends, {
}, "%depends loaded correctly");
is_deeply(\%pagestate, {
}, "%pagestate loaded correctly");
is_deeply(\%pagecase, { # generated implicitly since pagesources is loaded
	foo => "Foo",
	bar => "bar",
	"bar.png" => "bar.png"
}, "%pagecase generated correctly");
is_deeply(\%destsources, {
}, "%destsources generated correctly");
is_deeply(\%typedlinks, {
}, "%typedlinks cleared correctly");
is_deeply(\%oldtypedlinks, {
}, "%oldtypedlinks cleared correctly");

system "rm -rf $config{wikistatedir}";