/[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

Annotation of /trunk/t/1-validate-delimiters.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 837 - (hide annotations)
Thu May 24 12:44:45 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2154 byte(s)
 r1232@llin:  dpavlin | 2007-05-24 14:44:53 +0200
 added storing and retriving of delimiters templates to file and some basic tests

1 dpavlin 827 #!/usr/bin/perl -w
2    
3     use strict;
4 dpavlin 837 use Test::More tests => 10;
5 dpavlin 827 use Test::Exception;
6     use blib;
7    
8     use Data::Dump qw/dump/;
9     use Cwd qw/abs_path/;
10 dpavlin 837 use File::Temp qw/tempfile/;
11 dpavlin 827
12     BEGIN {
13     use_ok( 'WebPAC::Validate' );
14     }
15    
16     my $debug = shift @ARGV;
17    
18     ok(my $abs_path = abs_path($0), "abs_path");
19     $abs_path =~ s#/[^/]*$#/#;
20    
21 dpavlin 837 my ( $fh, $path ) = tempfile();
22    
23 dpavlin 827 ok(my $v = new WebPAC::Validate(
24     path => "$abs_path/data/validate_test",
25 dpavlin 828 delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],
26 dpavlin 837 delimiters_path => $path,
27 dpavlin 827 debug => $debug,
28     ), "new");
29    
30     diag "rules = ", dump( $v->{rules} );
31    
32     $v->{rules} = {};
33    
34     sub test_v {
35     my $row = shift || die "no row?";
36    
37     my $d = dump( $row );
38    
39     $row->{'000'} = [ 42 ];
40    
41     $v->reset_errors;
42     my $e = $v->validate_rec( $row );
43    
44     diag ">> validate $d\n",dump($e) if ($debug);
45     }
46    
47     test_v({
48 dpavlin 828 '900' => [
49     { 'a' => 'a : aa = aaa : a ; a', 'b' => 'b ; b ; b ; b ; a : / z . z . ' },
50     { 'a' => 'a : a : a', 'c' => [ 'a : b ; c', 'a : b ; c / d' ] },
51     { 'a' => 'a : b / c' },
52     { 'a' => 'a : b / c' },
53 dpavlin 829 ],
54     '901' => [
55     { 'a' => 'a : b / c', 'b' => 'foo' },
56     { 'a' => 'a : b / c', 'b' => 'foo' },
57     ],
58 dpavlin 827 });
59    
60     diag dump($v->{_delimiters_templates});
61    
62     is_deeply( $v->{_delimiters_templates}, {
63     900 => {
64 dpavlin 828 "^a : / " => 2,
65     "^a : : ^c : ; ^c : ; / " => 1,
66     "^a : = : ; ^b ; ; ; ; : . . " => 1,
67 dpavlin 827 },
68 dpavlin 829 901 => { "^a : / ^b" => 2 },
69 dpavlin 827 }, 'just subfields and delimiters');
70    
71 dpavlin 832 ok(my $dt = $v->delimiters_templates, 'delimiters_template');
72     diag $dt;
73 dpavlin 834
74     ok($dt = $v->delimiters_templates( report => 1 ), 'delimiters_template report');
75     diag $dt;
76 dpavlin 835
77     $v->{_validate_delimiters_templates} = {
78     900 => { '^a : ^b' => 1 },
79     };
80    
81     test_v({
82     '900' => [
83     { 'a' => 'foo : bar', 'b' => 'baz' },
84     { 'a' => 'foo', 'b' => 'baz' },
85     { 'a' => 'foo' },
86     { 'a' => 'foo : bar' },
87     ],
88     });
89    
90     ok (my $e = $v->report, 'report');
91    
92     diag $e;
93     diag dump( $v->{errors} );
94 dpavlin 837
95     ok( $v->save_delimiters_templates, 'save_delimiters_templates' );
96    
97     ok(my $v2 = new WebPAC::Validate(
98     delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],
99     delimiters_path => $path,
100     debug => $debug,
101     ), "new");
102    
103     is_deeply( $v->{_delimiters_templates}, $v2->{_validate_delimiters_templates}, 'save/load ok');

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26