/[webpac2]/trunk/t/1-validate-delimiters.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/1-validate-delimiters.t

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

revision 835 by dpavlin, Thu May 24 10:53:50 2007 UTC revision 851 by dpavlin, Sun May 27 11:14:40 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Test::More tests => 7;  use Test::More tests => 15;
5  use Test::Exception;  use Test::Exception;
6  use blib;  use blib;
7    
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
10    use File::Temp qw/ :POSIX /;
11    
12  BEGIN {  BEGIN {
13  use_ok( 'WebPAC::Validate' );  use_ok( 'WebPAC::Validate' );
# Line 17  my $debug = shift @ARGV; Line 18  my $debug = shift @ARGV;
18  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
19  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
20    
21    my $delimiters_path = tmpnam();
22    
23  ok(my $v = new WebPAC::Validate(  ok(my $v = new WebPAC::Validate(
24          path => "$abs_path/data/validate_test",          path => "$abs_path/data/validate_test",
25          delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],          delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],
26            delimiters_path => $delimiters_path,
27          debug => $debug,          debug => $debug,
28  ), "new");  ), "new");
29    
30  diag "rules = ", dump( $v->{rules} );  diag "rules = ", dump( $v->{rules} ) if ( $debug );
31    
32  $v->{rules} = {};  $v->{rules} = {};
33    
# Line 34  sub test_v { Line 38  sub test_v {
38    
39          $row->{'000'} = [ 42 ];          $row->{'000'} = [ 42 ];
40    
41          $v->reset_errors;          $v->reset;
42          my $e = $v->validate_rec( $row );          my $e = $v->validate_rec( $row );
43    
44          diag ">> validate $d\n",dump($e) if ($debug);          diag ">> validate $d\n",dump($e) if ($debug);
# Line 53  test_v({ Line 57  test_v({
57          ],          ],
58  });  });
59    
60  diag dump($v->{_delimiters_templates});  diag dump($v->{_delimiters_templates}) if ( $debug );
61    
62  is_deeply( $v->{_delimiters_templates}, {  is_deeply( $v->{_delimiters_templates}, {
63          900 => {          900 => {
# Line 64  is_deeply( $v->{_delimiters_templates}, Line 68  is_deeply( $v->{_delimiters_templates},
68          901 => { "^a :  / ^b" => 2 },          901 => { "^a :  / ^b" => 2 },
69  }, 'just subfields and delimiters');  }, 'just subfields and delimiters');
70    
71  ok(my $dt = $v->delimiters_templates, 'delimiters_template');  ok(! $v->delimiters_templates, 'no accumulated delimiters_template');
72  diag $dt;  
73    ok(my $dt = $v->delimiters_templates( current_input => 1 ), 'delimiters_template');
74    diag $dt if ( $debug );
75    
76  ok($dt = $v->delimiters_templates( report => 1 ), 'delimiters_template report');  ok($dt = $v->delimiters_templates( report => 1, current_input => 1 ), 'delimiters_template report');
77  diag $dt;  diag $dt if ( $debug );
78    
79    $v->reset;
80    ok( $v->delimiters_templates, 'have accumulated delimiters_templates');
81    
82  $v->{_validate_delimiters_templates} = {  $v->{_validate_delimiters_templates} = {
83          900 => { '^a : ^b' => 1 },          900 => { '^a : ^b' => 1 },
# Line 85  test_v({ Line 94  test_v({
94    
95  ok (my $e = $v->report, 'report');  ok (my $e = $v->report, 'report');
96    
97  diag $e;  diag $e if ( $debug );
98  diag dump( $v->{errors} );  
99    ok( $v->save_delimiters_templates, 'save_delimiters_templates' );
100    
101    ok( -s $delimiters_path, "$delimiters_path " . ( -s $delimiters_path ) . " bytes" );
102    
103    ok( $v->save_delimiters_templates, 'save_delimiters_templates to existing file' );
104    
105    ok( -s $delimiters_path . '.new' , "new file created" );
106    
107    ok(my $v2 = new WebPAC::Validate(
108            delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],
109            delimiters_path => $delimiters_path,
110            debug => $debug,
111    ), "new");
112    
113    is_deeply( $v->{_accumulated_delimiters_templates}, $v2->{_validate_delimiters_templates}, 'save/load ok');
114    
115    diag dump( $v, $v2 ) if ( $debug );

Legend:
Removed from v.835  
changed lines
  Added in v.851

  ViewVC Help
Powered by ViewVC 1.1.26