summaryrefslogtreecommitdiff
path: root/cpan/Pod-Simple/t/strpvbtm.t
diff options
context:
space:
mode:
authorDavid E. Wheeler <david@kineticode.com>2009-10-27 12:09:33 -0700
committerRafael Garcia-Suarez <rgs@consttype.org>2009-10-28 11:28:38 +0100
commit9d65762f3680caf03a8526c0d9868a9b366f7818 (patch)
treed4ce818f6918699f4e934ce2bea1f558519a9d5c /cpan/Pod-Simple/t/strpvbtm.t
parent28c5b5bcd7f52e6b2219508a1066cd0ccc8dd19a (diff)
downloadperl-9d65762f3680caf03a8526c0d9868a9b366f7818.tar.gz
Bring Pod::Simple up to 3.09 as on CPAN.
Diffstat (limited to 'cpan/Pod-Simple/t/strpvbtm.t')
-rw-r--r--cpan/Pod-Simple/t/strpvbtm.t111
1 files changed, 111 insertions, 0 deletions
diff --git a/cpan/Pod-Simple/t/strpvbtm.t b/cpan/Pod-Simple/t/strpvbtm.t
new file mode 100644
index 0000000000..9cb83f3559
--- /dev/null
+++ b/cpan/Pod-Simple/t/strpvbtm.t
@@ -0,0 +1,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";
+}