/[webpac2]/trunk/t/2-input.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/2-input.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 797 by dpavlin, Sun Feb 4 13:28:30 2007 UTC revision 909 by dpavlin, Tue Oct 30 01:46:41 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 108;  use Test::More tests => 123;
4  use Test::Exception;  use Test::Exception;
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use blib;  use blib;
# Line 18  my $debug = shift @ARGV; Line 18  my $debug = shift @ARGV;
18  my $no_log = $debug ? 0 : 1;  my $no_log = $debug ? 0 : 1;
19    
20  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
21  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;      #vim
22    
23  my $module = 'WebPAC::Input::ISIS';  my $module = 'WebPAC::Input::ISIS';
24  diag "testing with $module";  diag "testing with $module";
25    
26  throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module";  throws_ok { my $input = new WebPAC::Input( no_log => $no_log ) } qr/module/, "need module";
27  ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module");  ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module");
28  ok(my $input_lm = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module");  ok(my $input_lm = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module");
29    
# Line 79  sub test_fetch($$) { Line 79  sub test_fetch($$) {
79                  cmp_ok($input->pos, '==', $mfn, "pos $mfn");                  cmp_ok($input->pos, '==', $mfn, "pos $mfn");
80                  push @db, $rec;                  push @db, $rec;
81                  ok(my $dump = $input->dump_ascii, "dump_ascii $mfn");                  ok(my $dump = $input->dump_ascii, "dump_ascii $mfn");
82                    # XXX test count will help us keep this test in-line :-)
83                    ok($rec->{leader}, "leader $mfn") if $rec->{leader};
84                  diag $dump if ($debug);                  diag $dump if ($debug);
85          }          }
86    
# Line 105  test_start_limit($input, $size, 3, 0); Line 107  test_start_limit($input, $size, 3, 0);
107  test_start_limit($input, 3, $size, $size - 2);  test_start_limit($input, 3, $size, $size - 2);
108  test_start_limit($input, 1, $size + 2, $size);  test_start_limit($input, 1, $size + 2, $size);
109    
110  ok(my $s = $input->stats, 'stats');  ok(my $s = $input->stats, "$module stats");
111  diag "stats:\n$s" if ($debug);  diag "stats:\n$s" if ($debug);
112    
113  $module = 'WebPAC::Input::MARC';  $module = 'WebPAC::Input::MARC';
114  diag "testing with $module";  diag "testing with $module";
115    
116  ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module");  ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module");
117    
118  ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso");  ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso");
119    
# Line 119  test_after_open($input); Line 121  test_after_open($input);
121    
122  test_fetch($input, $input->size);  test_fetch($input, $input->size);
123    
124    ok(my $s = $input->stats, "$module stats");
125    
126    diag "stats:\n$s" if ($debug);
127  # test modify_record  # test modify_record
128  $module = 'WebPAC::Input::Test';  $module = 'WebPAC::Input::Test';
129  ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, debug => $debug ), "new $module");  ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, debug => $debug ), "new $module");
# Line 134  $WebPAC::Input::Test::rec = { Line 139  $WebPAC::Input::Test::rec = {
139    
140  $WebPAC::Input::Test::size = 42;  $WebPAC::Input::Test::size = 42;
141    
142  ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)");  ok($input->open( path => "/fake/path", ), "open modify_isis (plain)");
143    
144  cmp_ok($input->size, '==', 42, 'size');  cmp_ok($input->size, '==', 42, 'size');
145    
# Line 143  ok(my $rec_p = $input->fetch, 'fetch'); Line 148  ok(my $rec_p = $input->fetch, 'fetch');
148  # modify_records  # modify_records
149    
150  ok($input->open(  ok($input->open(
151          path => "$abs_path/modify_isis/LIBRI",          path => "/another/fake/path",
152          modify_records => {          modify_records => {
153                  200 => {                  200 => {
154                          '*' => { '^c' => '. ' },                          '*' => { '^c' => '. ' },
155                          '^f' => { ' : ' => ' / ' },                          '^f' => { ' : ' => ' / ' },
156                  }                  }
157          },          },
158  ), "open modify_isis (with modify_records)");  ), "open (with modify_records)");
159    
160  # seek  # seek
161  throws_ok { $input->seek } qr/without/, 'seek without position';  throws_ok { $input->seek } qr/without/, 'seek without position';
162  cmp_ok($input->seek(0), '==', -1, 'seek');  cmp_ok($input->seek(0), '==', -1, 'seek');
163    
164  my $f = $WebPAC::Input::Test::filter_coderef;  sub test_filter {
165  ok(ref($f) eq 'CODE', 'filter_coderef');  
166            my $f = $WebPAC::Input::Test::filter_coderef;
167            ok(ref($f) eq 'CODE', 'filter_coderef');
168    
169            my ($field, $from, $to) = @_;
170            cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" );
171    }
172    
173    test_filter(200,
174            '^afoo^cbar^fbing : bong',
175            '^afoo. bar^fbing / bong',
176    );
177    
178    # modify_file
179    
180    my $modify_file = "$abs_path/conf/modify/test.pl";
181    
182    ok($input->open(
183            path => "/and/another/fake/path",
184            modify_file => $modify_file,
185    ), "open (with modify_file $modify_file)");
186    
187    diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug);
188    
189    test_filter(200,
190            '^a foo ; bar = baz : zzz',
191            '^a foo^kbar^dbaz : zzz',
192    );
193    
194    # empty subfield removal
195    
196    ok($input->open(
197            path => "/another/fake/path",
198            modify_records => {
199                    900 => {
200                            '^a' => { '^e' => ' : ^e' },
201                    },
202                    901 => {
203                            '^a' => { 'foo' => 'baz' },
204                    },
205            },
206    ), "open (with modify_records for empty subfields)");
207    
208  cmp_ok(  test_filter(900,
209          $f->(   '^afoo^cbar^fbing : bong',      200),          '^a^ebar',
210          'eq',   '^afoo. bar^fbing / bong',          '^a^ebar',
         'modify 200'  
211  );  );
212    
213    test_filter(900,
214            '^afoo^ebar',
215            '^afoo : ^ebar',
216    );
217    
218    test_filter(901,
219            '^afoo^ebar',
220            '^abaz^ebar',
221    );

Legend:
Removed from v.797  
changed lines
  Added in v.909

  ViewVC Help
Powered by ViewVC 1.1.26