/[webpac2]/trunk/t/3-normalize-xml.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/3-normalize-xml.t

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

revision 315 by dpavlin, Fri Dec 23 21:17:37 2005 UTC revision 352 by dpavlin, Sat Jan 7 18:23:27 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 76;  use Test::More tests => 84;
4  use Test::Exception;  use Test::Exception;
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use blib;  use blib;
# Line 13  use_ok( 'WebPAC::Normalize::XML' ); Line 13  use_ok( 'WebPAC::Normalize::XML' );
13    
14  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
15  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
16  diag "abs_path: $abs_path";  #diag "abs_path: $abs_path";
17    
18  throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup";  throws_ok { new WebPAC::Normalize::XML( lookup_regex => 'foo' ) } qr/pair/, "lookup_regex without lookup";
19  throws_ok { new WebPAC::Normalize::XML( lookup => 'bar' ) } qr/pair/, "lookup without lookup_regex";  throws_ok { new WebPAC::Normalize::XML( lookup => 'bar' ) } qr/pair/, "lookup without lookup_regex";
20    
21  ok(my $n = new WebPAC::Normalize::XML(  ok(my $n = new WebPAC::Normalize::XML(
22          debug => 1,          debug => 0,
23          filter => {          filter => {
24                  regex => sub {                  regex => sub {
25                          my ($val, $regex) = @_;                          my ($val, $regex) = @_;
# Line 153  $rec = { Line 153  $rec = {
153                  'a' => '1',                  'a' => '1',
154                  'b' => '2',                  'b' => '2',
155                  'c' => '3',                  'c' => '3',
156                  'txt' => 'yap',                  'x' => 'yap',
157          } ],          } ],
158  };  };
159    
160  my $import = {  my $import = {
161          'Tag' => { 'isis' => [          'Tag' => { 'isis' => [
162                          { content => 'v900^a + v900^b = v900^c [txt]' },                          { content => 'v900^a + v900^b = v900^c [v900^x]' },
163          ] },          ] },
164  };  };
165    
# Line 169  sub parse_test($$$) { Line 169  sub parse_test($$$) {
169          # erase internal cache (yak!)          # erase internal cache (yak!)
170          delete($n->{tags_by_order});          delete($n->{tags_by_order});
171          push @{$rec->{'000'}}, 42 unless ($rec->{'000'});          push @{$rec->{'000'}}, 42 unless ($rec->{'000'});
172          diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec);          #diag "test normalisation of: ",Dumper($n->{import_xml}->{indexer}, $rec);
173          ok(my $ds = $n->data_structure( $rec ), "data_structure");          ok(my $ds = $n->data_structure( $rec ), "data_structure");
174          diag Dumper($ds);          #diag Dumper($ds);
175          cmp_ok($ds->{Tag}->{display}->[0], 'eq', $r, "parse $r");          cmp_ok($ds->{Tag}->{display}->[0], 'eq', $r, "parse $r");
176  }  }
177    
# Line 185  $rec->{'900'}->[0]->{'c'} = 6; Line 185  $rec->{'900'}->[0]->{'c'} = 6;
185  parse_test($import, $rec, '1 + 5 = 6 [yap]');  parse_test($import, $rec, '1 + 5 = 6 [yap]');
186    
187  delete($rec->{'900'}->[0]->{'c'});  delete($rec->{'900'}->[0]->{'c'});
188  parse_test($import, $rec, '1 + 5');  $rec->{'900'}->[0]->{'x'} = 'hmmm';
189    parse_test($import, $rec, '1 + 5 [hmmm]');
190    
191  $rec->{'900'}->[0]->{'txt'} = 'nope!';  $rec->{'900'}->[0]->{'x'} = 'nope!';
192  delete($rec->{'900'}->[0]->{'a'});  delete($rec->{'900'}->[0]->{'a'});
193  parse_test($import, $rec, '5 [nope!]');  parse_test($import, $rec, '5 [nope!]');
194    

Legend:
Removed from v.315  
changed lines
  Added in v.352

  ViewVC Help
Powered by ViewVC 1.1.26