[libcatmandu-marc-perl] 06/26: More alephseq tests

Jonas Smedegaard dr at jones.dk
Tue Dec 19 12:17:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag upstream/1.23.1
in repository libcatmandu-marc-perl.

commit 66ebdd77d4299b9fad0dbdf883aeedccdd681d8e
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Fri Nov 10 10:49:10 2017 +0100

    More alephseq tests
---
 t/Catmandu/Exporter/MARC/ALEPHSEQ.t | 157 ++++++++++++++++++++++++------------
 1 file changed, 106 insertions(+), 51 deletions(-)

diff --git a/t/Catmandu/Exporter/MARC/ALEPHSEQ.t b/t/Catmandu/Exporter/MARC/ALEPHSEQ.t
index 2d9ad59..6bd575e 100644
--- a/t/Catmandu/Exporter/MARC/ALEPHSEQ.t
+++ b/t/Catmandu/Exporter/MARC/ALEPHSEQ.t
@@ -5,6 +5,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use Catmandu::Exporter::MARC;
+use utf8;
 
 my $pkg;
 
@@ -15,60 +16,114 @@ BEGIN {
 
 require_ok $pkg;
 
-my $alephseq = undef;
+note("catmandu marc export");
+{
+    my $alephseq = undef;
 
-my $exporter = Catmandu::Exporter::MARC->new(file => \$alephseq, type=> 'ALEPHSEQ' , skip_empty_subfields => 1);
+    my $record = {
+        _id => '000000002',
+        record => [
+          [ 'FMT', ' ', ' ' , '_', 'BK' ] ,
+          [ 'LDR', ' ', ' ' , '_', '00000nam a2200301 i 4500' ] ,
+          [ '001', ' ', ' ' , '_', '000000002' ] ,
+          [ '245', '1', '0' , 'a', 'Catmandu Test' ] ,
+          [ '650', ' ', '0' , 'a', 'Perl' ] ,
+          [ '650', ' ', '0' , 'a', 'MARC' , 'a' , 'MARC2' ] ,
+          [ '650', ' ', '0' , 'a', '加德滿都' ] ,
+        ]
+    };
+
+    my $expected =<<'EOF';
+000000002 FMT   L BK
+000000002 LDR   L 00000nam^a2200301^i^4500
+000000002 001   L 000000002
+000000002 24510 L $$aCatmandu Test
+000000002 650 0 L $$aPerl
+000000002 650 0 L $$aMARC$$aMARC2
+000000002 650 0 L $$a加德滿都
+EOF
+
+    my $exporter = Catmandu::Exporter::MARC->new(file => \$alephseq, type=> 'ALEPHSEQ' , skip_empty_subfields => 1);
+
+    ok $exporter , 'got an MARC/ALEPHSEQ exporter';
+
+    ok $exporter->add($record) , 'add a record';
+
+    ok $exporter->commit , 'commit';
+
+    is_deeply $alephseq , $expected , 'got expected results';
+}
 
-ok $exporter , 'got an MARC/ALEPHSEQ exporter';
+note("marc-in-json export");
+{
+    my $alephseq ;
 
-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', ''],
+
+    my $exporter = Catmandu::Exporter::MARC->new(
+                      file => \$alephseq,
+                      type=> 'ALEPHSEQ',
+                      record_format => 'MARC-in-JSON',
+                      skip_empty_subfields => 1
+    );
+
+    ok($exporter, "create exporter ALEPHSEQ for MARC-in-JSON");
+
+    my $record = {
+        _id => '000000002',
+        leader => "00000nam a2200301 i 4500" ,
+        fields => [
+            { '001'  => '000000002' } ,
+            { '245'  => {
+                    ind1 => '1' ,
+                    ind2 => '0' ,
+                    subfields => [
+                        { a => 'Catmandu Test'}
+                    ]
+                }
+            } ,
+            { '650'  => {
+                    ind1 => ' ' ,
+                    ind2 => '0' ,
+                    subfields => [
+                        { a => 'Perl'}
+                    ]
+                }
+            } ,
+            { '650'  => {
+                    ind1 => ' ' ,
+                    ind2 => '0' ,
+                    subfields => [
+                        { a => 'MARC'} ,
+                        { a => 'MARC2'}
+                    ]
+                }
+            } ,
+            { '650'  => {
+                    ind1 => ' ' ,
+                    ind2 => '0' ,
+                    subfields => [
+                        { a => '加德滿都'}
+                    ]
+                }
+            } ,
         ]
-});
-
-ok $exporter->commit;
-
-ok($alephseq =~ /^000000001/, 'test id');
-ok($alephseq =~ /000000001 100   L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
-ok($alephseq !~ /000000001 500/, 'test skip empty subfields');
-
-$alephseq = '';
-$exporter = Catmandu::Exporter::MARC->new(
-                  file => \$alephseq,
-                  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($alephseq =~ /^000000001/, 'test id');
-ok($alephseq =~ /000000001 100   L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
-ok($alephseq !~ /000000001 500/, 'test skip empty subfields');
-ok($alephseq =~ /000000001 540   L \$\$aabcd/, 'test skip newlines');
+    };
+
+    my $expected =<<'EOF';
+000000002 FMT   L BK
+000000002 LDR   L 00000nam^a2200301^i^4500
+000000002 001   L 000000002
+000000002 24510 L $$aCatmandu Test
+000000002 650 0 L $$aPerl
+000000002 650 0 L $$aMARC$$aMARC2
+000000002 650 0 L $$a加德滿都
+EOF
+
+    ok $exporter->add($record), 'add record';
+
+    ok $exporter->commit() , 'commit';
+
+    is_deeply $alephseq , $expected , 'got expected results';
+}
 
 done_testing;

-- 
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