1use strict;
2use warnings;
3use Test::More tests => 9;
4
5my $d;
6#use Pod::Simple::Debug (\$d, 0);
7
8use Pod::Simple::XMLOutStream;
9use Pod::Simple::DumpAsXML;
10
11
12$Pod::Simple::XMLOutStream::ATTR_PAD   = ' ';
13$Pod::Simple::XMLOutStream::SORT_ATTRS = 1; # for predictably testable output
14
15
16print "# A simple sanity test...\n";
17is( Pod::Simple::XMLOutStream->_out("=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
18 '<Document><Para><F><C>foo</C> <I>bar</I></F> <B>stuff <X>thing</X>baz</B></Para></Document>'
19);
20
21print "# With lots of nesting, and Z's...\n";
22is( Pod::Simple::XMLOutStream->_out("=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
23 '<Document><Para><F><C>foo</C> <I>bar</I></F> <B>stuff <X>thing</X>baz</B></Para></Document>'
24);
25
26#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
28sub mergy {$_[0]->merge_text(1)}
29sub nixy  {$_[0]->nix_X_codes(1)}
30sub nixy_mergy {$_[0]->merge_text(1); $_[0]->nix_X_codes(1);}
31
32#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
34print "# With no F/X\n";
35
36is( Pod::Simple::DumpAsXML->_out( "=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
37  join "\n",
38
39  '<Document>',
40  '  <Para>',
41  '    <F>',
42  '      <C>',
43  '        foo',
44  '      </C>',
45  '      ',
46  '      <I>',
47  '        bar',
48  '      </I>',
49  '    </F>',
50  '    ',
51  '    <B>',
52  '      stuff ',
53  '      <X>',
54  '        thing',
55  '      </X>',
56  '      baz',
57  '    </B>',
58  '  </Para>',
59  '</Document>',
60  '',
61);
62
63#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
65print "#  with just X-nixing...\n";
66
67is( Pod::Simple::DumpAsXML->_out( \&nixy, "=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
68  join "\n",
69
70  '<Document>',
71  '  <Para>',
72  '    <F>',
73  '      <C>',
74  '        foo',
75  '      </C>',
76  '      ',
77  '      <I>',
78  '        bar',
79  '      </I>',
80  '    </F>',
81  '    ',
82  '    <B>',
83  '      stuff baz',
84  '    </B>',
85  '  </Para>',
86  '</Document>',
87  '',
88);
89
90#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92print "# With merging...\n";
93
94is( Pod::Simple::DumpAsXML->_out( \&mergy, "=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
95  join "\n",
96
97  '<Document>',
98  '  <Para>',
99  '    <F>',
100  '      <C>',
101  '        foo',
102  '      </C>',
103  '      ',
104  '      <I>',
105  '        bar',
106  '      </I>',
107  '    </F>',
108  '    ',
109  '    <B>',
110  '      stuff ',
111  '      <X>',
112  '        thing',
113  '      </X>',
114  '      baz',
115  '    </B>',
116  '  </Para>',
117  '</Document>',
118  '',
119);
120
121#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122
123print "# With nixing and merging...\n";
124#$d = 10;
125is( Pod::Simple::DumpAsXML->_out( \&nixy_mergy, "=pod\n\nZ<>F<C<Z<>fE<111>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
126  join "\n",
127
128  '<Document>',
129  '  <Para>',
130  '    <F>',
131  '      <C>',
132  '        foo',
133  '      </C>',
134  '      ',
135  '      <I>',
136  '        bar',
137  '      </I>',
138  '    </F>',
139  '    ',
140  '    <B>',
141  '      stuff baz',
142  '    </B>',
143  '  </Para>',
144  '</Document>',
145  '',
146);
147
148#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150# Now the scary bits... with L's!
151print "# A wee L<...> sanity test...\n";
152is( Pod::Simple::XMLOutStream->_out(qq{=pod\n\nL<E<78>et::Ping/Ping-E<112>ong>\n}),
153 '<Document><Para><L content-implicit="yes" raw="E&#60;78&#62;et::Ping/Ping-E&#60;112&#62;ong" section="Ping-pong" to="Net::Ping" type="pod">&#34;Ping-pong&#34; in Net::Ping</L></Para></Document>'
154);
155print "# Now a wee L<...> with mergy...\n";
156
157$d = 10;
158
159is( Pod::Simple::DumpAsXML->_out(\&mergy, qq{=pod\n\nL<E<78>et::Ping/Ping-E<112>ong>\n}),
160 join "\n",
161
162 '<Document>',
163 '  <Para>',
164 '    <L content-implicit="yes" raw="E&#60;78&#62;et::Ping/Ping-E&#60;112&#62;ong" section="Ping-pong" to="Net::Ping" type="pod">',
165 '      &#34;Ping-pong&#34; in Net::Ping',
166 '    </L>',
167 '  </Para>',
168 '</Document>',
169 ''
170);
171
172
173print "# Now a complex tree with L's, with nixy+mergy...\n";
174
175is( Pod::Simple::DumpAsXML->_out( \&nixy_mergy, "=pod\n\nZ<>F<C<Z<>fE<111>L<E<78>et::Ping/Ping-E<112>ong>o> I<bar>> B<stuff X<thingZ<>>baz>\n"),
176  join "\n",
177
178  '<Document>',
179  '  <Para>',
180  '    <F>',
181  '      <C>',
182  '        fo',
183  '        <L content-implicit="yes" raw="E&#60;78&#62;et::Ping/Ping-E&#60;112&#62;ong" section="Ping-pong" to="Net::Ping" type="pod">',
184  '          &#34;Ping-pong&#34; in Net::Ping',
185  '        </L>',
186  '        o',
187  '      </C>',
188  '      ',
189  '      <I>',
190  '        bar',
191  '      </I>',
192  '    </F>',
193  '    ',
194  '    <B>',
195  '      stuff baz',
196  '    </B>',
197  '  </Para>',
198  '</Document>',
199  '',
200);
201