Commit | Line | Data |
---|---|---|
9d65762f DW |
1 | #!/usr/bin/perl -w |
2 | ||
c9989a74 | 3 | # t/strip_verbatim_indent.t.t - check verbatim indent stripping feature |
9d65762f DW |
4 | |
5 | BEGIN { | |
6 | chdir 't' if -d 't'; | |
7 | } | |
8 | ||
9 | use strict; | |
10 | use lib '../lib'; | |
5aeca1f7 | 11 | use Test::More tests => 87; |
9d65762f DW |
12 | #use Test::More 'no_plan'; |
13 | ||
14 | use_ok('Pod::Simple::XHTML') or exit; | |
15 | use_ok('Pod::Simple::XMLOutStream') or exit; | |
16 | ||
17 | isa_ok my $parser = Pod::Simple::XHTML->new, 'Pod::Simple::XHTML'; | |
18 | ||
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'; | |
23 | ||
24 | for my $spec ( | |
25 | [ | |
26 | "\n=pod\n\n foo bar baz\n", | |
27 | undef, | |
28 | qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>}, | |
29 | "<pre><code> foo bar baz</code></pre>\n\n", | |
30 | 'undefined indent' | |
31 | ], | |
32 | [ | |
33 | "\n=pod\n\n foo bar baz\n", | |
34 | ' ', | |
35 | qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>}, | |
36 | "<pre><code>foo bar baz</code></pre>\n\n", | |
37 | 'single space indent' | |
38 | ], | |
39 | [ | |
40 | "\n=pod\n\n foo bar baz\n", | |
41 | ' ', | |
42 | qq{<Document><Verbatim\nxml:space="preserve"> foo bar baz</Verbatim></Document>}, | |
43 | "<pre><code> foo bar baz</code></pre>\n\n", | |
44 | 'too large indent' | |
45 | ], | |
46 | [ | |
47 | "\n=pod\n\n foo bar baz\n", | |
48 | ' ', | |
49 | qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>}, | |
50 | "<pre><code>foo bar baz</code></pre>\n\n", | |
51 | 'double space indent' | |
52 | ], | |
53 | [ | |
54 | "\n=pod\n\n foo bar baz\n", | |
55 | sub { ' ' }, | |
56 | qq{<Document><Verbatim\nxml:space="preserve">foo bar baz</Verbatim></Document>}, | |
57 | "<pre><code>foo bar baz</code></pre>\n\n", | |
58 | 'code ref stripper' | |
59 | ], | |
60 | [ | |
61 | "\n=pod\n\n foo bar\n\n baz blez\n", | |
62 | ' ', | |
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' | |
66 | ], | |
67 | [ | |
68 | "\n=pod\n\n foo bar\n\n baz blez\n", | |
69 | sub { ' ' }, | |
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' | |
73 | ], | |
74 | [ | |
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' | |
80 | ], | |
81 | [ | |
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", | |
86 | 'militant code ref' | |
5aeca1f7 CBW |
87 | ], |
88 | [ | |
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", | |
93 | 'code ref and paren' | |
9d65762f DW |
94 | ], |
95 | ) { | |
96 | my ($pod, $indent, $xml, $xhtml, $desc) = @$spec; | |
97 | # Test XML output. | |
98 | ok my $p = Pod::Simple::XMLOutStream->new, "Construct XML parser to test $desc"; | |
99 | $p->hide_line_numbers(1); | |
100 | my $output = ''; | |
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"; | |
106 | ||
107 | ||
108 | # Test XHTML output. | |
109 | ok $p = Pod::Simple::XHTML->new, "Construct XHMTL parser to test $desc"; | |
110 | $p->html_header(''); | |
111 | $p->html_footer(''); | |
112 | $output = ''; | |
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"; | |
118 | } |