r1249@llin: dpavlin | 2007-05-27 11:49:30 +0200
[webpac2] / t / 2-input.t
index 5ce5e73..19af3df 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::More tests => 111;
+use Test::More tests => 118;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;
@@ -134,7 +134,7 @@ $WebPAC::Input::Test::rec = {
 
 $WebPAC::Input::Test::size = 42;
 
-ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)");
+ok($input->open( path => "/fake/path", ), "open modify_isis (plain)");
 
 cmp_ok($input->size, '==', 42, 'size');
 
@@ -143,7 +143,7 @@ ok(my $rec_p = $input->fetch, 'fetch');
 # modify_records
 
 ok($input->open(
-       path => "$abs_path/modify_isis/LIBRI",
+       path => "/another/fake/path",
        modify_records => {
                200 => {
                        '*' => { '^c' => '. ' },
@@ -156,13 +156,18 @@ ok($input->open(
 throws_ok { $input->seek } qr/without/, 'seek without position';
 cmp_ok($input->seek(0), '==', -1, 'seek');
 
-my $f = $WebPAC::Input::Test::filter_coderef;
-ok(ref($f) eq 'CODE', 'filter_coderef');
+sub test_filter {
+
+       my $f = $WebPAC::Input::Test::filter_coderef;
+       ok(ref($f) eq 'CODE', 'filter_coderef');
+
+       my ($field, $from, $to) = @_;
+       cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" );
+}
 
-cmp_ok(
-       $f->(   '^afoo^cbar^fbing : bong',      200),
-       'eq',   '^afoo. bar^fbing / bong',
-       'modify 200'
+test_filter(200,
+       '^afoo^cbar^fbing : bong',
+       '^afoo. bar^fbing / bong',
 );
 
 # modify_file
@@ -170,22 +175,42 @@ cmp_ok(
 my $modify_file = "$abs_path/conf/modify/test.pl";
 
 ok($input->open(
-       path => "$abs_path/modify_isis/LIBRI",
+       path => "/and/another/fake/path",
        modify_file => $modify_file,
 ), "open (with modify_file $modify_file)");
 
-my $f = $WebPAC::Input::Test::filter_coderef;
-ok(ref($f) eq 'CODE', 'filter_coderef');
-
 diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug);
 
-sub test_filter {
-       my ($field, $from, $to) = @_;
-       cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" );
-}
-
 test_filter(200,
        '^a foo ; bar = baz : zzz',
        '^a foo^kbar^dbaz : zzz',
 );
 
+# empty subfield removal
+
+ok($input->open(
+       path => "/another/fake/path",
+       modify_records => {
+               900 => {
+                       '^a' => { '^e' => ' : ^e' },
+               },
+               901 => {
+                       '^a' => { 'foo' => 'baz' },
+               },
+       },
+), "open (with modify_records for empty subfields)");
+
+test_filter(900,
+       '^a^ebar',
+       '^a^ebar',
+);
+
+test_filter(900,
+       '^afoo^ebar',
+       '^afoo : ^ebar',
+);
+
+test_filter(901,
+       '^afoo^ebar',
+       '^abaz^ebar',
+);