xref: /openbsd-src/gnu/usr.bin/perl/cpan/podlators/t/man/heading.t (revision e068048151d29f2562a32185e21a8ba885482260)
1#!/usr/bin/perl
2#
3# Additional tests for Pod::Man heading generation.
4#
5# Copyright 2002, 2004, 2006, 2008-2009, 2012, 2015, 2018-2019, 2022
6#     Russ Allbery <rra@cpan.org>
7#
8# This program is free software; you may redistribute it and/or modify it
9# under the same terms as Perl itself.
10#
11# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
12
13use 5.008;
14use strict;
15use warnings;
16
17use lib 't/lib';
18
19use Test::More tests => 11;
20use Test::Podlators qw(read_test_data);
21
22BEGIN {
23    use_ok('Pod::Man');
24}
25
26# Loop through all the test data, generate output, and compare it to the
27# desired output data.
28my $testnum = 1;
29while (defined(my $data = read_test_data(\*DATA, { options => 1 }))) {
30    my $parser = Pod::Man->new(%{ $data->{options} });
31    isa_ok($parser, 'Pod::Man', 'Parser object');
32
33    # Run the parser, storing the output into a Perl variable.
34    my $got;
35    $parser->output_string(\$got);
36    $parser->parse_string_document($data->{input});
37
38    # Extract just the heading line.
39    my ($heading) = ($got =~ m{^ ([.]TH [^\n]+ \n)}xms);
40
41    # Compare the results.
42    is($heading, $data->{output}, "Test $testnum");
43    $testnum++;
44}
45
46# Below the marker are sets of options, the input data, and the corresponding
47# expected .TH line from the man page.  The options and output are separated
48# by lines containing only ###.
49
50__DATA__
51
52###
53date 2009-01-17
54release 1.0
55###
56=head1 NAME
57
58test - Test man page
59###
60.TH STDIN 1 2009-01-17 1.0 "User Contributed Perl Documentation"
61###
62
63###
64date 2009-01-17
65name TEST
66section 8
67release 2.0-beta
68###
69=head1 NAME
70
71test - Test man page
72###
73.TH TEST 8 2009-01-17 2.0-beta "User Contributed Perl Documentation"
74###
75
76###
77date 2009-01-17
78release 1.0
79center Testing Documentation
80###
81=head1 NAME
82
83test - Test man page
84###
85.TH STDIN 1 2009-01-17 1.0 "Testing Documentation"
86###
87
88###
89date
90release
91center
92###
93=head1 NAME
94
95test - Test man page
96###
97.TH STDIN 1 "" "" ""
98###
99
100###
101date foo ""bar""
102release "quoted"
103section 4"
104name "BAR
105center Something
106###
107=head1 NAME
108
109test - Test man page
110###
111.TH """BAR" "4""" "foo """"bar""""" """quoted""" Something
112###
113