[libcatmandu-marc-perl] 201/208: Creating tests Perl module
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 03:42:50 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.19
in repository libcatmandu-marc-perl.
commit 0de1750607d7d33e32f02afb9ca84ec0bf1974f9
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Wed Sep 27 15:01:03 2017 +0200
Creating tests Perl module
---
lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm | 1 +
lib/Catmandu/Exporter/MARC/XML.pm | 3 +-
t/00-load.t | 21 ----
t/01-importer.t | 55 ---------
t/04-marc21.t | 20 ----
t/13-marcxml.t | 56 ---------
t/28-marc_append.t | 23 ----
t/Catmandu/Exporter/MARC.t | 17 +++
t/Catmandu/Exporter/MARC/ALEPHSEQ.t | 74 ++++++++++++
t/Catmandu/Exporter/MARC/Base.t | 17 +++
t/Catmandu/Exporter/MARC/ISO.t | 17 +++
t/Catmandu/Exporter/MARC/MARCMaker.t | 17 +++
t/Catmandu/Exporter/MARC/MiJ.t | 17 +++
t/{08-exporter.t => Catmandu/Exporter/MARC/XML.t} | 129 +++++++++++----------
.../Fix/Bind/marc_each.t} | 12 +-
t/Catmandu/Fix/Condition/marc_all_match.t | 17 +++
t/Catmandu/Fix/Condition/marc_any_match.t | 17 +++
.../Fix/Condition/marc_has.t} | 16 ++-
t/Catmandu/Fix/Condition/marc_has_many.t | 17 +++
t/Catmandu/Fix/Condition/marc_match.t | 17 +++
.../Fix/Condition/marc_spec_has.t} | 17 ++-
t/Catmandu/Fix/Inline/marc_add.t | 17 +++
t/Catmandu/Fix/Inline/marc_map.t | 17 +++
t/Catmandu/Fix/Inline/marc_remove.t | 17 +++
t/Catmandu/Fix/Inline/marc_set.t | 17 +++
t/{09-marc_add.t => Catmandu/Fix/marc_add.t} | 20 ++--
t/Catmandu/Fix/marc_append.t | 25 ++++
t/{26-marc_copy.t => Catmandu/Fix/marc_copy.t} | 13 ++-
t/{30-marc_cut.t => Catmandu/Fix/marc_cut.t} | 12 +-
.../Fix/marc_decode_dollar_subfields.t} | 19 ++-
.../Fix/marc_in_json.t} | 27 +++--
t/{03-marc_map.t => Catmandu/Fix/marc_map.t} | 17 ++-
t/{29-marc_paste.t => Catmandu/Fix/marc_paste.t} | 15 ++-
t/{05-marc_remove.t => Catmandu/Fix/marc_remove.t} | 19 ++-
.../Fix/marc_replace_all.t} | 16 ++-
t/{12-marc_set.t => Catmandu/Fix/marc_set.t} | 20 ++--
t/{21-marc-spec.t => Catmandu/Fix/marc_spec.t} | 22 +++-
t/Catmandu/Fix/marc_xml.t | 17 +++
t/Catmandu/Importer/MARC.t | 17 +++
.../Importer/MARC/ALEPHSEQ.t} | 19 ++-
t/Catmandu/Importer/MARC/Decoder.t | 17 +++
t/{19-io-string.t => Catmandu/Importer/MARC/ISO.t} | 47 +++++++-
t/Catmandu/Importer/MARC/Lint.t | 17 +++
.../Importer/MARC/MARCMaker.t} | 20 +++-
t/{11-mij.t => Catmandu/Importer/MARC/MiJ.t} | 20 +++-
.../Importer/MARC/MicroLIF.t} | 19 ++-
t/Catmandu/Importer/MARC/RAW.t | 32 +++++
t/Catmandu/Importer/MARC/Record.t | 39 +++++++
t/Catmandu/Importer/MARC/XML.t | 44 +++++++
t/Catmandu/MARC.t | 17 +++
t/{99-deprecate.t => deprecate.t} | 0
t/{07-inline-fix.t => inline-fix.t} | 0
t/{18-inlineable.t => inlineable.t} | 0
t/{22-mapping_rules.t => mapping_rules.t} | 0
...3-mapping_rules_spec.t => mapping_rules_spec.t} | 0
...4-marc-spec-subspecs.t => marc-spec-subspecs.t} | 0
...internal-syntax.t => old-new-internal-syntax.t} | 0
57 files changed, 863 insertions(+), 335 deletions(-)
diff --git a/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm b/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
index dca0253..fb91280 100644
--- a/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
+++ b/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
@@ -133,6 +133,7 @@ sub add {
sub commit {
my $self = shift;
$self->fh->flush;
+ 1;
}
1;
diff --git a/lib/Catmandu/Exporter/MARC/XML.pm b/lib/Catmandu/Exporter/MARC/XML.pm
index dc70c22..57a272b 100644
--- a/lib/Catmandu/Exporter/MARC/XML.pm
+++ b/lib/Catmandu/Exporter/MARC/XML.pm
@@ -97,6 +97,8 @@ sub commit {
}
$self->fh->flush;
+
+ 1;
}
1;
@@ -180,4 +182,3 @@ L<Catmandu::Counter>, and L<Catmandu::Logger> for a full list of methods.
L<Catmandu::Importer::MARC::XML>
=cut
-
diff --git a/t/00-load.t b/t/00-load.t
deleted file mode 100644
index e2388b3..0000000
--- a/t/00-load.t
+++ /dev/null
@@ -1,21 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-use Test::More;
-
-BEGIN {
- use_ok 'Catmandu::Importer::MARC';
- use_ok 'Catmandu::Exporter::MARC';
- use_ok 'Catmandu::Fix::marc_map';
- use_ok 'Catmandu::Fix::marc_xml';
- use_ok 'Catmandu::Fix::marc_in_json';
- use_ok 'Catmandu::Fix::marc_set';
- use_ok 'Catmandu::Fix::marc_remove';
- use_ok 'Catmandu::Fix::marc_add';
- use_ok 'Catmandu::Fix::marc_spec';
- use_ok 'Catmandu::Fix::marc_decode_dollar_subfields';
- use_ok 'Catmandu::Fix::Condition::marc_match';
-}
-
-done_testing 11;
diff --git a/t/01-importer.t b/t/01-importer.t
deleted file mode 100644
index 1c1d456..0000000
--- a/t/01-importer.t
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Catmandu::Importer::MARC;
-use MARC::File::USMARC;
-use Test::Simple tests => 10;
-
-my $importer = Catmandu::Importer::MARC->new(
- file => 't/camel.mrc',
- type => "ISO"
-);
-my $records = $importer->to_array();
-
-ok( @$records == 10, 'got all records' );
-ok( $records->[0]->{'_id'} eq 'fol05731351 ', 'got _id' );
-ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
-ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
- '_id matches record id' );
-
-my $file = MARC::File::USMARC->in('t/camel.mrc');
-my @marc_objects;
-while ( my $marc = $file->next() ) {
- push( @marc_objects, $marc );
-}
-$file->close();
-undef $file;
-$importer = Catmandu::Importer::MARC->new( records => \@marc_objects );
-$records = $importer->to_array();
-
-ok( @$records == 10, 'got all records' );
-ok( $records->[0]->{'_id'} eq 'fol05731351 ', 'got _id' );
-ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
-ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
- '_id matches record id' );
-
-# Test that the ID can be formed like '260c' (not a useful field in real life!)
-$importer = Catmandu::Importer::MARC->new(
- file => 't/camel.mrc',
- type => "ISO",
- id => '260c',
-);
-$records = $importer->to_array();
-ok( $records->[0]->{'_id'} eq '2000.', 'got _id from subfield' );
-
-# Test broken records
-$importer = Catmandu::Importer::MARC->new(
- file => 't/broken.xml',
- type => "XML",
- skip_errors => 1,
-);
-$records = $importer->to_array();
-
-ok (@$records == 9, 'skipped one record');
diff --git a/t/04-marc21.t b/t/04-marc21.t
deleted file mode 100644
index 070f945..0000000
--- a/t/04-marc21.t
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use utf8;
-
-use Catmandu::Importer::MARC;
-use Test::Simple tests => 3;
-
-my $importer = Catmandu::Importer::MARC->new(file => 't/marc.xml', type => 'XML');
-
-my $records = $importer->to_array;
-
-ok(@$records == 1);
-
-ok($records->[0]->{record}->[1]->[0] eq '920');
-
-ok($records->[0]->{record}->[8]->[4] eq 'TEEM (한국전기전자재료학회)');
-
-1;
diff --git a/t/13-marcxml.t b/t/13-marcxml.t
deleted file mode 100644
index b3d3b40..0000000
--- a/t/13-marcxml.t
+++ /dev/null
@@ -1,56 +0,0 @@
-use strict;
-use warnings;
-
-use Catmandu::Exporter::MARC;
-use XML::LibXML;
-use Test::More;
-
-my $record = {
- record => [
- ['001', undef, undef, undef, 'rec002'],
- ['100', ' ', ' ', 'a', 'Slayer'],
- ['245', ' ', ' ',
- 'a', 'Reign in Blood' ,
- ]
- ]
-};
-
-# XML exporter with default arguments
-
-my $xml = undef;
-my $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML');
-$exporter->add($record);
-$exporter->commit;
-my $dom = XML::LibXML->load_xml( string => $xml );
-ok($dom->version() eq '1.0', 'document version');
-ok($dom->encoding() eq 'UTF-8', 'document encoding');
-my $root = $dom->documentElement();
-ok($root->localname eq 'collection', 'root collection');
-ok($root->prefix eq 'marc', 'namespace prefix');
-
-
-# XML exporter with arguments
-
-$xml = undef;
-$exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML', collection => 0, xml_declaration => 1);
-$exporter->add($record);
-$exporter->commit;
-$dom = XML::LibXML->load_xml( string => $xml );
-ok($dom->version() eq '1.0', 'document version');
-ok($dom->encoding() eq 'UTF-8', 'document encoding');
-$root = $dom->documentElement();
-ok($root->localname eq 'record', 'root record');
-ok($root->prefix eq 'marc', 'namespace prefix');
-
-# XML exporter with arguments
-
-$xml = undef;
-$exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML' , collection => 1, xml_declaration => 0);
-$exporter->add($record);
-$exporter->commit;
-$dom = XML::LibXML->load_xml( string => $xml );
-$root = $dom->documentElement();
-ok($root->localname eq 'collection', 'root collection');
-ok($root->prefix eq 'marc', 'namespace prefix');
-
-done_testing;
\ No newline at end of file
diff --git a/t/28-marc_append.t b/t/28-marc_append.t
deleted file mode 100644
index 3991751..0000000
--- a/t/28-marc_append.t
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
-use Test::More;
-
-use Catmandu::Importer::MARC;
-use Catmandu::Fix;
-
-
-#---
-{
- my $fixer = Catmandu::Fix->new(fixes => [q|marc_append('100','.')|,q|marc_map('100','test')|]);
- my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
- my $record = $fixer->fix($importer->first);
-
- like $record->{test}, qr/^Martinsson, Tobias,1976-\.$/, q|fix: marc_append('100','.')|;
-}
-
-done_testing;
diff --git a/t/Catmandu/Exporter/MARC.t b/t/Catmandu/Exporter/MARC.t
new file mode 100644
index 0000000..5d040a3
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Exporter/MARC/ALEPHSEQ.t b/t/Catmandu/Exporter/MARC/ALEPHSEQ.t
new file mode 100644
index 0000000..4f849b9
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC/ALEPHSEQ.t
@@ -0,0 +1,74 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Catmandu::Exporter::MARC;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::ALEPHSEQ';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+my $xml = undef;
+
+my $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'ALEPHSEQ' , skip_empty_subfields => 1);
+
+ok $exporter , 'got an MARC/ALEPHSEQ exporter';
+
+ok $exporter->add({
+ _id => '1' ,
+ record => [
+ ['001', undef, undef, '_', 'rec001'],
+ ['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'],
+ ['245', ' ', ' ',
+ 'a', 'Sketches in Blue' ,
+ ],
+ ['500', ' ', ' ', 'a', undef],
+ ['501', ' ', ' ' ],
+ ['502', ' ', ' ', 'a', undef, 'b' , 'ok'],
+ ['503'. ' ', ' ', 'a', ''],
+ ]
+});
+
+ok $exporter->commit;
+
+ok($xml =~ /^000000001/, 'test id');
+ok($xml =~ /000000001 100 L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
+ok($xml !~ /000000001 500/, 'test skip empty subfields');
+
+$xml = '';
+$exporter = Catmandu::Exporter::MARC->new(
+ file => \$xml,
+ type=> 'ALEPHSEQ',
+ record_format => 'MARC-in-JSON',
+ skip_empty_subfields => 1
+);
+
+ok($exporter, "create exporter ALEPHSEQ for MARC-in-JSON");
+
+$exporter->add({
+ _id => '1',
+ fields => [
+ { '001' => 'rec001' } ,
+ { '100' => { 'subfields' => [ { 'a' => 'Davis, Miles'} , { 'c' => 'Test'}], 'ind1' => ' ', 'ind2' => ' '}} ,
+ { '245' => { 'subfields' => [ { 'a' => 'Sketches in Blue'}], 'ind1' => ' ', 'ind2' => ' '}} ,
+ { '500' => { 'subfields' => [ { 'a' => undef }] , 'ind1' => ' ', 'ind2' => ' '}} ,
+ { '501' => { 'ind1' => ' ', 'ind2' => ' ' }} ,
+ { '502' => { 'subfields' => [ { 'a' => undef} , { 'b' , 'ok' } ] , 'ind1' => ' ', 'ind2' => ' ' } } ,
+ { '503' => { 'subfields' => [ { 'a' => '' }] , 'ind1' => ' ', 'ind2' => ' '}} ,
+ { '540' => { 'subfields' => [ { 'a' => "\nabcd\n" }] , 'ind1' => ' ', 'ind2' => ' '}}
+ ]
+});
+
+ok($xml =~ /^000000001/, 'test id');
+ok($xml =~ /000000001 100 L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
+ok($xml !~ /000000001 500/, 'test skip empty subfields');
+ok($xml =~ /000000001 540 L \$\$aabcd/, 'test skip newlines');
+
+done_testing;
diff --git a/t/Catmandu/Exporter/MARC/Base.t b/t/Catmandu/Exporter/MARC/Base.t
new file mode 100644
index 0000000..8f039a4
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC/Base.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::Base';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Exporter/MARC/ISO.t b/t/Catmandu/Exporter/MARC/ISO.t
new file mode 100644
index 0000000..99573f7
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC/ISO.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::ISO';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Exporter/MARC/MARCMaker.t b/t/Catmandu/Exporter/MARC/MARCMaker.t
new file mode 100644
index 0000000..8ce07f7
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC/MARCMaker.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::MARCMaker';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Exporter/MARC/MiJ.t b/t/Catmandu/Exporter/MARC/MiJ.t
new file mode 100644
index 0000000..edadf7b
--- /dev/null
+++ b/t/Catmandu/Exporter/MARC/MiJ.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::MiJ';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/08-exporter.t b/t/Catmandu/Exporter/MARC/XML.t
similarity index 56%
rename from t/08-exporter.t
rename to t/Catmandu/Exporter/MARC/XML.t
index c672234..604be4b 100644
--- a/t/08-exporter.t
+++ b/t/Catmandu/Exporter/MARC/XML.t
@@ -1,19 +1,29 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Exporter::MARC;
use XML::XPath;
-use Test::Simple tests => 25;
+use XML::LibXML;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Exporter::MARC::XML';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $xml = undef;
my $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'XML' , collection => 0);
-ok($exporter, "create exporter XML");
+ok $exporter , 'got an MARC/XML exporter';
-$exporter->add({
+ok $exporter->add({
record => [
['001', undef, undef, undef, 'rec001'],
['100', ' ', ' ', 'a', 'Davis, Miles'],
@@ -27,7 +37,7 @@ $exporter->add({
]
});
-$exporter->commit;
+ok $exporter->commit;
my $xp;
ok($xp = XML::XPath->new(xml => $xml), "parse XML");
@@ -39,11 +49,12 @@ ok(! $xp->exists('/marc:record/marc:datafield[@tag="502"]/marc:subfield[@code="a
ok(! $xp->exists('/marc:record/marc:datafield[@tag="503"]/marc:subfield[@code="a"]') ,'skipped 503a - empty subfields');
$xml = undef;
+
$exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'XML', record_format => 'MARC-in-JSON', collection => 0);
ok($exporter, "create exporter MARC-in-JSON");
-$exporter->add({
+ok $exporter->add({
fields => [
{ '001' => 'rec001' } ,
{ '100' => { 'subfields' => [ { 'a' => 'Davis, Miles'}], 'ind1' => ' ', 'ind2' => ' '}} ,
@@ -55,6 +66,8 @@ $exporter->add({
]
});
+ok $exporter->commit;
+
ok($xp = XML::XPath->new(xml => $xml), "parse XML");
ok($xp->findvalue('/marc:record/marc:controlfield[@tag="001"]') eq 'rec001','test 001');
ok($xp->findvalue('/marc:record/marc:datafield[@tag="245"]/marc:subfield[@code="a"]') eq 'Sketches in Blue','test 245');
@@ -63,56 +76,52 @@ ok(! $xp->exists('/marc:record/marc:datafield[@tag="501"]') ,'skipped 501 - no s
ok(! $xp->exists('/marc:record/marc:datafield[@tag="502"]/marc:subfield[@code="a"]') ,'skipped 502a - empty subfields');
ok(! $xp->exists('/marc:record/marc:datafield[@tag="503"]/marc:subfield[@code="a"]') ,'skipped 503a - empty subfields');
-$xml = '';
-$exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'ALEPHSEQ' , skip_empty_subfields => 1);
-
-ok($exporter, "create exporter ALEPHSEQ");
-
-$exporter->add({
- _id => '1' ,
- record => [
- ['001', undef, undef, '_', 'rec001'],
- ['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'],
- ['245', ' ', ' ',
- 'a', 'Sketches in Blue' ,
- ],
- ['500', ' ', ' ', 'a', undef],
- ['501', ' ', ' ' ],
- ['502', ' ', ' ', 'a', undef, 'b' , 'ok'],
- ['503'. ' ', ' ', 'a', ''],
- ]
-});
-
-
-ok($xml =~ /^000000001/, 'test id');
-ok($xml =~ /000000001 100 L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
-ok($xml !~ /000000001 500/, 'test skip empty subfields');
-
-$xml = '';
-$exporter = Catmandu::Exporter::MARC->new(
- file => \$xml,
- type=> 'ALEPHSEQ',
- record_format => 'MARC-in-JSON',
- skip_empty_subfields => 1
-);
-
-ok($exporter, "create exporter ALEPHSEQ for MARC-in-JSON");
-
-$exporter->add({
- _id => '1',
- fields => [
- { '001' => 'rec001' } ,
- { '100' => { 'subfields' => [ { 'a' => 'Davis, Miles'} , { 'c' => 'Test'}], 'ind1' => ' ', 'ind2' => ' '}} ,
- { '245' => { 'subfields' => [ { 'a' => 'Sketches in Blue'}], 'ind1' => ' ', 'ind2' => ' '}} ,
- { '500' => { 'subfields' => [ { 'a' => undef }] , 'ind1' => ' ', 'ind2' => ' '}} ,
- { '501' => { 'ind1' => ' ', 'ind2' => ' ' }} ,
- { '502' => { 'subfields' => [ { 'a' => undef} , { 'b' , 'ok' } ] , 'ind1' => ' ', 'ind2' => ' ' } } ,
- { '503' => { 'subfields' => [ { 'a' => '' }] , 'ind1' => ' ', 'ind2' => ' '}} ,
- { '540' => { 'subfields' => [ { 'a' => "\nabcd\n" }] , 'ind1' => ' ', 'ind2' => ' '}}
- ]
-});
-
-ok($xml =~ /^000000001/, 'test id');
-ok($xml =~ /000000001 100 L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
-ok($xml !~ /000000001 500/, 'test skip empty subfields');
-ok($xml =~ /000000001 540 L \$\$aabcd/, 'test skip newlines');
+{
+ my $record = {
+ record => [
+ ['001', undef, undef, undef, 'rec002'],
+ ['100', ' ', ' ', 'a', 'Slayer'],
+ ['245', ' ', ' ',
+ 'a', 'Reign in Blood' ,
+ ]
+ ]
+ };
+
+ # XML exporter with default arguments
+ my $xml = undef;
+ my $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML');
+ $exporter->add($record);
+ $exporter->commit;
+ my $dom = XML::LibXML->load_xml( string => $xml );
+ ok($dom->version() eq '1.0', 'document version');
+ ok($dom->encoding() eq 'UTF-8', 'document encoding');
+ my $root = $dom->documentElement();
+ ok($root->localname eq 'collection', 'root collection');
+ ok($root->prefix eq 'marc', 'namespace prefix');
+
+
+ # XML exporter with arguments
+ $xml = undef;
+ $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML', collection => 0, xml_declaration => 1);
+ $exporter->add($record);
+ $exporter->commit;
+ $dom = XML::LibXML->load_xml( string => $xml );
+ ok($dom->version() eq '1.0', 'document version');
+ ok($dom->encoding() eq 'UTF-8', 'document encoding');
+ $root = $dom->documentElement();
+ ok($root->localname eq 'record', 'root record');
+ ok($root->prefix eq 'marc', 'namespace prefix');
+
+ # XML exporter with arguments
+
+ $xml = undef;
+ $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type => 'XML' , collection => 1, xml_declaration => 0);
+ $exporter->add($record);
+ $exporter->commit;
+ $dom = XML::LibXML->load_xml( string => $xml );
+ $root = $dom->documentElement();
+ ok($root->localname eq 'collection', 'root collection');
+ ok($root->prefix eq 'marc', 'namespace prefix');
+}
+
+done_testing;
diff --git a/t/16-marc-each.t b/t/Catmandu/Fix/Bind/marc_each.t
similarity index 93%
rename from t/16-marc-each.t
rename to t/Catmandu/Fix/Bind/marc_each.t
index 6ca2460..83ddddb 100644
--- a/t/16-marc-each.t
+++ b/t/Catmandu/Fix/Bind/marc_each.t
@@ -1,20 +1,20 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
my $pkg;
+
BEGIN {
$pkg = 'Catmandu::Fix::Bind::marc_each';
use_ok $pkg;
}
+
require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => [q|
@@ -45,4 +45,4 @@ $fixer->fix($importer)->each(sub {
ok ! exists $record->{title} , "field 245 deleted $id";
});
-done_testing;
\ No newline at end of file
+done_testing;
diff --git a/t/Catmandu/Fix/Condition/marc_all_match.t b/t/Catmandu/Fix/Condition/marc_all_match.t
new file mode 100644
index 0000000..abda08b
--- /dev/null
+++ b/t/Catmandu/Fix/Condition/marc_all_match.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_all_match';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Fix/Condition/marc_any_match.t b/t/Catmandu/Fix/Condition/marc_any_match.t
new file mode 100644
index 0000000..91063c1
--- /dev/null
+++ b/t/Catmandu/Fix/Condition/marc_any_match.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_any_match';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/20-marc_has.t b/t/Catmandu/Fix/Condition/marc_has.t
similarity index 86%
rename from t/20-marc_has.t
rename to t/Catmandu/Fix/Condition/marc_has.t
index 76f3785..db5335e 100644
--- a/t/20-marc_has.t
+++ b/t/Catmandu/Fix/Condition/marc_has.t
@@ -1,15 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_has';
+ use_ok $pkg;
+}
+require_ok $pkg;
my $fixes = <<EOF;
if marc_has(245)
diff --git a/t/Catmandu/Fix/Condition/marc_has_many.t b/t/Catmandu/Fix/Condition/marc_has_many.t
new file mode 100644
index 0000000..e6b2564
--- /dev/null
+++ b/t/Catmandu/Fix/Condition/marc_has_many.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_has_many';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Fix/Condition/marc_match.t b/t/Catmandu/Fix/Condition/marc_match.t
new file mode 100644
index 0000000..9eafe77
--- /dev/null
+++ b/t/Catmandu/Fix/Condition/marc_match.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_match';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/25-marc_spec_has.t b/t/Catmandu/Fix/Condition/marc_spec_has.t
similarity index 79%
rename from t/25-marc_spec_has.t
rename to t/Catmandu/Fix/Condition/marc_spec_has.t
index e10b543..19e0a2c 100644
--- a/t/25-marc_spec_has.t
+++ b/t/Catmandu/Fix/Condition/marc_spec_has.t
@@ -1,14 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Condition::marc_spec_has';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixes = <<EOF;
diff --git a/t/Catmandu/Fix/Inline/marc_add.t b/t/Catmandu/Fix/Inline/marc_add.t
new file mode 100644
index 0000000..e0a4b00
--- /dev/null
+++ b/t/Catmandu/Fix/Inline/marc_add.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Inline::marc_add';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Fix/Inline/marc_map.t b/t/Catmandu/Fix/Inline/marc_map.t
new file mode 100644
index 0000000..f72f186
--- /dev/null
+++ b/t/Catmandu/Fix/Inline/marc_map.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Inline::marc_map';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Fix/Inline/marc_remove.t b/t/Catmandu/Fix/Inline/marc_remove.t
new file mode 100644
index 0000000..54231fe
--- /dev/null
+++ b/t/Catmandu/Fix/Inline/marc_remove.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Inline::marc_remove';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Fix/Inline/marc_set.t b/t/Catmandu/Fix/Inline/marc_set.t
new file mode 100644
index 0000000..eb85665
--- /dev/null
+++ b/t/Catmandu/Fix/Inline/marc_set.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::Inline::marc_set';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/09-marc_add.t b/t/Catmandu/Fix/marc_add.t
similarity index 93%
rename from t/09-marc_add.t
rename to t/Catmandu/Fix/marc_add.t
index fa8abc2..a761188 100644
--- a/t/09-marc_add.t
+++ b/t/Catmandu/Fix/marc_add.t
@@ -1,14 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_add';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => [
q|add_field(my.deep.field,foo)|,
@@ -44,5 +51,4 @@ is $record->{record}->[2]->[6] , 'green', 'created 997 subfield a value';
is $record->{record}->[2]->[7] , 'a', 'created 997 subfield a';
is $record->{record}->[2]->[8] , 'blue', 'created 997 subfield a value';
-done_testing 20;
-
+done_testing;
diff --git a/t/Catmandu/Fix/marc_append.t b/t/Catmandu/Fix/marc_append.t
new file mode 100644
index 0000000..735fd44
--- /dev/null
+++ b/t/Catmandu/Fix/marc_append.t
@@ -0,0 +1,25 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Catmandu::Importer::MARC;
+use Catmandu::Fix;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_append';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+my $fixer = Catmandu::Fix->new(fixes => [q|marc_append('100','.')|,q|marc_map('100','test')|]);
+my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
+my $record = $fixer->fix($importer->first);
+
+like $record->{test}, qr/^Martinsson, Tobias,1976-\.$/, q|fix: marc_append('100','.')|;
+
+done_testing;
diff --git a/t/26-marc_copy.t b/t/Catmandu/Fix/marc_copy.t
similarity index 98%
rename from t/26-marc_copy.t
rename to t/Catmandu/Fix/marc_copy.t
index 7e04464..1fcdfb7 100644
--- a/t/26-marc_copy.t
+++ b/t/Catmandu/Fix/marc_copy.t
@@ -1,10 +1,20 @@
+#!perl
+
use strict;
use warnings;
use Test::More;
use Test::Exception;
-use Test::Warn;
use Catmandu;
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_copy';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
my $mrc = <<'MRC';
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
@@ -211,5 +221,4 @@ note 'marc_copy(...,all)';
], 'marc_copy(...,all)';
}
-
done_testing;
diff --git a/t/30-marc_cut.t b/t/Catmandu/Fix/marc_cut.t
similarity index 98%
rename from t/30-marc_cut.t
rename to t/Catmandu/Fix/marc_cut.t
index 12aae35..e0cad51 100644
--- a/t/30-marc_cut.t
+++ b/t/Catmandu/Fix/marc_cut.t
@@ -1,10 +1,20 @@
+#!perl
+
use strict;
use warnings;
use Test::More;
use Test::Exception;
-use Test::Warn;
use Catmandu;
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_cut';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
my $mrc = <<'MRC';
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
diff --git a/t/14-marc_decode_dollar_subfields.t b/t/Catmandu/Fix/marc_decode_dollar_subfields.t
similarity index 78%
rename from t/14-marc_decode_dollar_subfields.t
rename to t/Catmandu/Fix/marc_decode_dollar_subfields.t
index 7635a92..90abf69 100644
--- a/t/14-marc_decode_dollar_subfields.t
+++ b/t/Catmandu/Fix/marc_decode_dollar_subfields.t
@@ -1,14 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_decode_dollar_subfields';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => [
q|marc_decode_dollar_subfields()|,
@@ -21,4 +28,4 @@ my $record = $fixer->fix($importer->first);
like $record->{test}, qr/: Ermoupolis, Syros Island, Greece/, q|fix: marc_decode_dollar_subfields()|;
-done_testing 1;
+done_testing;
diff --git a/t/15-marc_in_json.t b/t/Catmandu/Fix/marc_in_json.t
similarity index 86%
rename from t/15-marc_in_json.t
rename to t/Catmandu/Fix/marc_in_json.t
index 31b6711..6d53306 100644
--- a/t/15-marc_in_json.t
+++ b/t/Catmandu/Fix/marc_in_json.t
@@ -1,31 +1,38 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
+use Test::Exception;
use Test::Deep;
-
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_in_json';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $record = {
record => [
['LDR', undef, undef, '_', '00000nas-a2200000z--4500'],
['001', undef, undef, undef, 'rec002'],
['008', undef, undef, '_' , '150519s----------------------000---eng-d'] ,
- ['100', '1', '1',
- '_', '' ,
+ ['100', '1', '1',
+ '_', '' ,
'a', 'Slayer'
],
['245', ' ', ' ',
- '_', '' ,
+ '_', '' ,
'a', 'Reign in Blood' ,
],
['999', ' ', ' ',
- '_', '' ,
+ '_', '' ,
'x', 'test' ,
'x', 'test2' ,
'x', 'test3' ,
@@ -52,4 +59,4 @@ my $record3 = $fixer2->fix($record2);
cmp_deeply($record,$record3);
-done_testing 11;
\ No newline at end of file
+done_testing;
diff --git a/t/03-marc_map.t b/t/Catmandu/Fix/marc_map.t
similarity index 95%
rename from t/03-marc_map.t
rename to t/Catmandu/Fix/marc_map.t
index 85c2bcc..208911f 100644
--- a/t/03-marc_map.t
+++ b/t/Catmandu/Fix/marc_map.t
@@ -1,14 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_map';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => ['t/test.fix']);
my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
diff --git a/t/29-marc_paste.t b/t/Catmandu/Fix/marc_paste.t
similarity index 96%
rename from t/29-marc_paste.t
rename to t/Catmandu/Fix/marc_paste.t
index 310e80b..d42b90e 100644
--- a/t/29-marc_paste.t
+++ b/t/Catmandu/Fix/marc_paste.t
@@ -1,10 +1,20 @@
+#!perl
+
use strict;
use warnings;
use Test::More;
use Test::Exception;
-use Test::Warn;
use Catmandu;
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_paste';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
my $mrc = <<'MRC';
<?xml version="1.0" encoding="UTF-8"?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
@@ -117,5 +127,4 @@ note 'marc_copy(001,cntrl); set_field(cntrl.0.tag,002); marc_paste(cntrl,at:245,
, 'marc_copy(001,cntrl)';
}
-
-done_testing();
+done_testing;
diff --git a/t/05-marc_remove.t b/t/Catmandu/Fix/marc_remove.t
similarity index 89%
rename from t/05-marc_remove.t
rename to t/Catmandu/Fix/marc_remove.t
index 8998894..2d46021 100644
--- a/t/05-marc_remove.t
+++ b/t/Catmandu/Fix/marc_remove.t
@@ -1,15 +1,22 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
use Catmandu::Fix::Inline::marc_map qw(:all);
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_remove';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => [
q|marc_remove('245')|,
@@ -45,4 +52,4 @@ ok (defined $dewey2, 'didnt delete dewey');
ok (!defined $lccn2, 'deleted lccn');
-done_testing 8;
+done_testing;
diff --git a/t/27-marc_replace_all.t b/t/Catmandu/Fix/marc_replace_all.t
similarity index 91%
rename from t/27-marc_replace_all.t
rename to t/Catmandu/Fix/marc_replace_all.t
index b12d076..bdfd86d 100644
--- a/t/27-marc_replace_all.t
+++ b/t/Catmandu/Fix/marc_replace_all.t
@@ -1,15 +1,20 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_replace_all';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
#---
{
@@ -45,5 +50,4 @@ use Catmandu::Fix;
], q|fix: marc_replace_all('630a','Active','{Active}')|;
}
-
done_testing;
diff --git a/t/12-marc_set.t b/t/Catmandu/Fix/marc_set.t
similarity index 91%
rename from t/12-marc_set.t
rename to t/Catmandu/Fix/marc_set.t
index 85ae949..c25acef 100644
--- a/t/12-marc_set.t
+++ b/t/Catmandu/Fix/marc_set.t
@@ -1,14 +1,21 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use warnings qw(FATAL utf8);
-use utf8;
-
use Test::More;
-
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_set';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => [q|marc_set('LDR/0-3','XXX')|,q|marc_map('LDR','leader')|]);
my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
@@ -47,5 +54,4 @@ like $record->{leader}, qr/^XXX/, q|fix: marc_set('LDR/0-3','XXX');|;
like $record->{test}, qr/^XXX$/, q|fix: marc_set('100[1]a','$.my.deep.field'');|;
}
-
-done_testing 4;
+done_testing;
diff --git a/t/21-marc-spec.t b/t/Catmandu/Fix/marc_spec.t
similarity index 97%
rename from t/21-marc-spec.t
rename to t/Catmandu/Fix/marc_spec.t
index dfeacfe..67127dd 100644
--- a/t/21-marc-spec.t
+++ b/t/Catmandu/Fix/marc_spec.t
@@ -1,10 +1,21 @@
-#!/usr/bin/perl
+#!perl
+
use strict;
-use warnings qw(FATAL utf8);
-use utf8;
+use warnings;
use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
use Catmandu::Fix;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_spec';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $fixer = Catmandu::Fix->new(fixes => ['t/marc_spec.fix']);
my $importer = Catmandu::Importer::MARC->new( file => 't/camel9.mrc', type => "ISO" );
@@ -22,7 +33,7 @@ is_deeply
[
'first',
'IMchF'
- ],
+ ],
q|fix: add_field(my.references2.$first, 'first'); marc_spec('003', my.references2.$append);|;
is $records->[0]->{my}{title}{all}, 'Cross-platform Perl /Eric F. Johnson.', q|fix: marc_spec('245', my.title.all);|;
@@ -151,5 +162,4 @@ is $records->[0]->{my}{multi}{level1}{inverted}, 'bleatherbigskinebinding', q|fi
is $records->[0]->{my}{nullvalue} , '0' , q|fix: marc_spec('008/0', my.nullvalue);|;
-
-done_testing;
\ No newline at end of file
+done_testing;
diff --git a/t/Catmandu/Fix/marc_xml.t b/t/Catmandu/Fix/marc_xml.t
new file mode 100644
index 0000000..ae74175
--- /dev/null
+++ b/t/Catmandu/Fix/marc_xml.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Fix::marc_xml';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/Catmandu/Importer/MARC.t b/t/Catmandu/Importer/MARC.t
new file mode 100644
index 0000000..c4e58a4
--- /dev/null
+++ b/t/Catmandu/Importer/MARC.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/02-aleph.t b/t/Catmandu/Importer/MARC/ALEPHSEQ.t
similarity index 62%
rename from t/02-aleph.t
rename to t/Catmandu/Importer/MARC/ALEPHSEQ.t
index 7d8327a..6a33f02 100644
--- a/t/02-aleph.t
+++ b/t/Catmandu/Importer/MARC/ALEPHSEQ.t
@@ -1,13 +1,24 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
-use Test::Simple tests => 3;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::ALEPHSEQ';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $importer = Catmandu::Importer::MARC->new( file => 't/rug01.aleph', type => "ALEPHSEQ" );
+ok $importer , 'got an MARC/ALEPHSEQ importer';
+
my @records;
my $n = $importer->each(
@@ -22,4 +33,4 @@ ok($records[0]->{record}->[1]->[0] eq 'LDR');
ok($records[0]->{record}->[1]->[-1] !~ /\^/);
-1;
+done_testing;
diff --git a/t/Catmandu/Importer/MARC/Decoder.t b/t/Catmandu/Importer/MARC/Decoder.t
new file mode 100644
index 0000000..6c620e3
--- /dev/null
+++ b/t/Catmandu/Importer/MARC/Decoder.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::Decoder';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/19-io-string.t b/t/Catmandu/Importer/MARC/ISO.t
similarity index 88%
rename from t/19-io-string.t
rename to t/Catmandu/Importer/MARC/ISO.t
index a791387..1426dc7 100644
--- a/t/19-io-string.t
+++ b/t/Catmandu/Importer/MARC/ISO.t
@@ -1,18 +1,27 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
-use MARC::File::USMARC;
-use Test::Simple tests => 4;
-my $data = join("",<DATA>);
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::ISO';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $importer = Catmandu::Importer::MARC->new(
- file => \$data,
+ file => 't/camel.mrc',
type => "ISO"
);
+
+ok $importer , 'got an MARC/ISO importer';
+
my $records = $importer->to_array();
ok( @$records == 10, 'got all records' );
@@ -21,5 +30,31 @@ ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
'_id matches record id' );
+# Test that the ID can be formed like '260c' (not a useful field in real life!)
+$importer = Catmandu::Importer::MARC->new(
+ file => 't/camel.mrc',
+ type => "ISO",
+ id => '260c',
+);
+$records = $importer->to_array();
+ok( $records->[0]->{'_id'} eq '2000.', 'got _id from subfield' );
+
+# Test inlines
+my $data = join("",<DATA>);
+
+$importer = Catmandu::Importer::MARC->new(
+ file => \$data,
+ type => "ISO"
+);
+$records = $importer->to_array();
+
+ok( @$records == 10, 'got all records' );
+ok( $records->[0]->{'_id'} eq 'fol05731351 ', 'got _id' );
+ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
+ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
+ '_id matches record id' );
+
+done_testing;
+
__DATA__
00755cam 22002414a 4500001001300000003000600013005001700019008004100036010001700077020004300094040001800137042000800155050002600163082001700189100003100206245005400237260004200291300007200333500003300405650003700438630002500475630001300500
fol05731351
IMchF
20000613133448.0
000107s2000 nyua 001 0 eng
a 00020737
a0471383147 (paper/cd-rom : alk. paper)
aDLCcDLCdDLC
apcc
00aQA76.73.P22bM33 2000
00a005.13/3221
1 aMartinsson, Tobias,d1976-
10aActivePerl [...]
diff --git a/t/Catmandu/Importer/MARC/Lint.t b/t/Catmandu/Importer/MARC/Lint.t
new file mode 100644
index 0000000..f39b92a
--- /dev/null
+++ b/t/Catmandu/Importer/MARC/Lint.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::Lint';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/10-marcmaker.t b/t/Catmandu/Importer/MARC/MARCMaker.t
similarity index 60%
rename from t/10-marcmaker.t
rename to t/Catmandu/Importer/MARC/MARCMaker.t
index 5a843c9..176c6b5 100644
--- a/t/10-marcmaker.t
+++ b/t/Catmandu/Importer/MARC/MARCMaker.t
@@ -1,14 +1,24 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use utf8;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
-use Test::More tests => 3;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::MARCMaker';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $importer = Catmandu::Importer::MARC->new(file => 't/camel.mrk', type => 'MARCMaker');
+ok $importer , 'got an MARC/MARCMaker importer';
+
my $records = $importer->to_array;
ok(@$records == 10);
@@ -17,4 +27,4 @@ is($records->[0]->{record}->[1]->[4] , 'fol05731351 ');
is($records->[0]->{record}->[11]->[4] , 'Martinsson, Tobias,');
-1;
\ No newline at end of file
+done_testing;
diff --git a/t/11-mij.t b/t/Catmandu/Importer/MARC/MiJ.t
similarity index 61%
rename from t/11-mij.t
rename to t/Catmandu/Importer/MARC/MiJ.t
index 1ea9804..72ba259 100644
--- a/t/11-mij.t
+++ b/t/Catmandu/Importer/MARC/MiJ.t
@@ -1,14 +1,24 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-use utf8;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
-use Test::More tests => 3;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::MiJ';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $importer = Catmandu::Importer::MARC->new(file => 't/test.ndj', type => 'MiJ');
+ok $importer , 'got an MARC/MiJ importer';
+
my $records = $importer->to_array;
ok(@$records == 9);
@@ -17,4 +27,4 @@ is($records->[0]->{record}->[1]->[4] , '000000040');
is($records->[0]->{record}->[13]->[4] , 'Pevsner, Nikolaus,');
-1;
\ No newline at end of file
+done_testing;
diff --git a/t/17-microlif.t b/t/Catmandu/Importer/MARC/MicroLIF.t
similarity index 59%
rename from t/17-microlif.t
rename to t/Catmandu/Importer/MARC/MicroLIF.t
index d315a58..e955024 100644
--- a/t/17-microlif.t
+++ b/t/Catmandu/Importer/MARC/MicroLIF.t
@@ -1,13 +1,24 @@
-#!/usr/bin/perl
+#!perl
use strict;
use warnings;
-
+use Test::More;
+use Test::Exception;
use Catmandu::Importer::MARC;
-use Test::Simple tests => 2;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::MicroLIF';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
my $importer = Catmandu::Importer::MARC->new( file => 't/sample1.lif', type => "MicroLIF" );
+ok $importer , 'got an MARC/MicroLIF importer';
+
my @records;
my $n = $importer->each(
@@ -20,4 +31,4 @@ ok(@records == 1);
ok($records[0]->{record}->[1]->[0] eq '008');
-1;
+done_testing;
diff --git a/t/Catmandu/Importer/MARC/RAW.t b/t/Catmandu/Importer/MARC/RAW.t
new file mode 100644
index 0000000..0c62668
--- /dev/null
+++ b/t/Catmandu/Importer/MARC/RAW.t
@@ -0,0 +1,32 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Catmandu::Importer::MARC;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::RAW';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+my $importer = Catmandu::Importer::MARC->new(
+ file => 't/dollar_subfields.mrc',
+ type => "RAW"
+);
+
+ok $importer , 'got an MARC/RAW importer';
+
+my $records = $importer->to_array();
+
+ok( @$records == 2, 'got all records' );
+is( $records->[0]->{'_id'} , '12162', 'got _id' );
+
+
+done_testing;
diff --git a/t/Catmandu/Importer/MARC/Record.t b/t/Catmandu/Importer/MARC/Record.t
new file mode 100644
index 0000000..e08c8c4
--- /dev/null
+++ b/t/Catmandu/Importer/MARC/Record.t
@@ -0,0 +1,39 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use MARC::File::USMARC;
+use Catmandu::Importer::MARC;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::Record';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+my $file = MARC::File::USMARC->in('t/camel.mrc');
+my @marc_objects;
+while ( my $marc = $file->next() ) {
+ push( @marc_objects, $marc );
+}
+$file->close();
+undef $file;
+
+my $importer = Catmandu::Importer::MARC->new(type => 'Record' , records => \@marc_objects );
+
+ok $importer , 'got an MARC/Record importer';
+
+my $records = $importer->to_array();
+
+ok( @$records == 10, 'got all records' );
+ok( $records->[0]->{'_id'} eq 'fol05731351 ', 'got _id' );
+ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
+ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
+ '_id matches record id' );
+
+done_testing;
diff --git a/t/Catmandu/Importer/MARC/XML.t b/t/Catmandu/Importer/MARC/XML.t
new file mode 100644
index 0000000..2064a5f
--- /dev/null
+++ b/t/Catmandu/Importer/MARC/XML.t
@@ -0,0 +1,44 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Catmandu::Importer::MARC;
+use utf8;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::Importer::MARC::XML';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+my $importer = Catmandu::Importer::MARC->new(file => 't/marc.xml', type => 'XML');
+
+ok $importer , 'got an MARC/XML importer';
+
+my $records = $importer->to_array;
+
+ok(@$records == 1);
+
+is($records->[0]->{record}->[1]->[0] , '920');
+
+is($records->[0]->{record}->[8]->[4] , 'TEEM (한국전기전자재료학회)');
+
+# Test broken records
+$importer = Catmandu::Importer::MARC->new(
+ file => 't/broken.xml',
+ type => "XML",
+ skip_errors => 1,
+);
+
+ok $importer , 'got an MARC/XML importer';
+
+$records = $importer->to_array();
+
+ok (@$records == 9, 'skipped one record');
+
+done_testing;
diff --git a/t/Catmandu/MARC.t b/t/Catmandu/MARC.t
new file mode 100644
index 0000000..a44c7e0
--- /dev/null
+++ b/t/Catmandu/MARC.t
@@ -0,0 +1,17 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+my $pkg;
+
+BEGIN {
+ $pkg = 'Catmandu::MARC';
+ use_ok $pkg;
+}
+
+require_ok $pkg;
+
+done_testing;
diff --git a/t/99-deprecate.t b/t/deprecate.t
similarity index 100%
rename from t/99-deprecate.t
rename to t/deprecate.t
diff --git a/t/07-inline-fix.t b/t/inline-fix.t
similarity index 100%
rename from t/07-inline-fix.t
rename to t/inline-fix.t
diff --git a/t/18-inlineable.t b/t/inlineable.t
similarity index 100%
rename from t/18-inlineable.t
rename to t/inlineable.t
diff --git a/t/22-mapping_rules.t b/t/mapping_rules.t
similarity index 100%
rename from t/22-mapping_rules.t
rename to t/mapping_rules.t
diff --git a/t/23-mapping_rules_spec.t b/t/mapping_rules_spec.t
similarity index 100%
rename from t/23-mapping_rules_spec.t
rename to t/mapping_rules_spec.t
diff --git a/t/24-marc-spec-subspecs.t b/t/marc-spec-subspecs.t
similarity index 100%
rename from t/24-marc-spec-subspecs.t
rename to t/marc-spec-subspecs.t
diff --git a/t/06-old-new-internal-syntax.t b/t/old-new-internal-syntax.t
similarity index 100%
rename from t/06-old-new-internal-syntax.t
rename to t/old-new-internal-syntax.t
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git
More information about the Pkg-perl-cvs-commits
mailing list