File: github_issue_79.t

package info (click to toggle)
perl 5.40.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 126,152 kB
  • sloc: ansic: 668,539; perl: 525,522; sh: 72,038; pascal: 6,925; xml: 2,428; yacc: 1,410; makefile: 1,191; cpp: 208; lisp: 1
file content (58 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
use warnings;

use Test::More;

{
package DumpAsXML::Enh;

use Pod::Simple::DumpAsXML ();
our @ISA = qw(Pod::Simple::DumpAsXML);

sub new {
    my ( $class ) = @_;
    my $self = $class->SUPER::new();
    $self->code_handler( sub { pop( @_ )->_handle_line( 'code', @_ ); } );
    $self->cut_handler( sub { pop( @_ )->_handle_line( 'cut', @_ ); } );
    $self->pod_handler( sub { pop( @_ )->_handle_line( 'pod', @_ ); } );
    $self->whiteline_handler( sub { pop( @_ )->_handle_line( 'white', @_ ); } );
    return $self;
};

sub _handle_line {
    my ( $self, $elem, $text, $line ) = @_;
    my $fh = $self->{ output_fh };
    print { $fh } '  ' x $self->{ indent }, "<$elem start_line=\"$line\"/>\n";
};

}

my $output = '';
my $parser = DumpAsXML::Enh->new();
$parser->output_string( \$output );

my $input = [
    '=head1 DESCRIPTION',
    '',
    '    Verbatim paragraph.',
    '',
    '=cut',
];
my $expected_output = join "\n",
    '<Document start_line="1">',
    '  <head1 start_line="1">',
    '    DESCRIPTION',
    '  </head1>',
    '  <VerbatimFormatted start_line="3" xml:space="preserve">',
    '        Verbatim paragraph.',
    '  </VerbatimFormatted>',
    '  <cut start_line="5"/>',
    '</Document>',
    '',
;

$parser->parse_lines( @$input, undef );

is($output, $expected_output);

done_testing;