3 # t/strip_verbatim_indent.t.t - check verbatim indent stripping feature
11 use Test::More tests => 103;
12 #use Test::More 'no_plan';
14 use_ok('Pod::Simple::XHTML') or exit;
15 use_ok('Pod::Simple::XMLOutStream') or exit;
17 isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML';
19 ok $parser->strip_verbatim_indent(' '), 'Should be able to set striper to " "';
20 ok $parser->strip_verbatim_indent(' '), 'Should be able to set striper to " "';
21 ok $parser->strip_verbatim_indent("t"), 'Should be able to set striper to "\\t"';
22 ok $parser->strip_verbatim_indent(sub { ' ' }), 'Should be able to set striper to coderef';
26 "\n=pod\n\n foo bar baz\n",
28 qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>},
29 "<pre><code> foo bar baz</code></pre>\n\n",
33 "\n=pod\n\n foo bar baz\n",
35 qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
36 "<pre><code>foo bar baz</code></pre>\n\n",
40 "\n=pod\n\n foo bar baz\n",
42 qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>},
43 "<pre><code> foo bar baz</code></pre>\n\n",
47 "\n=pod\n\n foo bar baz\n",
49 qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
50 "<pre><code>foo bar baz</code></pre>\n\n",
54 "\n=pod\n\n foo bar baz\n",
56 qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>},
57 "<pre><code>foo bar baz</code></pre>\n\n",
61 "\n=pod\n\n foo bar\n\n baz blez\n",
63 qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
64 "<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
65 'single space indent and empty line'
68 "\n=pod\n\n foo bar\n\n baz blez\n",
70 qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
71 "<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
72 'code ref indent and empty line'
75 "\n=pod\n\n foo bar\n\n baz blez\n",
76 sub { (my $s = shift->[0]) =~ s/\S.*//; $s },
77 qq{<Document><Verbatim\nxml:space="preserve">foo bar\n\nbaz blez</Verbatim></Document>},
78 "<pre><code>foo bar\n\nbaz blez</code></pre>\n\n",
79 'heuristic code ref indent'
82 "\n=pod\n\n foo bar\n baz blez\n",
83 sub { s/^\s+// for @{ $_[0] } },
84 qq{<Document><Verbatim\nxml:space="preserve">foo bar\nbaz blez</Verbatim></Document>},
85 "<pre><code>foo bar\nbaz blez</code></pre>\n\n",
89 "\n=pod\n\n foo (bar\n baz blez\n",
90 sub { (my $i = $_[0]->[0]) =~ s/S.*//; $i },
91 qq{<Document><Verbatim\nxml:space="preserve">\n baz blez</Verbatim></Document>},
92 "<pre><code>\n baz blez</code></pre>\n\n",
96 my ($pod, $indent, $xml, $xhtml, $desc) = @$spec;
98 ok my $p = Pod::Simple::XMLOutStream->new, "Construct XML parser to test $desc";
99 $p->hide_line_numbers(1);
101 $p->output_string( \$output );
102 is $indent, $p->strip_verbatim_indent($indent),
103 'Set stripper for XML to ' . (defined $indent ? qq{"$indent"} : 'undef');
104 ok $p->parse_string_document( $pod ), "Parse POD to XML for $desc";
105 is $output, $xml, "Should have expected XML output for $desc";
109 ok $p = Pod::Simple::XHTML->new, "Construct XHMTL parser to test $desc";
113 $p->output_string( \$output );
114 is $indent, $p->strip_verbatim_indent($indent),
115 'Set stripper for XHTML to ' . (defined $indent ? qq{"$indent"} : 'undef');
116 ok $p->parse_string_document( $pod ), "Parse POD to XHTML for $desc";
117 is $output, $xhtml, "Should have expected XHTML output for $desc";
122 "\n=pod\n\n\t\tfoo bar baz\n",
124 "<pre><code>\t\tfoo bar baz</code></pre>\n\n",
128 "\n=pod\n\n\t\tfoo bar baz\n",
130 "<pre><code> foo bar baz</code></pre>\n\n",
134 "\n=pod\n\n\t\tfoo bar baz\n",
136 "<pre><code> foo bar baz</code></pre>\n\n",
140 "\n=pod\n\n\t\tfoo bar baz\n",
142 "<pre><code> foo bar baz</code></pre>\n\n",
143 'tabs are xlate to one space each'
146 my ($pod, $tabs, $xhtml, $desc) = @$spec;
148 ok my $p = Pod::Simple::XHTML->new, "Construct XHMTL parser to test $desc";
152 $p->output_string( \$output );
153 is $tabs, $p->expand_verbatim_tabs($tabs),
154 'Set tab for XHTML to ' . (defined $tabs ? qq{"$tabs"} : 'undef');
155 ok $p->parse_string_document( $pod ), "Parse POD to XHTML for $desc";
156 is $output, $xhtml, "Should have expected XHTML output for $desc";