--- trunk/t/2-input.t 2007/02/04 12:20:54 794 +++ trunk/t/2-input.t 2007/02/04 13:28:30 797 @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 104; +use Test::More tests => 108; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -11,6 +11,7 @@ BEGIN { use_ok( 'WebPAC::Input::ISIS' ); use_ok( 'WebPAC::Input::MARC' ); +use_ok( 'WebPAC::Input::Test' ); } my $debug = shift @ARGV; @@ -119,10 +120,24 @@ test_fetch($input, $input->size); # test modify_record -$module = 'WebPAC::Input::ISIS'; -ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); +$module = 'WebPAC::Input::Test'; +ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, debug => $debug ), "new $module"); + +$WebPAC::Input::Test::rec = { + '200' => [ + { 'a' => '[200 a]', 'b' => '[200 b]', 'c' => '[200 c]', 'f' => '[200 f] test : test' }, + ], + '900' => [ + { 'x' => 'foobar', }, + ], +}; + +$WebPAC::Input::Test::size = 42; ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)"); + +cmp_ok($input->size, '==', 42, 'size'); + ok(my $rec_p = $input->fetch, 'fetch'); # modify_records @@ -137,33 +152,16 @@ }, ), "open modify_isis (with modify_records)"); -ok(my $rec = $input->fetch, 'fetch'); -diag "fetched rec field 200 = ", dump($rec->{200}) if ($debug); - -cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working'); - -diag "input = ",dump($input->{data}) if ($debug); - -# break encapsulation, bad! bad! -$input->{ll_db}->{_isis_db}->{record} = { - 900 => 'foo ; bar ; baz', -}; - -$input->{modify_record} = { - 900 => { - '*' => [ - { ' ; ' => 'a' }, - { ' ; ' => 'b' }, - { ' ; ' => 'c' }, - ], - } -}; - -diag "hacked: ",dump($input, $input->fetch) if ($debug); - # seek -throws_ok { $input->seek } qw/without/, 'seek without position'; +throws_ok { $input->seek } qr/without/, 'seek without position'; cmp_ok($input->seek(0), '==', -1, 'seek'); -ok(my $rec = $input->fetch, 'fetch'); -diag "fetched rec = ", dump($rec) if ($debug); +my $f = $WebPAC::Input::Test::filter_coderef; +ok(ref($f) eq 'CODE', 'filter_coderef'); + +cmp_ok( + $f->( '^afoo^cbar^fbing : bong', 200), + 'eq', '^afoo. bar^fbing / bong', + 'modify 200' +); +