#!/usr/bin/perl -w
BEGIN {
chdir
't'
if
-d
't'
;
if
(
$ENV
{PERL_CORE}) {
@INC
=
'../lib'
;
}
else
{
unshift
(
@INC
,
'../blib/lib'
);
}
unshift
(
@INC
,
'../blib/lib'
);
$| = 1;
print
"1..5\n"
;
if
($] < 5.008) {
my
$n
;
for
$n
(1..5) {
print
"ok $n # skip -- Perl 5.8 required for UTF-8 support\n"
;
}
exit
;
}
}
END {
print
"not ok 1\n"
unless
$loaded
;
}
$loaded
= 1;
print
"ok 1\n"
;
my
$n
= 2;
eval
{
binmode
(\
*DATA
,
':encoding(utf-8)'
) };
eval
{
binmode
(\
*STDOUT
,
':encoding(utf-8)'
) };
while
(<DATA>) {
my
%options
;
next
until
$_
eq
"###\n"
;
while
(<DATA>) {
last
if
$_
eq
"###\n"
;
my
(
$option
,
$value
) =
split
;
$options
{
$option
} =
$value
;
}
open
(TMP,
'> tmp.pod'
) or
die
"Cannot create tmp.pod: $!\n"
;
eval
{
binmode
(\
*TMP
,
':encoding(utf-8)'
) };
print
TMP
"=encoding utf-8\n\n"
;
while
(<DATA>) {
last
if
$_
eq
"###\n"
;
print
TMP
$_
;
}
close
TMP;
my
$parser
= Pod::Man->new (
%options
) or
die
"Cannot create parser\n"
;
open
(OUT,
'> out.tmp'
) or
die
"Cannot create out.tmp: $!\n"
;
$parser
->parse_from_file (
'tmp.pod'
, \
*OUT
);
close
OUT;
my
$accents
= 0;
open
(TMP,
'out.tmp'
) or
die
"Cannot open out.tmp: $!\n"
;
eval
{
binmode
(\
*TMP
,
':encoding(utf-8)'
) };
while
(<TMP>) {
$accents
= 1
if
/Accent mark definitions/;
last
if
/^\.nh/;
}
my
$output
;
{
local
$/;
$output
= <TMP>;
}
close
TMP;
unlink
(
'tmp.pod'
,
'out.tmp'
);
if
((
$options
{utf8} && !
$accents
) || (!
$options
{utf8} &&
$accents
)) {
print
"ok $n\n"
;
}
else
{
print
"not ok $n\n"
;
print
(
$accents
?
"Saw accents\n"
:
"Saw no accents\n"
);
print
(
$options
{utf8} ?
"Wanted no accents\n"
:
"Wanted accents\n"
);
}
$n
++;
my
$expected
=
''
;
while
(<DATA>) {
last
if
$_
eq
"###\n"
;
$expected
.=
$_
;
}
if
(
$output
eq
$expected
) {
print
"ok $n\n"
;
}
else
{
print
"not ok $n\n"
;
print
"Expected\n========\n$expected\nOutput\n======\n$output\n"
;
}
$n
++;
}