/[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 87 by nigel, Sat Feb 24 21:41:21 2007 UTC code/trunk/perltest.pl revision 518 by ph10, Tue May 18 15:47:01 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. This is the version that supports /8 for UTF-8 testing. As it  # 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. For Perl 5.6, it  # stands, it requires at least Perl 5.8 for UTF-8 support. However, it needs to
6  # can be used as is for non-UTF-8 testing, but you have to uncomment the  # have "use utf8" at the start for running the UTF-8 tests, but *not* for the
7  # "use utf8" lines in order to to UTF-8 stuff (and you mustn't uncomment them  # other tests. The only way I've found for doing this is to cat this line in
8  # for non-UTF-8 use).  # explicitly in the RunPerlTest script.
   
 use locale;  
9    
10    # use locale;  # With this included, \x0b matches \s!
11    
12  # Function for turning a string into a string of printing chars. There are  # Function for turning a string into a string of printing chars. There are
13  # currently problems with UTF-8 strings; this fudges round them.  # currently problems with UTF-8 strings; this fudges round them.
# Line 18  my($t) = ""; Line 17  my($t) = "";
17    
18  if ($utf8)  if ($utf8)
19    {    {
 #  use utf8;                    <=============== For UTF-8 in Perl 5.6  
20    @p = unpack('U*', $_[0]);    @p = unpack('U*', $_[0]);
21    foreach $c (@p)    foreach $c (@p)
22      {      {
# Line 40  $t; Line 38  $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 88  for (;;) Line 85  for (;;)
85    
86    # The private /+ modifier means "print $' afterwards".    # The private /+ modifier means "print $' afterwards".
87    
88    $showrest = ($pattern =~ s/\+(?=[a-z]*$)//);    $showrest = ($pattern =~ s/\+(?=[a-zA-Z]*$)//);
89    
90    # The private /8 modifier means "operate in UTF-8". Currently, Perl    # Remove /8 from a UTF-8 pattern.
   # has bugs that we try to work around using this flag.  
91    
92    $utf8 = ($pattern =~ s/8(?=[a-z]*$)//);    $utf8 = $pattern =~ s/8(?=[a-zA-Z]*$)//;
93    
94    # Check that the pattern is valid    # Remove /J from a pattern with duplicate names.
95    
96    if ($utf8)    $pattern =~ s/J(?=[a-zA-Z]*$)//;
97      {  
98  #    use utf8;                    <=============== For UTF-8 in Perl 5.6    # Remove /K from a pattern (asks pcretest to check MARK data) */
99      eval "\$_ =~ ${pattern}";  
100      }    $pattern =~ s/K(?=[a-zA-Z]*$)//;
101    else  
102      {    # Remove /W from a pattern (asks pcretest to set PCRE_UCP)
     eval "\$_ =~ ${pattern}";  
     }  
103    
104      $pattern =~ s/W(?=[a-zA-Z]*$)//;
105    
106      # Check that the pattern is valid
107    
108      eval "\$_ =~ ${pattern}";
109    if ($@)    if ($@)
110      {      {
111      printf $outfile "Error: $@";      printf $outfile "Error: $@";
# Line 136  for (;;) Line 135  for (;;)
135      chomp;      chomp;
136      printf $outfile "$_\n" if $infile ne "STDIN";      printf $outfile "$_\n" if $infile ne "STDIN";
137    
138      s/\s+$//;      s/\s+$//;  # Remove trailing space
139      s/^\s+//;      s/^\s+//;  # Remove leading space
140        s/\\Y//g;  # Remove \Y (pcretest flag to set PCRE_NO_START_OPTIMIZE)
141    
142      last if ($_ eq "");      last if ($_ eq "");
   
143      $x = eval "\"$_\"";   # To get escapes processed      $x = eval "\"$_\"";   # To get escapes processed
144    
145      # Empty array for holding results, then do the matching.      # Empty array for holding results, ensure $REGERROR and $REGMARK are
146        # unset, then do the matching.
147    
148      @subs = ();      @subs = ();
149    
# Line 166  for (;;) Line 166  for (;;)
166           "push \@subs,\$16;" .           "push \@subs,\$16;" .
167           "push \@subs,\$'; }";           "push \@subs,\$'; }";
168    
169      if ($utf8)      undef $REGERROR;
170        {      undef $REGMARK;
171  #      use utf8;                    <=============== For UTF-8 in Perl 5.6  
172        eval "${cmd} (\$x =~ ${pattern}) {" . $pushes;      eval "${cmd} (\$x =~ ${pattern}) {" . $pushes;
       }  
     else  
       {  
       eval "${cmd} (\$x =~ ${pattern}) {" . $pushes;  
       }  
173    
174      if ($@)      if ($@)
175        {        {
# Line 183  for (;;) Line 178  for (;;)
178        }        }
179      elsif (scalar(@subs) == 0)      elsif (scalar(@subs) == 0)
180        {        {
181        printf $outfile "No match\n";        printf $outfile "No match";
182          if (defined $REGERROR && $REGERROR != 1)
183            { print $outfile (", mark = $REGERROR"); }
184          printf $outfile "\n";
185        }        }
186      else      else
187        {        {
# Line 204  for (;;) Line 202  for (;;)
202            }            }
203          splice(@subs, 0, 18);          splice(@subs, 0, 18);
204          }          }
205          if (defined $REGMARK && $REGMARK != 1)
206            { print $outfile ("MK: $REGMARK\n"); }
207        }        }
208      }      }
209    }    }

Legend:
Removed from v.87  
changed lines
  Added in v.518

  ViewVC Help
Powered by ViewVC 1.1.5