regop.t revision 1.3
1#!./perl 2 3BEGIN { 4 require Config; 5 if (($Config::Config{'extensions'} !~ /\bre\b/) ){ 6 print "1..0 # Skip -- Perl configured without re module\n"; 7 exit 0; 8 } 9} 10 11use strict; 12BEGIN { require "../../t/test.pl"; } 13our $NUM_SECTS; 14chomp(my @strs= grep { !/^\s*\#/ } <DATA>); 15my $out = runperl(progfile => "t/regop.pl", stderr => 1 ); 16# VMS currently embeds linefeeds in the output. 17$out =~ s/\cJ//g if $^O = 'VMS'; 18my @tests = grep { /\S/ } split /(?=Compiling REx)/, $out; 19# on debug builds we get an EXECUTING... message in there at the top 20shift @tests 21 if $tests[0] =~ /EXECUTING.../; 22 23plan( @tests + 2 + ( @strs - grep { !$_ or /^---/ } @strs )); 24 25is( scalar @tests, $NUM_SECTS, 26 "Expecting output for $NUM_SECTS patterns" ); 27ok( defined $out, 'regop.pl returned something defined' ); 28 29$out ||= ""; 30my $test= 1; 31foreach my $testout ( @tests ) { 32 my ( $pattern )= $testout=~/Compiling REx "([^"]+)"/; 33 ok( $pattern, "Pattern for test " . ($test++) ); 34 my $diaged; 35 while (@strs) { 36 local $_= shift @strs; 37 last if !$_ 38 or /^---/; 39 next if /^\s*#/; 40 s/^\s+//; 41 s/\s+$//; 42 ok( $testout=~/\Q$_\E/, "$_: /$pattern/" ) 43 or do { 44 !$diaged++ and diag("$_: /$pattern/\n$testout"); 45 }; 46 } 47} 48 49# The format below is simple. Each line is an exact 50# string that must be found in the output. 51# Lines starting the # are comments. 52# Lines starting with --- are seperators indicating 53# that the tests for this result set are finished. 54# If you add a test make sure you update $NUM_SECTS 55# the commented output is just for legacy/debugging purposes 56BEGIN{ $NUM_SECTS= 6 } 57 58__END__ 59#Compiling REx "X(A|[B]Q||C|D)Y" 60#size 34 61#first at 1 62# 1: EXACT <X>(3) 63# 3: OPEN1(5) 64# 5: TRIE-EXACT(21) 65# [Words:5 Chars:5 Unique:5 States:6 Start-Class:A-D] 66# <A> 67# <BQ> 68# <> 69# <C> 70# <D> 71# 21: CLOSE1(23) 72# 23: EXACT <Y>(25) 73# 25: END(0) 74#anchored "X" at 0 floating "Y" at 1..3 (checking floating) minlen 2 75#Guessing start of match, REx "X(A|[B]Q||C|D)Y" against "XY"... 76#Found floating substr "Y" at offset 1... 77#Found anchored substr "X" at offset 0... 78#Guessed: match at offset 0 79#Matching REx "X(A|[B]Q||C|D)Y" against "XY" 80# Setting an EVAL scope, savestack=140 81# 0 <> <XY> | 1: EXACT <X> 82# 1 <X> <Y> | 3: OPEN1 83# 1 <X> <Y> | 5: TRIE-EXACT 84# matched empty string... 85# 1 <X> <Y> | 21: CLOSE1 86# 1 <X> <Y> | 23: EXACT <Y> 87# 2 <XY> <> | 25: END 88#Match successful! 89#%MATCHED% 90#Freeing REx: "X(A|[B]Q||C|D)Y" 91Compiling REx "X(A|[B]Q||C|D)Y" 92[A-D] 93TRIE-EXACT 94<BQ> 95matched empty string 96Match successful! 97Found floating substr "Y" at offset 1... 98Found anchored substr "X" at offset 0... 99Guessed: match at offset 0 100checking floating 101minlen 2 102S:1/6 103W:5 104L:0/2 105C:5/5 106%MATCHED% 107--- 108#Compiling REx "[f][o][o][b][a][r]" 109#size 67 110#first at 1 111# 1: EXACT <foobar>(13) 112# 13: END(0) 113#anchored "foobar" at 0 (checking anchored isall) minlen 6 114#Guessing start of match, REx "[f][o][o][b][a][r]" against "foobar"... 115#Found anchored substr "foobar" at offset 0... 116#Guessed: match at offset 0 117#Freeing REx: "[f][o][o][b][a][r]" 118foobar 119checking anchored isall 120minlen 6 121anchored "foobar" at 0 122Guessed: match at offset 0 123Compiling REx "[f][o][o][b][a][r]" 124Freeing REx: "[f][o][o][b][a][r]" 125%MATCHED% 126--- 127#Compiling REx ".[XY]." 128#size 14 129#first at 1 130# 1: REG_ANY(2) 131# 2: ANYOF[XY](13) 132# 13: REG_ANY(14) 133# 14: END(0) 134#minlen 3 135#%FAILED% 136#Freeing REx: ".[XY]." 137%FAILED% 138minlen 3 139--- 140# Compiling REx "(?:ABCP|ABCG|ABCE|ABCB|ABCA|ABCD)" 141# Got 164 bytes for offset annotations. 142# TRIE(NATIVE): W:6 C:24 Uq:7 Min:4 Max:4 143# Char : Match Base Ofs A B C P G E D 144# State|--------------------------------------------------- 145# # 1| @ 7 + 0[ 2 . . . . . .] 146# # 2| @ 7 + 1[ . 3 . . . . .] 147# # 3| @ 7 + 2[ . . 4 . . . .] 148# # 4| @ A + 0[ 9 8 0 5 6 7 A] 149# # 5| W 1 @ 0 150# # 6| W 2 @ 0 151# # 7| W 3 @ 0 152# # 8| W 4 @ 0 153# # 9| W 5 @ 0 154# # A| W 6 @ 0 155# Final program: 156# 1: EXACT <ABC>(3) 157# 3: TRIEC-EXACT<S:4/10 W:6 L:1/1 C:24/7>[A-EGP](20) 158# <P> 159# <G> 160# <E> 161# <B> 162# <A> 163# <D> 164# 20: END(0) 165# anchored "ABC" at 0 (checking anchored) minlen 4 166# Offsets: [20] 167# 1:4[3] 3:4[15] 19:32[0] 20:34[0] 168# Guessing start of match in sv for REx "(?:ABCP|ABCG|ABCE|ABCB|ABCA|ABCD)" against "ABCD" 169# Found anchored substr "ABC" at offset 0... 170# Guessed: match at offset 0 171# Matching REx "(?:ABCP|ABCG|ABCE|ABCB|ABCA|ABCD)" against "ABCD" 172# 0 <> <ABCD> | 1:EXACT <ABC>(3) 173# 3 <ABC> <D> | 3:TRIEC-EXACT<S:4/10 W:6 L:1/1 C:24/7>[A-EGP](20) 174# 3 <ABC> <D> | State: 4 Accepted: 0 Charid: 7 CP: 44 After State: a 175# 4 <ABCD> <> | State: a Accepted: 1 Charid: 6 CP: 0 After State: 0 176# got 1 possible matches 177# only one match left: #6 <D> 178# 4 <ABCD> <> | 20:END(0) 179# Match successful! 180# %MATCHED% 181# Freeing REx: "(?:ABCP|ABCG|ABCE|ABCB|ABCA|ABCD)" 182%MATCHED% 183EXACT <ABC> 184TRIEC-EXACT 185[A-EGP] 186only one match left: #6 <D> 187S:4/10 188W:6 189L:1/1 190C:24/7 191minlen 4 192(checking anchored) 193anchored "ABC" at 0 194--- 195#Compiling REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|\.pyo|\.pyc|\.pyw|\.py)$" 196#size 48 nodes first at 3 197#first at 3 198#rarest char 199# at 0 200# 1: OPEN1(3) 201# 3: EXACTF <.>(5) 202# 5: TRIE-EXACTF(45) 203# [Start:2 Words:14 Chars:54 Unique:18 States:29 Minlen:2 Maxlen:3 Start-Class:BCEJPVWbcejpvw] 204# <.COM> 205# ... yada yada ... (dmq) 206# <.py> 207# 45: CLOSE1(47) 208# 47: EOL(48) 209# 48: END(0) 210#floating ""$ at 3..4 (checking floating) stclass "EXACTF <.>" minlen 3 211#Offsets: [48] 212# 1:1[1] 3:2[1] 5:2[81] 45:83[1] 47:84[1] 48:85[0] 213#Guessing start of match, REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|..." against "D:dev/perl/ver/28321_/perl.exe"... 214#Found floating substr ""$ at offset 30... 215#Starting position does not contradict /^/m... 216#Does not contradict STCLASS... 217#Guessed: match at offset 26 218#Matching REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|\.pyo|\.pyc|\.pyw|\.py)$..." against ".exe" 219#Matching stclass "EXACTF <.>" against ".exe" 220# Setting an EVAL scope, savestack=140 221# 26 <21_/perl> <.exe> | 1: OPEN1 222# 26 <21_/perl> <.exe> | 3: EXACTF <.> 223# 27 <21_/perl.> <exe> | 5: TRIE-EXACTF 224# only one match : #2 <.EXE> 225# 30 <21_/perl.exe> <> | 45: CLOSE1 226# 30 <21_/perl.exe> <> | 47: EOL 227# 30 <21_/perl.exe> <> | 48: END 228#Match successful! 229#POP STATE(1) 230#%MATCHED% 231#Freeing REx: "(\\.COM|\\.EXE|\\.BAT|\\.CMD|\\.VBS|\\.VBE|\\.JS|\\.JSE|\\."...... 232%MATCHED% 233floating ""$ at 3..4 (checking floating) 234#1:1[1] 3:2[1] 5:2[64] 45:83[1] 47:84[1] 48:85[0] 235#stclass EXACTF <.> minlen 3 236#Found floating substr ""$ at offset 30... 237#Does not contradict STCLASS... 238#Guessed: match at offset 26 239#Matching stclass EXACTF <.> against ".exe" 240--- 241#Compiling REx "[q]" 242#size 12 nodes Got 100 bytes for offset annotations. 243#first at 1 244#Final program: 245# 1: EXACT <q>(3) 246# 3: END(0) 247#anchored "q" at 0 (checking anchored isall) minlen 1 248#Offsets: [12] 249# 1:1[3] 3:4[0] 250#Guessing start of match, REx "[q]" against "q"... 251#Found anchored substr "q" at offset 0... 252#Guessed: match at offset 0 253#%MATCHED% 254#Freeing REx: "[q]" 255Got 100 bytes for offset annotations. 256Offsets: [12] 2571:1[3] 3:4[0] 258%MATCHED% 259Freeing REx: "[q]" 260