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