column name fix for remote column
[scpubgit/System-Introspector-Report.git] / t / publish_mediawiki_parser.t
CommitLineData
499ebcdd 1use strictures 1;
2use Test::More;
3
4use aliased 'System::Introspector::Report::Publish::MediaWiki::Parser';
5
6my $parser = Parser->new;
7my $stream = $parser->parse(<<'EOR');
8
9= Heading =
10
11<!-- SI:TITLE begin foo -->
12== Foo ==
13<!-- SI:TITLE end foo -->
14
15User description
16
17<!-- SI:TABLE begin foo -->
18<table class="si-report">
19 <tr>
20 <th class="si-colhead-bar">Bar</th>
21 <th class="si-colhead-baz">Baz</th>
22 <th>
23 Qux
24 </th>
25 </tr>
26 <tr>
27 <td class="si-column-bar">231</td>
28 <td class="si-column-baz">421</td>
29 <td>171</td>
30 </tr>
31 <tr>
32 <td class="si-column-bar">232</td>
33 <td class="si-column-baz">422</td>
34 <td>172</td>
35 <td>173</td>
36 </tr>
37</table>
38<!-- SI:TABLE end foo -->
39
40End Text
41
42EOR
43
44is shift(@$stream), '', 'empty line';
45is shift(@$stream), '= Heading =', 'heading';
46is shift(@$stream), '', 'empty line';
47
48do {
49 my $report = shift @$stream;
50 is ref($report), 'HASH', 'report structure';
51
52 is_deeply $report->{id}, ['foo'], 'report id';
53 is $report->{title}, 'Foo', 'report title';
54
55 is $report->{columns}[0]{key}, 'bar', 'first column key';
56 is $report->{columns}[0]{label}, 'Bar', 'first column label';
57 ok not($report->{columns}[0]{user}), 'first column not user supplied';
58
59 is $report->{columns}[1]{key}, 'baz', 'second column key';
60 is $report->{columns}[1]{label}, 'Baz', 'second column label';
61 ok not($report->{columns}[1]{user}), 'second column not user supplied';
62
63 is $report->{columns}[2]{key}, '__usercol_0', 'first user supplied column key';
64 like $report->{columns}[2]{label}, qr{^\s+Qux\s+$}, 'first user supplied column label';
65 ok $report->{columns}[2]{user}, 'third column is user supplied';
66
67 is $report->{columns}[3]{key}, '__usercol_orph_0', 'second user supplied column key';
68 is $report->{columns}[3]{label}, undef, 'second user supplied column label is empty';
69 ok $report->{columns}[3]{user}, 'fourth column is user supplied';
70
71 is_deeply $report->{rows}[0], {
72 bar => 231, baz => 421, __usercol_0 => 171,
73 }, 'first row';
74 is_deeply $report->{rows}[1], {
75 bar => 232, baz => 422, __usercol_0 => 172, __usercol_orph_0 => 173,
76 }, 'second row';
77};
78
79is shift(@$stream), '', 'empty line';
80is shift(@$stream), 'End Text', 'end text';
81is shift(@$stream), '', 'empty line'
82 while @$stream;
83
84done_testing;