r1201@llin: dpavlin | 2007-04-11 13:54:24 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2007 12:22:33 +0000 (12:22 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2007 12:22:33 +0000 (12:22 +0000)
 refactor filter tests

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@821 07558da8-63fa-0310-ba24-9fe276d99e06

t/2-input.t

index 2cf9069..70eb385 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::More tests => 111;
+use Test::More tests => 116;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;
@@ -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
@@ -174,23 +179,30 @@ ok($input->open(
        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
-test_filter(901,
-       '^a^efoo',
-       '^efoo',
+
+ok($input->open(
+       path => "/another/fake/path",
+       modify_records => {
+               900 => {
+                       '^a' => { '^e' => ' : ^e' },
+               }
+       },
+), "open (with modify_records for empty subfields)");
+
+test_filter(900,
+       '^a^ebar',
+       '^a^ebar',
+);
+
+test_filter(900,
+       '^afoo^ebar',
+       '^afoo : ^ebar',
 );