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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 949 - (show annotations)
Thu Nov 1 00:16:48 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2531 byte(s)
 r1433@llin:  dpavlin | 2007-10-31 22:48:02 +0100
 HUGE swiping changes to implement new testing architecture
 based on all new WebPAC::Test module which makes
 test writing a joy

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26