BEGIN {
use_ok(
'Text::BibTeX'
);
my
$common
= getcwd().
"/t/common.pl"
;
require
$common
;
}
my
(
$fh
,
$entry
);
my
$regular_file
=
'btparse/tests/data/regular.bib'
;
open
(BIB,
$regular_file
) ||
die
"couldn't open $regular_file: $!\n"
;
err_like
sub
{ ok(
$entry
= Text::BibTeX::Entry->new(
$regular_file
, \
*BIB
)); },
qr!$regular_file, line 5, warning: undefined macro "junk"!
;
test_entry (
$entry
,
'book'
,
'abook'
,
[
qw(title editor publisher year)
],
[
'A Book'
,
'John Q. Random'
,
'Foo Bar \& Sons'
,
'1922'
]);
ok(!Text::BibTeX::Entry->new(
$regular_file
, \
*BIB
));
seek
(BIB, 0, 0);
err_like
sub
{ ok(
$entry
->parse (
undef
, \
*BIB
)); },
qr!line 5, warning: undefined macro "junk"!
;
test_entry (
$entry
,
'book'
,
'abook'
,
[
qw(title editor publisher year)
],
[
'A Book'
,
'John Q. Random'
,
'Foo Bar \& Sons'
,
'1922'
]);
ok(!
$entry
->parse (
undef
, \
*BIB
));
close
(BIB);
ok(
$entry
->parse_s (
'@string(junk={, III})'
));
test_entry (
$entry
,
'string'
,
undef
, [
'junk'
], [
', III'
]);
$fh
= IO::File->new(
$regular_file
)
or
die
"couldn't open $regular_file: $!\n"
;
no_err
sub
{ ok(
$entry
= Text::BibTeX::Entry->new(
$regular_file
,
$fh
)); };
test_entry (
$entry
,
'book'
,
'abook'
,
[
qw(title editor publisher year)
],
[
'A Book'
,
'John Q. Random, III'
,
'Foo Bar \& Sons'
,
'1922'
]);
ok(! Text::BibTeX::Entry->new(
$regular_file
,
$fh
));
$fh
->
seek
(0, 0);
no_err
sub
{ ok(
$entry
->parse (
$regular_file
,
$fh
)); };
test_entry (
$entry
,
'book'
,
'abook'
,
[
qw(title editor publisher year)
],
[
'A Book'
,
'John Q. Random, III'
,
'Foo Bar \& Sons'
,
'1922'
]);
ok(! Text::BibTeX::Entry->new(
$regular_file
,
$fh
));
$fh
->
close
;