Skip to content

Commit 962c807

Browse files
erichermanbook
andcommitted
initial round of tests for Porting/merge-deltas.pl
Co-authored-by: Philippe Bruhat (BooK) <[email protected]>
1 parent 985bd06 commit 962c807

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

t/porting/merge-delta.t

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use v5.36;
2+
use Test2::V0;
3+
4+
# load the script
5+
do('./Porting/merge-deltas.pl') or die $@ || $!;
6+
7+
# helper function
8+
sub head2_slice ( $tree, $title ) {
9+
my $begin = next_header_pos( $tree, 2, header_pos( $tree, 1, $title ) );
10+
my $end = next_header_pos( $tree, 1, $begin ) - 1;
11+
return [ $tree->@[ $begin .. $end ] ];
12+
}
13+
14+
# test data
15+
my %pod = do {
16+
local $/;
17+
my ( undef, @kv ) = split /^# (.*)\n/m, <DATA>;
18+
@kv;
19+
};
20+
$pod{master} = slurp( 'Porting/perldelta_template.pod' );
21+
22+
# tree_for:
23+
# just a single test: we're not testing Pod::Simple::SimpleTree
24+
is(
25+
tree_for( $pod{'NAME section'} ),
26+
[
27+
Document => { start_line => 1 },
28+
[ head1 => { start_line => 1 }, 'NAME' ],
29+
[ Para => { start_line => 3 }, 'some text' ]
30+
],
31+
'tree_for on NAME section'
32+
);
33+
34+
# as_pod: round trips
35+
is( as_pod( tree_for( $pod{$_} ) ), $pod{$_}, "$_ POD round trips" )
36+
for sort keys %pod;
37+
38+
# merge_into: skips NAME section
39+
my $master_tree = tree_for( $pod{master} );
40+
my $master_pod = as_pod( $pod{master} );
41+
merge_into( $master_tree, tree_for( $pod{'NAME section'} ), 'NAME section' );
42+
is( as_pod($master_tree), $master_pod, 'merge_into( master, NAME section )' );
43+
44+
# merge_into: head2 section (e.g. Security)
45+
$master_tree = tree_for( $pod{master} );
46+
my $security_tree = tree_for( $pod{Security} );
47+
merge_into( $master_tree, $security_tree, 'Security' );
48+
is(
49+
head2_slice( $security_tree, 'Security' ),
50+
head2_slice( $master_tree, 'Security' ),
51+
'merge_into Security'
52+
);
53+
54+
done_testing;
55+
56+
__DATA__
57+
# NAME section
58+
=head1 NAME
59+
60+
some text
61+
62+
=cut
63+
# Security
64+
=head1 Security
65+
66+
Some security blurb.
67+
68+
=head2 [CVE-1999-12345] Heap buffer overflow vulnerability
69+
70+
A heap buffer overflow vulnerability was discovered in Perl.
71+
72+
=head1 Acknowledgements
73+
74+
ACK
75+
76+
=cut

0 commit comments

Comments
 (0)