/[pcre]/code/trunk/perltest.pl
ViewVC logotype

Diff of /code/trunk/perltest.pl

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

code/trunk/perltest revision 49 by nigel, Sat Feb 24 21:39:33 2007 UTC code/trunk/perltest.pl revision 488 by ph10, Mon Jan 11 15:29:42 2010 UTC
# Line 1  Line 1 
1  #! /usr/bin/perl  #! /usr/bin/env perl
2    
3  # Program for testing regular expressions with perl to check that PCRE handles  # Program for testing regular expressions with perl to check that PCRE handles
4  # them the same.  # them the same. This is the version that supports /8 for UTF-8 testing. As it
5    # stands, it requires at least Perl 5.8 for UTF-8 support. However, it needs to
6    # have "use utf8" at the start for running the UTF-8 tests, but *not* for the
7    # other tests. The only way I've found for doing this is to cat this line in
8    # explicitly in the RunPerlTest script.
9    
10    # use locale;  # With this included, \x0b matches \s!
11    
12  # Function for turning a string into a string of printing chars  # Function for turning a string into a string of printing chars. There are
13    # currently problems with UTF-8 strings; this fudges round them.
14    
15  sub pchars {  sub pchars {
16  my($t) = "";  my($t) = "";
17    
18  foreach $c (split(//, $_[0]))  if ($utf8)
19    {    {
20    if (ord $c >= 32 && ord $c < 127) { $t .= $c; }    @p = unpack('U*', $_[0]);
21      else { $t .= sprintf("\\x%02x", ord $c); }    foreach $c (@p)
22        {
23        if ($c >= 32 && $c < 127) { $t .= chr $c; }
24          else { $t .= sprintf("\\x{%02x}", $c); }
25        }
26      }
27    
28    else
29      {
30      foreach $c (split(//, $_[0]))
31        {
32        if (ord $c >= 32 && ord $c < 127) { $t .= $c; }
33          else { $t .= sprintf("\\x%02x", ord $c); }
34        }
35    }    }
36    
37  $t;  $t;
38  }  }
39    
40    
   
41  # Read lines from named file or stdin and write to named file or stdout; lines  # Read lines from named file or stdin and write to named file or stdout; lines
42  # consist of a regular expression, in delimiters and optionally followed by  # consist of a regular expression, in delimiters and optionally followed by
43  # options, followed by a set of test data, terminated by an empty line.  # options, followed by a set of test data, terminated by an empty line.
# Line 64  for (;;) Line 83  for (;;)
83     chomp($pattern);     chomp($pattern);
84     $pattern =~ s/\s+$//;     $pattern =~ s/\s+$//;
85    
86    # The private /+ modifier means "print $' afterwards". We use it    # The private /+ modifier means "print $' afterwards".
   # only on the end of patterns to make it easy to chop off here.  
87    
88    $showrest = ($pattern =~ s/\+(?=[a-z]*$)//);    $showrest = ($pattern =~ s/\+(?=[a-z]*$)//);
89    
90      # Remove /8 from a UTF-8 pattern.
91    
92      $utf8 = $pattern =~ s/8(?=[a-z]*$)//;
93    
94      # Remove /J from a pattern with duplicate names.
95    
96      $pattern =~ s/J(?=[a-z]*$)//;
97    
98    # Check that the pattern is valid    # Check that the pattern is valid
99    
100    eval "\$_ =~ ${pattern}";    eval "\$_ =~ ${pattern}";
# Line 105  for (;;) Line 131  for (;;)
131      s/^\s+//;      s/^\s+//;
132    
133      last if ($_ eq "");      last if ($_ eq "");
   
134      $x = eval "\"$_\"";   # To get escapes processed      $x = eval "\"$_\"";   # To get escapes processed
135    
136      # Empty array for holding results, then do the matching.      # Empty array for holding results, ensure $REGERROR and $REGMARK are
137        # unset, then do the matching.
138    
139      @subs = ();      @subs = ();
140    
141      eval "${cmd} (\$x =~ ${pattern}) {" .      $pushes = "push \@subs,\$&;" .
          "push \@subs,\$&;" .  
142           "push \@subs,\$1;" .           "push \@subs,\$1;" .
143           "push \@subs,\$2;" .           "push \@subs,\$2;" .
144           "push \@subs,\$3;" .           "push \@subs,\$3;" .
# Line 132  for (;;) Line 157  for (;;)
157           "push \@subs,\$16;" .           "push \@subs,\$16;" .
158           "push \@subs,\$'; }";           "push \@subs,\$'; }";
159    
160        undef $REGERROR;
161        undef $REGMARK;
162    
163        eval "${cmd} (\$x =~ ${pattern}) {" . $pushes;
164    
165      if ($@)      if ($@)
166        {        {
167        printf $outfile "Error: $@\n";        printf $outfile "Error: $@\n";
# Line 139  for (;;) Line 169  for (;;)
169        }        }
170      elsif (scalar(@subs) == 0)      elsif (scalar(@subs) == 0)
171        {        {
172        printf $outfile "No match\n";        printf $outfile "No match";
173          if (defined $REGERROR && $REGERROR != 1)
174            { print $outfile (", mark = $REGERROR"); }
175          printf $outfile "\n";
176        }        }
177      else      else
178        {        {
# Line 160  for (;;) Line 193  for (;;)
193            }            }
194          splice(@subs, 0, 18);          splice(@subs, 0, 18);
195          }          }
196          if (defined $REGMARK && $REGMARK != 1)
197            { print $outfile ("MK: $REGMARK\n"); }
198        }        }
199      }      }
200    }    }
201    
202  printf $outfile "\n";  # printf $outfile "\n";
203    
204  # End  # End

Legend:
Removed from v.49  
changed lines
  Added in v.488

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12