xref: /openbsd-src/gnu/usr.bin/perl/cpan/Pod-Simple/t/html01.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1# Testing HTML paragraphs
2use strict;
3use warnings;
4use Test::More tests => 15;
5
6#use Pod::Simple::Debug (10);
7
8use Pod::Simple::HTML;
9
10sub x {
11  my $code = $_[1];
12  Pod::Simple::HTML->_out(
13  sub{  $_[0]->bare_output(1); $code->($_[0]) if $code  },
14  "=pod\n\n$_[0]",
15) }
16
17is( x(
18q{
19=pod
20
21This is a paragraph
22
23=cut
24}),
25  qq{\n<p>This is a paragraph</p>\n},
26  "paragraph building"
27);
28
29
30is( x(qq{=pod\n\nThis is a paragraph}),
31 qq{\n<p>This is a paragraph</p>\n},
32 "paragraph building"
33);
34
35
36is( x(qq{This is a paragraph}),
37 qq{\n<p>This is a paragraph</p>\n},
38 "paragraph building"
39);
40
41
42
43like(x(
44'=head1 This is a heading')
45 => qr{\s*<h1><a[^<>]+>This\s+is\s+a\s+heading</a></h1>\s*$},
46  "heading building"
47);
48
49like(x('=head1 This is a heading', sub { $_[0]->html_h_level(2) })
50 => qr{\s*<h2><a[^<>]+>This\s+is\s+a\s+heading</a></h2>\s*$},
51  "heading building"
52);
53
54like(x(
55'=head2 This is a heading too')
56 => qr{\s*<h2><a[^<>]+>This\s+is\s+a\s+heading\s+too</a></h2>\s*$},
57  "heading building"
58);
59
60like(x(
61'=head3 Also, this is a heading')
62 => qr{\s*<h3><a[^<>]+>Also,\s+this\s+is\s+a\s+heading</a></h3>\s*$},
63  "heading building"
64);
65
66
67like(x(
68'=head4 This, too, is a heading')
69 => qr{\s*<h4><a[^<>]+>This,\s+too,\s+is\s+a\s+heading</a></h4>\s*$},
70  "heading building"
71);
72
73like(x(
74'=head5 The number of the heading shall be five')
75 => qr{\s*<h5><a[^<>]+>The\s+number\s+of\s+the\s+heading\s+shall\s+be\s+five</a></h5>\s*$},
76  "heading building"
77);
78
79like(x(
80'=head6 The sixth a heading is the perfect heading')
81 => qr{\s*<h6><a[^<>]+>The\s+sixth\s+a\s+heading\s+is\s+the\s+perfect\s+heading</a></h6>\s*$},
82  "heading building"
83);
84
85like(x(
86'=head2 Yada Yada Operator
87X<...> X<... operator> X<yada yada operator>')
88 => qr{name="Yada_Yada_Operator"},
89  "heading anchor name"
90);
91
92is(
93    x("=over 4\n\n=item one\n\n=item two\n\nHello\n\n=back\n"),
94    q{
95<dl>
96<dt><a name="one"
97>one</a></dt>
98
99<dd>
100<dt><a name="two"
101>two</a></dt>
102
103<dd>
104<p>Hello</p>
105</dd>
106</dl>
107}
108);
109
110my $html = q{<tt>
111<pre>
112#include &lt;stdio.h&gt;
113
114int main(int argc,char *argv[]) {
115
116        printf("Hellow World\n");
117        return 0;
118
119}
120</pre>
121</tt>};
122is(
123    x("=begin html\n\n$html\n\n=end html\n"),
124    "$html\n\n"
125);
126
127# Check subclass.
128SUBCLASS: {
129    package My::Pod::HTML;
130    use vars '@ISA', '$VERSION';
131    @ISA = ('Pod::Simple::HTML');
132    $VERSION = '0.01';
133    sub do_section { 'howdy' }
134}
135
136is(
137    My::Pod::HTML->_out(
138        sub{  $_[0]->bare_output(1)  },
139        "=pod\n\n=over\n\n=item Foo\n\n=back\n",
140    ),
141    "\n<dl>\n<dt><a name=\"howdy\"\n>Foo</a></dt>\n</dl>\n",
142);
143
144{   # Test that strip_verbatim_indent() works.  github issue #i5
145    my $output;
146
147    my $obj = Pod::Simple::HTML->new;
148    $obj->strip_verbatim_indent("  ");
149    $obj->output_string(\$output);
150    $obj->parse_string_document("=pod\n\n  First line\n  2nd line\n");
151    like($output, qr!<pre>First line\n2nd line</pre>!s);
152}
153