/[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 835 - (hide annotations)
Thu May 24 10:53:50 2007 UTC (17 years ago) by dpavlin
File MIME type: application/x-troff
File size: 1754 byte(s)
 r1228@llin:  dpavlin | 2007-05-24 12:53:57 +0200
 report invalid delimiter combinations

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26