r1213@llin: dpavlin | 2007-05-20 18:16:02 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 May 2007 16:19:17 +0000 (16:19 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 May 2007 16:19:17 +0000 (16:19 +0000)
 and fix to actually count right templates :-)

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@828 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Validate.pm
t/1-validate-delimiters.t

index dafe201..a8a5b87 100644 (file)
@@ -159,15 +159,14 @@ sub validate_rec {
                # first check delimiters
                if ( my $regex = $self->{delimiters_regex} ) {
 
-                       my $template = '';
-
                        foreach my $v (@{ $rec->{$f} }) {
                                        warn "## v = ", dump( $v );
                                        my $l = _pack_subfields_hash( $v, 1 );
                                        warn "## $l [$regex]\n";
+                                       my $template = '';
                                        $l =~ s/$regex/$template.=$1/eg && warn "## new: $l\n";
                                        warn "## template: $template\n";
-                                       $self->{_delimiters_templates}->{$f}->{$template}++;
+                                       $self->{_delimiters_templates}->{$f}->{$template}++ if ( $template );
                        }
 
                }
index 8a16e4f..9baa5ca 100755 (executable)
@@ -19,7 +19,7 @@ $abs_path =~ s#/[^/]*$#/#;
 
 ok(my $v = new WebPAC::Validate(
        path => "$abs_path/data/validate_test",
-       delimiters => [ ' : ', ' ; ', ' / ', ' \. ' ],
+       delimiters => [ ' : ', ' ; ', ' / ', ' \. ', ' = ' ],
        debug => $debug,
 ), "new");
 
@@ -41,15 +41,21 @@ sub test_v {
 }
 
 test_v({
-       '900' => [ { 'a' => 'a : aa = aaa : a ; a', 'b' => 'b ; b ; b ; b ; a : / z . z . ' }, { 'c' => 'a : b ; c / d' } ]
+       '900' => [
+               { 'a' => 'a : aa = aaa : a ; a', 'b' => 'b ; b ; b ; b ; a : / z . z . ' },
+               { 'a' => 'a : a : a', 'c' => [ 'a : b ; c', 'a : b ; c / d' ] },
+               { 'a' => 'a : b / c' },
+               { 'a' => 'a : b / c' },
+       ]
 });
 
 diag dump($v->{_delimiters_templates});
 
 is_deeply( $v->{_delimiters_templates}, {
        900 => {
-               "^a :  :  ; ^b ;  ;  ;  ;  :  .  . "            => 1,
-               "^a :  :  ; ^b ;  ;  ;  ;  :  .  . ^c :  ;  / " => 1,
+               "^a :  / " => 2,
+               "^a :  : ^c :  ; ^c :  ;  / " => 1,
+               "^a :  =  :  ; ^b ;  ;  ;  ;  :  .  . " => 1,
        },
 }, 'just subfields and delimiters');