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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
use 5.006;
use strict;
use warnings;
use HTML::Stream;
use Path::Tiny qw(path);
use Test::More;
use Pod::Tree;
use Pod::Tree::HTML;
my $Dir = 't/html.d';
my $nTests = 5 + 5 + 6 + 2 + 2 + 1 + 1;
plan tests => $nTests;
Source1();
Source2();
Source3();
Source4();
Source5();
Dest1();
Dest2();
Dest3();
Dest4();
Dest5();
Translate();
Empty();
Emit();
Base();
Depth();
sub Source1 {
my $tree = Pod::Tree->new;
$tree->load_file("$Dir/paragraph.pod");
my $actual;
my $html = Pod::Tree::HTML->new( $tree, \$actual );
Source( $html, \$actual );
}
sub Source2 {
my $actual;
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", \$actual );
Source( $html, \$actual );
}
sub Source3 {
my $io = IO::File->new("$Dir/paragraph.pod");
my $actual;
my $html = Pod::Tree::HTML->new( $io, \$actual );
Source( $html, \$actual );
}
sub Source4 {
my $pod = path("$Dir/paragraph.pod")->slurp;
my $actual;
my $html = Pod::Tree::HTML->new( \$pod, \$actual );
Source( $html, \$actual );
}
sub Source5 {
my @paragraphs = ReadParagraphs("$Dir/paragraph.pod");
my $actual;
my $html = Pod::Tree::HTML->new( \@paragraphs, \$actual );
Source( $html, \$actual );
}
sub Source {
my ( $html, $actual ) = @_;
$html->set_options( toc => 0 );
$html->translate;
my $expected = path("$Dir/paragraph.exp")->slurp;
is $$actual, $expected;
}
sub Dest1 {
my $actual;
my $string = IO::String->new($actual);
my $stream = HTML::Stream->new($string);
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", $stream );
$html->set_options( toc => 0 );
$html->translate;
my $expected = path("$Dir/paragraph.exp")->slurp;
is $actual, $expected;
}
sub Dest2 {
{
my $file = IO::File->new( "$Dir/paragraph.act", '>' );
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", $file );
$html->set_options( toc => 0 );
$html->translate;
}
my $expected = path("$Dir/paragraph.exp")->slurp;
my $actual = path("$Dir/paragraph.act")->slurp;
is $actual, $expected;
}
sub Dest3 {
my $actual;
my $string = IO::String->new($actual);
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", $string );
$html->set_options( toc => 0 );
$html->translate;
my $expected = path("$Dir/paragraph.exp")->slurp;
is $actual, $expected;
}
sub Dest4 {
my $actual;
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", \$actual );
$html->set_options( toc => 0 );
$html->translate;
my $expected = path("$Dir/paragraph.exp")->slurp;
is $actual, $expected;
}
sub Dest5 {
{
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", "$Dir/paragraph.act" );
$html->set_options( toc => 0 );
$html->translate;
}
my $expected = path("$Dir/paragraph.exp")->slurp;
my $actual = path("$Dir/paragraph.act")->slurp;
is $actual, $expected;
}
sub Translate {
for my $file (qw(cut paragraph list sequence for link)) {
my $actual = '';
my $html = Pod::Tree::HTML->new( "$Dir/$file.pod", \$actual );
$html->set_options( toc => 0 );
$html->translate;
my $expected = path("$Dir/$file.exp")->slurp;
is $actual, $expected;
path("$Dir/$file.act")->spew($actual);
# WriteFile("$ENV{HOME}/public_html/pod/$file.html", $actual);
}
}
sub Empty {
my $actual = "$Dir/empty.act";
unlink $actual;
my $html = Pod::Tree::HTML->new( "$Dir/empty.pod", $actual );
$html->translate;
ok !-e $actual;
$html = Pod::Tree::HTML->new( "$Dir/empty.pod", $actual, empty => 1 );
$html->translate;
ok -e $actual;
}
sub Emit {
for my $piece (qw(body toc)) {
my $actual = '';
my $html = Pod::Tree::HTML->new( "$Dir/paragraph.pod", \$actual );
my $emit = "emit_$piece";
$html->set_options( hr => 0 );
$html->$emit;
my $expected = path("$Dir/$piece.exp")->slurp;
is $actual, $expected;
path("$Dir/$piece.act")->spew($actual);
# WriteFile("$ENV{HOME}/public_html/pod/$piece.html", $actual);
}
}
sub Base {
my $actual = '';
my $html = Pod::Tree::HTML->new( "$Dir/link.pod", \$actual );
$html->set_options( toc => 0, base => 'http://world.std.com/~swmcd/pod' );
$html->translate;
my $expected = path("$Dir/base.exp")->slurp;
is $actual, $expected;
path("$Dir/base.act")->spew($actual);
# WriteFile("$ENV{HOME}/public_html/pod/base.html", $actual);
}
sub Depth {
my $actual = '';
my $html = Pod::Tree::HTML->new( "$Dir/link.pod", \$actual );
$html->set_options( toc => 0, depth => 2 );
$html->translate;
my $expected = path("$Dir/depth.exp")->slurp;
is $actual, $expected;
path("$Dir/depth.act")->spew($actual);
# WriteFile("$ENV{HOME}/public_html/pod/depth.html", $actual);
}
sub ReadParagraphs {
my $file = shift;
my $pod = path($file)->slurp;
my @chunks = split /( \n\s*\n | \r\s*\r | \r\n\s*\r\n )/x, $pod;
my @paragraphs;
while (@chunks) {
push @paragraphs, join '', splice @chunks, 0, 2;
}
@paragraphs;
}
|