Ticket #1795: pcre.t.patch

File pcre.t.patch, 2.0 KB (added by ronaldws, 11 years ago)

Patch to add test for returned error string

  • t/library/pcre.t

     
    9999CODE 
    100100Loaded 
    101101OUT 
    102  
    103 ## 2 
    104102    my @todo; 
    105     @todo = ( todo => '3..5 fail on Win32' ) if $^O =~ /MSWin32/; 
     103    @todo = ( todo => '4..6 fail on Win32 (maybe)' ) if $^O =~ /MSWin32/; 
    106104    pir_output_is( <<"CODE", <<'OUT', 'soup to nuts', @todo ); 
    107105 
    108106.include 'iglobals.pasm' 
     
    139137OK2: 
    140138    say 'ok 2' 
    141139 
    142  
    143     .local string s 
    144140    .local string pat 
     141    pat= '(a' 
     142    func= get_global ['PCRE'], 'compile' 
    145143 
    146     s= '--a--' 
    147     pat= 'a' 
    148  
    149144    .local pmc code 
    150     .local string error 
     145    .local pmc error 
    151146    .local int errptr 
     147     error= new ['String'] 
    152148 
    153149    func= get_global ['PCRE'], 'compile' 
    154150    ( code, error, errptr )= func( pat, 0 ) 
    155151 
    156     .local int is_code_defined 
    157     is_code_defined= defined code 
    158     if is_code_defined goto OK3 
     152    # expecting error like 'missing )' 
     153    .local int error_end 
     154    .local int found_paren 
     155    error_end = elements error 
     156    dec error_end 
     157    found_paren = error.'reverse_index'(')', error_end) 
     158    ne found_paren, -1, OK3 
    159159    print 'not ' 
    160160OK3: 
    161161    say 'ok 3' 
    162162 
     163    pat= 'a' 
     164 
     165    func= get_global ['PCRE'], 'compile' 
     166    ( code, error, errptr )= func( pat, 0 ) 
     167 
     168    .local int is_code_defined 
     169    is_code_defined= defined code 
     170    if is_code_defined goto OK4 
     171    print 'not ' 
     172OK4: 
     173    say 'ok 4' 
     174 
    163175    .local int ok 
    164176    .local pmc result 
    165177 
     178    .local string s 
     179    s= '--a--' 
     180 
    166181    func= get_global ['PCRE'], 'match' 
    167182    ( ok, result )= func( code, s, 0, 0 ) 
    168183 
    169     unless ok < 0 goto OK4 
     184    unless ok < 0 goto OK5 
    170185    print 'not ' 
    171 OK4: 
    172     say 'ok 4' 
     186OK5: 
     187    say 'ok 5' 
    173188 
    174189    .local int i 
    175190    i = 0 
     
    177192 
    178193    func = get_global ['PCRE'], 'dollar' 
    179194    match = func( s, ok, result, i ) 
    180     if 'a' == match goto OK5 
     195    if 'a' == match goto OK6 
    181196    print 'not ' 
    182 OK5: 
    183     say 'ok 5' 
     197OK6: 
     198    say 'ok 6' 
    184199 
    185200.end 
    186201CODE 
     
    189204ok 3 
    190205ok 4 
    191206ok 5 
     207ok 6 
    192208OUT 
    193209 
    194210}