[libcatmandu-marc-perl] 112/208: more marc_spec rule tests

Jonas Smedegaard dr at jones.dk
Sat Oct 28 03:42:42 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 99c88bb41bf23bf97818e5f5bd87c211a2a8cf4a
Author: Carsten Klee <cKlee at users.noreply.github.com>
Date:   Thu Mar 2 16:23:11 2017 +0100

    more marc_spec rule tests
---
 lib/Catmandu/MARC.pm      |   4 +-
 t/23-mapping_rules_spec.t | 170 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/lib/Catmandu/MARC.pm b/lib/Catmandu/MARC.pm
index 2e2e517..0d1437d 100644
--- a/lib/Catmandu/MARC.pm
+++ b/lib/Catmandu/MARC.pm
@@ -470,10 +470,10 @@ sub marc_spec {
                 }
 
                 if ( $invert_level == 3 ) {
-                    if (@subfield) { push @subfields, @subfield }
+                    if (@subfield) { push @sf_results, @subfield }
 
                     # return $value_set ASAP
-                    if ( @subfields && $value_set ) {
+                    if ( @sf_results && $value_set ) {
                         return $value_set;
                     }
                     next;
diff --git a/t/23-mapping_rules_spec.t b/t/23-mapping_rules_spec.t
index 9ce6257..858c089 100644
--- a/t/23-mapping_rules_spec.t
+++ b/t/23-mapping_rules_spec.t
@@ -128,6 +128,18 @@ note 'marc_spec(500$a,note)     note: "ABC"';
     is_deeply $record->{note}, 'ABC', 'marc_spec(500$a,note)';
 }
 
+note 'marc_spec(500$a,note, invert:1)     note: "D"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(500$a,note,invert:1); retain_field(note)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{note}, 'D', 'marc_spec(500$a,note,invert:1)';
+}
+
 note 'marc_spec(500,note.$append)  note: [ "ABCD" ]';
 {
     my $importer = Catmandu->importer(
@@ -152,6 +164,18 @@ note 'marc_spec(500$a,note.$append)     note: [ "ABC" ]';
     is_deeply $record->{note}, ['ABC'], ' marc_spec(500$a,note.$append)';
 }
 
+note 'marc_spec(500$a,note.$append, invert:1)     note: [ "D" ]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(500$a,note.$append,invert:1); retain_field(note)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{note}, ['D'], 'marc_spec(500$a,note.$append,invert:1)';
+}
+
 note 'marc_spec(500,note, split:1)     note: [ "A" , "B" , "C" , "D" ]';
 {
     my $importer = Catmandu->importer(
@@ -164,6 +188,18 @@ note 'marc_spec(500,note, split:1)     note: [ "A" , "B" , "C" , "D" ]';
     is_deeply $record->{note}, [ 'A', 'B', 'C', 'D' ], 'marc_spec(500,note, split:1)';
 }
 
+note 'marc_spec(500$x,note, split:1, invert:1)     note: [ "A" , "B" , "C"]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(500$x,note, split:1, invert:1); retain_field(note)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{note}, [ 'A', 'B', 'C' ], 'marc_spec(500$x,note, split:1, invert:1)';
+}
+
 note 'marc_spec(500$a,note, split:1)    note: [ "A" , "B" , "C" ]';
 {
     my $importer = Catmandu->importer(
@@ -195,6 +231,19 @@ note 'marc_spec(500$a,note.$append, split:1)    note : [[ "A" , "B" , "C" ]]';
         'marc_spec(500$a,note.$append, split:1)';
 }
 
+note 'marc_spec(500$x,note.$append, split:1, invert:1)    note : [[ "A" , "B" , "C" ]]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(500$x,note.$append, split:1, invert:1); retain_field(note)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{note}, [ [ 'A', 'B', 'C' ] ],
+        'marc_spec(500$x,note.$append, split:1, invert:1)';
+}
+
 note
     'marc_map(500a,note.$append, split:1, nested_arrays: 1)  note : [[[ "A" , "B" , "C" ]]]';
 {
@@ -225,6 +274,42 @@ note 'marc_spec(650$a,subject)  subject: "AlphaBetaGamma"';
     is_deeply $record->{subject}, 'AlphaBetaGamma', 'marc_spec(650$a,subject)';
 }
 
+note 'marc_spec(650[0]$a,subject)  subject: "Alpha"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(650[0]$a,subject) ; retain_field(subject)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{subject}, 'Alpha', 'marc_spec(650[0]$a,subject)';
+}
+
+note 'marc_spec(650$a/0,subject)  subject: "ABG"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(650$a/0,subject) ; retain_field(subject)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{subject}, 'ABG', 'marc_spec(650$a/0,subject)';
+}
+
+note 'marc_spec(650$a/#,subject,invert:1)  subject: "AlphBetGamm"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(650$a/#,subject,invert:1) ; retain_field(subject)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{subject}, 'AlphBetGamm', 'marc_spec(650$a/#,subject,invert:1)';
+}
+
 note 'marc_spec(650$a,subject.$append)  subject: [ "Alpha", "Beta" , "Gamma" ]';
 {
     my $importer = Catmandu->importer(
@@ -303,6 +388,42 @@ note 'marc_spec(999$a,local)    local: "XYZ"';
     is_deeply $record->{local}, 'XYZ', 'marc_spec(999$a,local)';
 }
 
+note 'marc_spec(999$a[0],local)    local: "XZ"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[0],local); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, 'XZ', 'marc_spec(999$a[0],local)';
+}
+
+note 'marc_spec(999$a[#],local)    local: "YZ"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[#],local); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, 'YZ', 'marc_spec(999$a[#],local)';
+}
+
+note 'marc_spec(999$a[#],local,invert:1)    local: "X"';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[#],local,invert:1); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, 'X', 'marc_spec(999$a[#],local,invert:1)';
+}
+
 note 'marc_spec(999$a,local.$append)    local: [ "XY", "Z" ]';
 {
     my $importer = Catmandu->importer(
@@ -315,6 +436,18 @@ note 'marc_spec(999$a,local.$append)    local: [ "XY", "Z" ]';
     is_deeply $record->{local}, [ 'XY', 'Z' ], 'marc_spec(999$a,local.$append)';
 }
 
+note 'marc_spec(999$a[0],local.$append)    local: [ "X", "Z" ]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[0],local.$append); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, [ 'X', 'Z' ], 'marc_spec(999$a[0],local.$append)';
+}
+
 note 'marc_spec(999$a,local, split:1)   local: [ "X" , "Y", "Z" ]';
 {
     my $importer = Catmandu->importer(
@@ -327,6 +460,30 @@ note 'marc_spec(999$a,local, split:1)   local: [ "X" , "Y", "Z" ]';
     is_deeply $record->{local}, [ 'X', 'Y', 'Z' ], 'marc_spec(999$a,local, split:1)';
 }
 
+note 'marc_spec(999$a[0],local, split:1)   local: [ "X" , "Z" ]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[0],local, split:1); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, [ 'X', 'Z' ], 'marc_spec(999$a[0],local, split:1)';
+}
+
+note 'marc_spec(999$a[0],local, split:1, invert:1)   local: [ "Y" ]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[0],local, split:1, invert:1); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, [ 'Y' ], 'marc_spec(999$a[0],local, split:1, invert:1)';
+}
+
 note 'marc_spec(999$a,local.$append, split:1)   local: [[ "X" , "Y", "Z" ]]';
 {
     my $importer = Catmandu->importer(
@@ -340,6 +497,19 @@ note 'marc_spec(999$a,local.$append, split:1)   local: [[ "X" , "Y", "Z" ]]';
         'marc_spec(999$a,local.$append, split:1)';
 }
 
+note 'marc_spec(999$a[0],local.$append, split:1)   local: [[ "X" , "Z" ]]';
+{
+    my $importer = Catmandu->importer(
+        'MARC',
+        file => \$mrc,
+        type => 'XML',
+        fix  => 'marc_spec(999$a[0],local.$append, split:1); retain_field(local)'
+    );
+    my $record = $importer->first;
+    is_deeply $record->{local}, [ [ 'X', 'Z' ] ],
+        'marc_spec(999$a[0],local.$append, split:1)';
+}
+
 note
     'marc_spec(999$a,local, split:1, nested_arrays:1)  local: [ ["X" , "Y"] , ["Z"] ]';
 {

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