From 471dfa980cfd9949095c1ce99dfecd51045deb05 Mon Sep 17 00:00:00 2001 From: djfiander Date: Tue, 12 Jan 2010 02:14:38 +0000 Subject: [PATCH] move load_MARC_rec into separate package to prep for creating new test scripts git-svn-id: svn://svn.open-ils.org/ILS/trunk@15302 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t | 61 ++----------------- .../perlmods/OpenILS/Utils/MFHD/test/testlib.pm | 70 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 57 deletions(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t index b5c963c12f..35d86cdecf 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/mfhd.t @@ -8,7 +8,9 @@ use Test::More 'no_plan'; use MARC::Record; use OpenILS::Utils::MFHD; -my $testno = 0; +use testlib; + +my $testno = 1; sub right_answer { my $holding = shift; @@ -24,68 +26,13 @@ sub right_answer { return $answer; } -sub load_MARC_rec { - my $fh = shift; - my $rec; - my $line; - my $marc = undef; - - # skim to beginning of record (a non-blank, non comment line) - while ($line = <$fh>) { - chomp $line; - last if (!($line =~ /^\s*$/) && !($line =~ /^#/)); - } - - return undef if !$line; - - $testno += 1; - $marc = MARC::Record->new(); - carp('No record created!') unless $marc; - - $marc->leader('01119nas 2200313 a 4500'); - $marc->append_fields( - MARC::Field->new('008', '970701c18439999enkwr p 0 a0eng ')); - $marc->append_fields( - MARC::Field->new('035', '', '', a => sprintf('%04d', $testno))); - - while ($line) { - next if $line =~ /^#/; # allow embedded comments - - return $marc if $line =~ /^\s*$/; - - my ($fieldno, $indicators, $rest) = split(/ /, $line, 3); - my @inds = unpack('aa', $indicators); - my $field; - my @subfields; - - @subfields = (); - foreach my $subfield (split(/\$/, $rest)) { - next unless $subfield; - - my ($key, $val) = unpack('aa*', $subfield); - push @subfields, $key, $val; - } - - $field = MARC::Field->new( - $fieldno, $inds[0], $inds[1], - a => 'scratch', - @subfields - ); - - $marc->append_fields($field); - - $line = <$fh>; - chomp $line if $line; - } - return $marc; -} my $rec; my @captions; open(my $testdata, "new($rec); foreach my $cap (sort { $a->tag <=> $b->tag } $rec->field('85.')) { diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm new file mode 100644 index 0000000000..2867337a41 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/test/testlib.pm @@ -0,0 +1,70 @@ +package testlib; + +use strict; +use warnings; + +use base 'Exporter'; + +our @EXPORT_OK = qw(load_MARC_rec); + +use Data::Dumper; + +use MARC::Record; + +sub load_MARC_rec { + my $fh = shift; + my $testno = shift; + my $rec; + my $line; + my $marc = undef; + + # skim to beginning of record (a non-blank, non comment line) + while ($line = <$fh>) { + chomp $line; + last if (!($line =~ /^\s*$/) && !($line =~ /^#/)); + } + + return undef if !$line; + + $marc = MARC::Record->new(); + carp('No record created!') unless $marc; + + $marc->leader('01119nas 2200313 a 4500'); + $marc->append_fields( + MARC::Field->new('008', '970701c18439999enkwr p 0 a0eng ')); + $marc->append_fields( + MARC::Field->new('035', '', '', a => sprintf('%04d', $testno))); + + while ($line) { + next if $line =~ /^#/; # allow embedded comments + + return $marc if $line =~ /^\s*$/; + + my ($fieldno, $indicators, $rest) = split(/ /, $line, 3); + my @inds = unpack('aa', $indicators); + my $field; + my @subfields; + + @subfields = (); + foreach my $subfield (split(/\$/, $rest)) { + next unless $subfield; + + my ($key, $val) = unpack('aa*', $subfield); + push @subfields, $key, $val; + } + + $field = MARC::Field->new( + $fieldno, $inds[0], $inds[1], + a => 'scratch', + @subfields + ); + + $marc->append_fields($field); + + $line = <$fh>; + chomp $line if $line; + } + return $marc; +} + +1; -- 2.11.0