| 1 |
#!perl |
| 2 |
|
| 3 |
# test CALLREGEXEC() |
| 4 |
# (currently it just checks that it handles non-\0 terminated strings; |
| 5 |
# full tests haven't been added yet) |
| 6 |
|
| 7 |
use warnings; |
| 8 |
use strict; |
| 9 |
|
| 10 |
use XS::APItest; |
| 11 |
*callregexec = *XS::APItest::callregexec; |
| 12 |
|
| 13 |
use Test::More tests => 48; |
| 14 |
|
| 15 |
# Test that the regex engine can handle strings without terminating \0 |
| 16 |
# XXX This is by no means comprehensive; it doesn't test all ops, nor all |
| 17 |
# code paths within those ops (especially not utf8). |
| 18 |
|
| 19 |
|
| 20 |
# this sub takes a string that has an extraneous char at the end. |
| 21 |
# First see if the string (less the last char) matches the regex; |
| 22 |
# then see if that string (including the last char) matches when |
| 23 |
# calling callregexec(), but with the length arg set to 1 char less than |
| 24 |
# the length of the string. |
| 25 |
# In theory the result should be the same for both matches, since |
| 26 |
# they should both not 'see' the final char. |
| 27 |
|
| 28 |
sub try { |
| 29 |
my ($str, $re, $exp, $desc) = @_; |
| 30 |
|
| 31 |
my $str1 = substr($str, 0, -1); |
| 32 |
ok !!$exp == !!($str1 =~ $re), "$desc str =~ qr"; |
| 33 |
|
| 34 |
my $bytes = do { use bytes; length $str1 }; |
| 35 |
ok !!$exp == !!callregexec($re, 0, $bytes, 0, $str, 0), |
| 36 |
"$desc callregexec"; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
{ |
| 41 |
try "\nx", qr/\n^/m, 0, 'MBOL'; |
| 42 |
try "ax", qr/a$/m, 1, 'MEOL'; |
| 43 |
try "ax", qr/a$/s, 1, 'SEOL'; |
| 44 |
try "abx", qr/^(ab|X)./s, 0, 'SANY'; |
| 45 |
try "abx", qr/^(ab|X)./, 0, 'REG_ANY'; |
| 46 |
try "abx", qr/^ab(c|d|e|x)/, 0, 'TRIE/TRIEC'; |
| 47 |
try "abx", qr/^abx/, 0, 'EXACT'; |
| 48 |
try "abx", qr/^ABX/i, 0, 'EXACTF'; |
| 49 |
try "abx", qr/^ab\b/, 1, 'BOUND'; |
| 50 |
try "ab-", qr/^ab\B/, 0, 'NBOUND'; |
| 51 |
try "aas", qr/a[st]/, 0, 'ANYOF'; |
| 52 |
try "aas", qr/a[s\xDF]/i, 0, 'ANYOFV'; |
| 53 |
try "ab1", qr/ab\d/, 0, 'DIGIT'; |
| 54 |
try "ab\n", qr/ab[[:ascii:]]/, 0, 'POSIX'; |
| 55 |
try "aP\x{307}", qr/^a\X/, 1, 'CLUMP 1'; |
| 56 |
try "aP\x{307}x", qr/^a\X/, 1, 'CLUMP 2'; |
| 57 |
try "\x{100}\r\n", qr/^\x{100}\X/, 1, 'CLUMP 3'; |
| 58 |
try "abb", qr/^a(b)\1/, 0, 'REF'; |
| 59 |
try "ab\n", qr/^.+\R/, 0, 'LNBREAK'; |
| 60 |
try "ab\n", qr/^.+\v/, 0, 'VERTWS'; |
| 61 |
try "abx", qr/^.+\V/, 1, 'NVERTWS'; |
| 62 |
try "ab\t", qr/^.+\h/, 0, 'HORIZWS'; |
| 63 |
try "abx", qr/^.+\H/, 1, 'NHORIZWS'; |
| 64 |
try "abx", qr/a.*x/, 0, 'CURLY'; |
| 65 |
} |