handle newline and html break conversions in mediawiki publishing
[scpubgit/System-Introspector-Report.git] / t / publish_mediawiki_parser.t
1 use strictures 1;
2 use Test::More;
3
4 use aliased 'System::Introspector::Report::Publish::MediaWiki::Parser';
5
6 my $parser = Parser->new;
7 my $stream = $parser->parse(<<'EOR');
8
9 = Heading =
10
11 <!-- SI:TITLE begin foo -->
12 == Foo ==
13 <!-- SI:TITLE end foo -->
14
15 User 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   <tr>
38     <td class="si-column-bar">foo<br/>bar</td>
39     <td class="si-column-baz">bar<br/>baz</td>
40     <td>199</td>
41   </tr>
42 </table>
43 <!-- SI:TABLE end foo -->
44
45 End Text
46
47 EOR
48
49 is shift(@$stream), '', 'empty line';
50 is shift(@$stream), '= Heading =', 'heading';
51 is shift(@$stream), '', 'empty line';
52
53 do {
54   my $report = shift @$stream;
55   is ref($report), 'HASH', 'report structure';
56
57   is_deeply $report->{id}, ['foo'], 'report id';
58   is $report->{title}, 'Foo', 'report title';
59
60   is $report->{columns}[0]{key}, 'bar', 'first column key';
61   is $report->{columns}[0]{label}, 'Bar', 'first column label';
62   ok not($report->{columns}[0]{user}), 'first column not user supplied';
63
64   is $report->{columns}[1]{key}, 'baz', 'second column key';
65   is $report->{columns}[1]{label}, 'Baz', 'second column label';
66   ok not($report->{columns}[1]{user}), 'second column not user supplied';
67
68   is $report->{columns}[2]{key}, '__usercol_0', 'first user supplied column key';
69   like $report->{columns}[2]{label}, qr{^\s+Qux\s+$}, 'first user supplied column label';
70   ok $report->{columns}[2]{user}, 'third column is user supplied';
71
72   is $report->{columns}[3]{key}, '__usercol_orph_0', 'second user supplied column key';
73   is $report->{columns}[3]{label}, undef, 'second user supplied column label is empty';
74   ok $report->{columns}[3]{user}, 'fourth column is user supplied';
75
76   is_deeply $report->{rows}[0], {
77     bar => 231, baz => 421, __usercol_0 => 171,
78   }, 'first row';
79   is_deeply $report->{rows}[1], {
80     bar => 232, baz => 422, __usercol_0 => 172, __usercol_orph_0 => 173,
81   }, 'second row';
82   is_deeply $report->{rows}[2], {
83     bar => "foo\nbar", baz => "bar\nbaz", __usercol_0 => 199,
84   }, 'third row';
85 };
86
87 is shift(@$stream), '', 'empty line';
88 is shift(@$stream), 'End Text', 'end text';
89 is shift(@$stream), '', 'empty line'
90   while @$stream;
91
92 done_testing;