PICA-Data
view release on metacpan or search on metacpan
t/30-writer.t view on Meta::CPAN
close $fh;
my $PLAIN = <<'PLAIN';
003@ $01041318383
021A $aHello $$Â¥!
028C/01 $dEmma$aGoldman
PLAIN
my $out = do {local (@ARGV, $/) = $filename; <>};
is $out, $PLAIN, 'Plain writer';
(undef, $filename) = tempfile(OPEN => 0);
pica_writer('plain', fh => $filename);
ok -e $filename, 'write to file';
}
sub write_result {
my ($type, $options, @records) = @_;
my ($fh, $filename) = tempfile();
my $writer = pica_writer($type, fh => $fh, %$options);
foreach my $record (@records) {
$writer->write($record);
}
$writer->end;
close $fh;
return do {local (@ARGV, $/) = $filename; <>};
}
note 'PICA::Writer::Import';
{
my $out = write_result('import', {}, @pica_records);
my $expect = <<EXPECT;
\x1D
\x1E003@ \x1F01041318383
\x1E021A \x1FaHello \$Â¥!
\x1D
t/30-writer.t view on Meta::CPAN
my $parser = pica_parser('PPXML' => 't/files/slim_ppxml.xml');
my $record;
my ($fh, $filename) = tempfile();
my $writer = PICA::Writer::PPXML->new(fh => $fh);
while ($record = $parser->next) {
$writer->write($record);
}
$writer->end;
close $fh;
my $out = do {local (@ARGV, $/) = $filename; <>};
my $in = do {local (@ARGV, $/) = 't/files/slim_ppxml.xml'; <>};
is_xml($out, $in, 'PPXML writer');
}
note 'PICA::Writer::Generic';
{
my $out = write_result('generic', {
us => "#",
rs => "%",
t/30-writer.t view on Meta::CPAN
note 'undefined occurrence';
{
my $pica_record = [['003@', undef, '0', '1041318383']];
my ($fh, $filename) = tempfile();
my $writer = PICA::Writer::Plus->new(fh => $fh);
$writer->write($pica_record);
close $fh;
my $out = do {local (@ARGV, $/) = $filename; <>};
my $PLUS = <<'PLUS';
003@ 01041318383
PLUS
is $out, $PLUS, 'undef occ';
}
{
my %tests = (
" 123A \$xy\n\n" => [["123A",undef,"x","y"," "]],
"? 123A \$xy\n\n" => [["123A",undef,"x","y","?"]]
( run in 1.257 second using v1.01-cache-2.11-cpan-49f99fa48dc )