| 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | # t/strip_verbatim_indent.t.t - check verbatim indent stripping feature |
| 4 | |
| 5 | BEGIN { |
| 6 | chdir 't' if -d 't'; |
| 7 | } |
| 8 | |
| 9 | use strict; |
| 10 | use lib '../lib'; |
| 11 | use Test::More tests => 79; |
| 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' |
| 87 | ], |
| 88 | ) { |
| 89 | my ($pod, $indent, $xml, $xhtml, $desc) = @$spec; |
| 90 | # Test XML output. |
| 91 | ok my $p = Pod::Simple::XMLOutStream->new, "Construct XML parser to test $desc"; |
| 92 | $p->hide_line_numbers(1); |
| 93 | my $output = ''; |
| 94 | $p->output_string( \$output ); |
| 95 | is $indent, $p->strip_verbatim_indent($indent), |
| 96 | 'Set stripper for XML to ' . (defined $indent ? qq{"$indent"} : 'undef'); |
| 97 | ok $p->parse_string_document( $pod ), "Parse POD to XML for $desc"; |
| 98 | is $output, $xml, "Should have expected XML output for $desc"; |
| 99 | |
| 100 | |
| 101 | # Test XHTML output. |
| 102 | ok $p = Pod::Simple::XHTML->new, "Construct XHMTL parser to test $desc"; |
| 103 | $p->html_header(''); |
| 104 | $p->html_footer(''); |
| 105 | $output = ''; |
| 106 | $p->output_string( \$output ); |
| 107 | is $indent, $p->strip_verbatim_indent($indent), |
| 108 | 'Set stripper for XHTML to ' . (defined $indent ? qq{"$indent"} : 'undef'); |
| 109 | ok $p->parse_string_document( $pod ), "Parse POD to XHTML for $desc"; |
| 110 | is $output, $xhtml, "Should have expected XHTML output for $desc"; |
| 111 | } |