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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
use 5.006;
use strict;
use warnings;
use IO::File;
use Path::Tiny qw(path);
use Test::More tests => 3;
use Pod::Tree;
my $Dir = "t/load.d";
LoadFH("$Dir/list");
LoadString("$Dir/list");
LoadParagraphs("$Dir/list");
sub LoadFH {
my $file = shift;
my $fh = IO::File->new;
my $tree = Pod::Tree->new;
$fh->open("$file.pod") or die "Can't open $file.pod: $!\n";
$tree->load_fh($fh);
my $actual = $tree->dump;
my $expected = path("$file.exp")->slurp;
is $actual, $expected;
path("$file.act")->spew($actual);
}
sub LoadString {
my $file = shift;
my $string = path("$file.pod")->slurp;
my $tree = Pod::Tree->new;
$tree->load_string($string);
my $actual = $tree->dump;
my $expected = path("$file.exp")->slurp;
is $actual, $expected;
}
sub LoadParagraphs {
my $file = shift;
my @paragraphs = ReadParagraphs("$file.pod");
my $tree = Pod::Tree->new;
$tree->load_paragraphs( \@paragraphs );
my $actual = $tree->dump;
my $expected = path("$file.exp")->slurp;
is $actual, $expected;
}
sub ReadParagraphs {
my $file = shift;
my $pod = path($file)->slurp;
my @chunks = split /(\n{2,})/, $pod;
my @paragraphs;
while (@chunks) {
push @paragraphs, join '', splice @chunks, 0, 2;
}
@paragraphs;
}
sub Split {
my $string = shift;
my @pieces = split /(\n{2,})/, $string;
my @paragraphs;
while (@pieces) {
my ( $text, $ending ) = splice @pieces, 0, 2;
$ending or $ending = ''; # to quiet -w
push @paragraphs, $text . $ending;
}
@paragraphs;
}
|