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 eq '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, got ". scalar(@tests) ); 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: /$pattern/\n\n" 45 . "EXPECTED:\n$_\n\n" 46 . "WITHIN GOT:\n$testout"); 47 }; 48 } 49} 50 51# The format below is simple. Each line is an exact 52# string that must be found in the output. 53# Lines starting the # are comments. 54# Lines starting with --- are separators indicating 55# that the tests for this result set are finished. 56# If you add a test make sure you update $NUM_SECTS 57# the commented output is just for legacy/debugging purposes 58BEGIN{ $NUM_SECTS= 8 } 59 60__END__ 61#Compiling REx "X(A|[B]Q||C|D)Y" 62#size 34 63#first at 1 64# 1: EXACT <X>(3) 65# 3: OPEN1(5) 66# 5: TRIE-EXACT(21) 67# [Words:5 Chars:5 Unique:5 States:6 Start-Class:A-D] 68# <A> 69# <BQ> 70# <> 71# <C> 72# <D> 73# 21: CLOSE1(23) 74# 23: EXACT <Y>(25) 75# 25: END(0) 76#anchored "X" at 0 floating "Y" at 1..3 (checking floating) minlen 2 77#Guessing start of match, REx "X(A|[B]Q||C|D)Y" against "XY"... 78#Found floating substr "Y" at offset 1... 79#Found anchored substr "X" at offset 0... 80#Guessed: match at offset 0 81#Matching REx "X(A|[B]Q||C|D)Y" against "XY" 82# Setting an EVAL scope, savestack=140 83# 0 <> <XY> | 1: EXACT <X> 84# 1 <X> <Y> | 3: OPEN1 85# 1 <X> <Y> | 5: TRIE-EXACT 86# matched empty string... 87# 1 <X> <Y> | 21: CLOSE1 88# 1 <X> <Y> | 23: EXACT <Y> 89# 2 <XY> <> | 25: END 90#Match successful! 91#%MATCHED% 92#Freeing REx: "X(A|[B]Q||C|D)Y" 93Compiling REx "X(A|[B]Q||C|D)Y" 94[A-D] 95TRIE-EXACT 96<BQ> 97matched empty string 98Match successful! 99Found floating substr "Y" at offset 1 (rx_origin now 0)... 100Found anchored substr "X" at offset 0 (rx_origin now 0)... 101Successfully guessed: match at offset 0 102checking floating 103minlen 2 104S:1/6 105W:5 106L:0/2 107C:5/5 108%MATCHED% 109--- 110#Compiling REx "[f][o][o][b][a][r]" 111#size 67 112#first at 1 113# 1: EXACT <foobar>(13) 114# 13: END(0) 115#anchored "foobar" at 0 (checking anchored isall) minlen 6 116#Guessing start of match, REx "[f][o][o][b][a][r]" against "foobar"... 117#Found anchored substr "foobar" at offset 0... 118#Guessed: match at offset 0 119#Freeing REx: "[f][o][o][b][a][r]" 120foobar 121checking anchored isall 122minlen 6 123anchored "foobar" at 0 124Successfully guessed: match at offset 0 125Compiling REx "[f][o][o][b][a][r]" 126Freeing REx: "[f][o][o][b][a][r]" 127%MATCHED% 128--- 129#Compiling REx ".[XY]." 130#size 14 131#first at 1 132# 1: REG_ANY(2) 133# 2: ANYOF[XY](13) 134# 13: REG_ANY(14) 135# 14: END(0) 136#minlen 3 137#%FAILED% 138#Freeing REx: ".[XY]." 139%FAILED% 140minlen 3 141--- 142# Compiling REx "(?:ABCP|ABCG|ABCE|ABCB|ABCA|ABCD)" 143# TRIE(NATIVE): W:6 C:24 Uq:7 Min:4 Max:4 144# Char : Match Base Ofs A B C P G E D 145# State|--------------------------------------------------- 146# # 1| @ 7 + 0[ 2 . . . . . .] 147# # 2| @ 7 + 1[ . 3 . . . . .] 148# # 3| @ 7 + 2[ . . 4 . . . .] 149# # 4| @ A + 0[ 9 8 0 5 6 7 A] 150# # 5| W 1 @ 0 151# # 6| W 2 @ 0 152# # 7| W 3 @ 0 153# # 8| W 4 @ 0 154# # 9| W 5 @ 0 155# # A| W 6 @ 0 156# word_info N:(prev,char)= 1:(0,1) 2:(0,1) 3:(0,1) 4:(0,1) 5:(0,1) 6:(0,1) 157# Final program: 158# 1: EXACT <ABC> (3) 159# 3: TRIEC-EXACT<S:4/10 W:6 L:1/1 C:24/7>[A-EGP] (20) 160# <P> 161# <G> 162# <E> 163# <B> 164# <A> 165# <D> 166# 20: END (0) 167# anchored "ABC" at 0 (checking anchored) minlen 4 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: 7 CP: 0 After State: 0 176# got 1 possible matches 177# TRIE matched word #6, continuing 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] 186S:4/10 187W:6 188L:1/1 189C:24/7 190minlen 4 191(checking anchored) 192anchored "ABC" at 0 193--- 194#Compiling REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|\.pyo|\.pyc|\.pyw|\.py)$" 195#size 48 nodes first at 3 196#first at 3 197#rarest char 198# at 0 199# 1: OPEN1(3) 200# 3: EXACTF <.>(5) 201# 5: TRIE-EXACTF(45) 202# [Start:2 Words:14 Chars:54 Unique:18 States:29 Minlen:2 Maxlen:3 Start-Class:BCEJPVWbcejpvw] 203# <.COM> 204# ... yada yada ... (dmq) 205# <.py> 206# 45: CLOSE1(47) 207# 47: EOL(48) 208# 48: END(0) 209#floating ""$ at 3..4 (checking floating) stclass "EXACTF <.>" minlen 3 210#Guessing start of match, REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|..." against "D:dev/perl/ver/28321_/perl.exe"... 211#Found floating substr ""$ at offset 30... 212#Starting position does not contradict /^/m... 213#Does not contradict STCLASS... 214#Guessed: match at offset 26 215#Matching REx "(\.COM|\.EXE|\.BAT|\.CMD|\.VBS|\.VBE|\.JS|\.JSE|\.WSF|\.WSH|\.pyo|\.pyc|\.pyw|\.py)$..." against ".exe" 216#Matching stclass "EXACTF <.>" against ".exe" 217# Setting an EVAL scope, savestack=140 218# 26 <21_/perl> <.exe> | 1: OPEN1 219# 26 <21_/perl> <.exe> | 3: EXACTF <.> 220# 27 <21_/perl.> <exe> | 5: TRIE-EXACTF 221# only one match : #2 <.EXE> 222# 30 <21_/perl.exe> <> | 45: CLOSE1 223# 30 <21_/perl.exe> <> | 47: EOL 224# 30 <21_/perl.exe> <> | 48: END 225#Match successful! 226#POP STATE(1) 227#%MATCHED% 228#Freeing REx: "(\\.COM|\\.EXE|\\.BAT|\\.CMD|\\.VBS|\\.VBE|\\.JS|\\.JSE|\\."...... 229%MATCHED% 230floating ""$ at 3..4 (checking floating) 231#stclass EXACTF <.> minlen 3 232#Found floating substr ""$ at offset 30... 233#Does not contradict STCLASS... 234#Guessed: match at offset 26 235#Matching stclass EXACTF <.> against ".exe" 236--- 237#Compiling REx "[q]" 238#first at 1 239#Final program: 240# 1: EXACT <q>(3) 241# 3: END(0) 242#anchored "q" at 0 (checking anchored isall) minlen 1 243#Guessing start of match, REx "[q]" against "q"... 244#Found anchored substr "q" at offset 0... 245#Guessed: match at offset 0 246#%MATCHED% 247#Freeing REx: "[q]" 248%MATCHED% 249Freeing REx: "[q]" 250--- 251#Compiling REx "^(\S{1,9}):\s*(\d+)$" 252#Final program: 253# 1: SBOL (2) 254# 2: OPEN1 (4) 255# 4: CURLY {1,9} (7) 256# 6: NPOSIXD[\s] (0) 257# 7: CLOSE1 (9) 258# 9: EXACT <:> (11) 259# 11: STAR (13) 260# 12: POSIXD[\s] (0) 261# 13: OPEN2 (15) 262# 15: PLUS (17) 263# 16: POSIXD[\d] (0) 264# 17: CLOSE2 (19) 265# 19: EOL (20) 266# 20: END (0) 267#Freeing REx: "^(\S{1,9}):\s*(\d+)$" 268%MATCHED% 269Freeing REx: "^(\S{1,9}):\s*(\d+)$" 270--- 271#Compiling REx "(?(DEFINE)(?<foo>foo))(?(DEFINE)(?<bar>(?&foo)bar))(?(DEFINE"... 272study_chunk_recursed_count: 5 273#Final program: 274# 1: DEFINEP (3) 275# 3: IFTHEN (14) 276# 5: OPEN1 'foo' (7) 277# 7: EXACT <foo> (9) 278# 9: CLOSE1 'foo' (14) 279# 11: LONGJMP (13) 280# 13: TAIL (14) 281# 14: DEFINEP (16) 282# 16: IFTHEN (30) 283# 18: OPEN2 'bar' (20) 284# 20: GOSUB1[-15] (23) 285# 23: EXACT <bar> (25) 286# 25: CLOSE2 'bar' (30) 287# 27: LONGJMP (29) 288# 29: TAIL (30) 289# 30: DEFINEP (32) 290# 32: IFTHEN (46) 291# 34: OPEN3 'baz' (36) 292# 36: GOSUB2[-18] (39) 293# 39: EXACT <baz> (41) 294# 41: CLOSE3 'baz' (46) 295# 43: LONGJMP (45) 296# 45: TAIL (46) 297# 46: DEFINEP (48) 298# 48: IFTHEN (62) 299# 50: OPEN4 'bop' (52) 300# 52: GOSUB3[-18] (55) 301# 55: EXACT <bop> (57) 302# 57: CLOSE4 'bop' (62) 303# 59: LONGJMP (61) 304# 61: TAIL (62) 305# 62: END (0) 306minlen 0 307#Matching REx "(?(DEFINE)(?<foo>foo))(?(DEFINE)(?<bar>(?&foo)bar))(?(DEFINE"... against "" 308# 0 <> <> | 1:DEFINEP(3) 309# 0 <> <> | 3:IFTHEN(14) 310# 0 <> <> | 14:DEFINEP(16) 311# 0 <> <> | 16:IFTHEN(30) 312# 0 <> <> | 30:DEFINEP(32) 313# 0 <> <> | 32:IFTHEN(46) 314# 0 <> <> | 46:DEFINEP(48) 315# 0 <> <> | 48:IFTHEN(62) 316# 0 <> <> | 62:END(0) 317#Match successful! 318%MATCHED% 319#Freeing REx: "(?(DEFINE)(?<foo>foo))(?(DEFINE)(?<bar>(?&foo)bar))(?(DEFINE"... 320