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
|
#!/usr/bin/perl -w
# t/strip_verbatim_indent.t.t - check verabtim indent stripping feature
BEGIN {
chdir 't' if -d 't';
}
use strict;
use lib '../lib';
use Test::More tests => 79;
#use Test::More 'no_plan';
use_ok('Pod::Simple::XHTML') or exit;
use_ok('Pod::Simple::XMLOutStream') or exit;
isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
ok $parser->strip_verbatim_indent(' '), 'Should be able to set striper to " "';
ok $parser->strip_verbatim_indent(' '), 'Should be able to set striper to " "';
ok $parser->strip_verbatim_indent("t"), 'Should be able to set striper to "\\t"';
ok $parser->strip_verbatim_indent(sub { ' ' }), 'Should be able to set striper to coderef';
for my $spec (
[
"\n=pod\n\n foo bar baz\n",
undef,
qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>},
"<pre><code> foo bar baz</code></pre>\n\n",
'undefined indent'
],
[
"\n=pod\n\n foo bar baz\n",
' ',
qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
"<pre><code>foo bar baz</code></pre>\n\n",
'single space indent'
],
[
"\n=pod\n\n foo bar baz\n",
' ',
qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>},
"<pre><code> foo bar baz</code></pre>\n\n",
'too large indent'
],
[
"\n=pod\n\n foo bar baz\n",
' ',
qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
"<pre><code>foo bar baz</code></pre>\n\n",
'double space indent'
],
[
"\n=pod\n\n foo bar baz\n",
sub { ' ' },
qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
"<pre><code>foo bar baz</code></pre>\n\n",
'code ref stripper'
],
[
"\n=pod\n\n foo bar\n\n baz blez\n",
' ',
qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
"<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
'single space indent and empty line'
],
[
"\n=pod\n\n foo bar\n\n baz blez\n",
sub { ' ' },
qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
"<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
'code ref indent and empty line'
],
[
"\n=pod\n\n foo bar\n\n baz blez\n",
sub { (my $s = shift->[0]) =~ s/\S.*//; $s },
qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
"<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
'heuristic code ref indent'
],
[
"\n=pod\n\n foo bar\n baz blez\n",
sub { s/^\s+// for @{ $_[0] } },
qq{<Document><Verbatim\nxml:space="preserve">foo bar\nbaz blez</Verbatim></Document>},
"<pre><code>foo bar\nbaz blez</code></pre>\n\n",
'militant code ref'
],
) {
my ($pod, $indent, $xml, $xhtml, $desc) = @$spec;
# Test XML output.
ok my $p = Pod::Simple::XMLOutStream->new, "Construct XML parser to test $desc";
$p->hide_line_numbers(1);
my $output = '';
$p->output_string( \$output );
is $indent, $p->strip_verbatim_indent($indent),
'Set stripper for XML to ' . (defined $indent ? qq{"$indent"} : 'undef');
ok $p->parse_string_document( $pod ), "Parse POD to XML for $desc";
is $output, $xml, "Should have expected XML output for $desc";
# Test XHTML output.
ok $p = Pod::Simple::XHTML->new, "Construct XHMTL parser to test $desc";
$p->html_header('');
$p->html_footer('');
$output = '';
$p->output_string( \$output );
is $indent, $p->strip_verbatim_indent($indent),
'Set stripper for XHTML to ' . (defined $indent ? qq{"$indent"} : 'undef');
ok $p->parse_string_document( $pod ), "Parse POD to XHTML for $desc";
is $output, $xhtml, "Should have expected XHTML output for $desc";
}
|