more tests (and fix 2 from yesterday)

This commit is contained in:
Nuno Lopes 2006-06-14 17:37:53 +00:00
parent 7406f3771a
commit a7bc286638
9 changed files with 362 additions and 1 deletions

View File

@ -11,6 +11,7 @@ var_dump(preg_match('<>', ''));
var_dump(preg_match('~a', ''));
var_dump(preg_match('@\@\@@', '@@'));
var_dump(preg_match('//z', '@@'));
var_dump(preg_match('{', ''));
?>
--EXPECTF--
@ -31,3 +32,6 @@ int(1)
Warning: preg_match(): Unknown modifier 'z' in %sdelimiters.php on line 10
bool(false)
Warning: preg_match(): No ending matching delimiter '}' found in %sdelimiters.php on line 11
bool(false)

View File

@ -0,0 +1,39 @@
--TEST--
D (PCRE_DOLLAR_ENDONLY) modififer
--FILE--
<?php
var_dump(preg_match_all('/^\S+.+$/', "aeiou\n", $m));
var_dump($m);
var_dump(preg_match_all('/^\S+.+$/D', "aeiou\n", $m));
var_dump($m);
var_dump(preg_match_all('/^\S+\s$/D', "aeiou\n", $m));
var_dump($m);
?>
--EXPECT--
int(1)
array(1) {
[0]=>
array(1) {
[0]=>
string(5) "aeiou"
}
}
int(0)
array(1) {
[0]=>
array(0) {
}
}
int(1)
array(1) {
[0]=>
array(1) {
[0]=>
string(6) "aeiou
"
}
}

View File

@ -1,7 +1,7 @@
--TEST--
Localized match
--SKIPIF--
<?php if (!function_exists('setlocale')) die('setlocale() not available'); ?>
<?php if (!function_exists('setlocale')) die('skip: setlocale() not available'); ?>
--FILE--
<?php

View File

@ -0,0 +1,127 @@
--TEST--
preg_match_all() flags
--FILE--
<?php
var_dump(preg_match_all('/(.)x/', 'zxax', $match, PREG_PATTERN_ORDER));
var_dump($match);
var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_SET_ORDER));
var_dump($match);
var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_OFFSET_CAPTURE));
var_dump($match);
var_dump(preg_match_all('/(.)x/', 'zxyx', $match, PREG_SET_ORDER | PREG_OFFSET_CAPTURE));
var_dump($match);
?>
--EXPECT--
int(2)
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "zx"
[1]=>
string(2) "ax"
}
[1]=>
array(2) {
[0]=>
string(1) "z"
[1]=>
string(1) "a"
}
}
int(2)
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "zx"
[1]=>
string(1) "z"
}
[1]=>
array(2) {
[0]=>
string(2) "yx"
[1]=>
string(1) "y"
}
}
int(2)
array(2) {
[0]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "zx"
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(2) "yx"
[1]=>
int(2)
}
}
[1]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(1) "z"
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(1) "y"
[1]=>
int(2)
}
}
}
int(2)
array(2) {
[0]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "zx"
[1]=>
int(0)
}
[1]=>
array(2) {
[0]=>
string(1) "z"
[1]=>
int(0)
}
}
[1]=>
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "yx"
[1]=>
int(2)
}
[1]=>
array(2) {
[0]=>
string(1) "y"
[1]=>
int(2)
}
}
}

View File

@ -0,0 +1,95 @@
--TEST--
preg_match() flags
--FILE--
<?php
var_dump(preg_match('/x(.)/', 'fjszxax', $match, PREG_OFFSET_CAPTURE));
var_dump($match);
var_dump(preg_match('/(.)x/', 'fjszxax', $match, PREG_OFFSET_CAPTURE, 4));
var_dump($match);
var_dump(preg_match('/(?P<capt1>.)(x)(?P<letsmix>\S+)/', 'fjszxax', $match, PREG_OFFSET_CAPTURE));
var_dump($match);
?>
--EXPECT--
int(1)
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "xa"
[1]=>
int(4)
}
[1]=>
array(2) {
[0]=>
string(1) "a"
[1]=>
int(5)
}
}
int(1)
array(2) {
[0]=>
array(2) {
[0]=>
string(2) "ax"
[1]=>
int(5)
}
[1]=>
array(2) {
[0]=>
string(1) "a"
[1]=>
int(5)
}
}
int(1)
array(6) {
[0]=>
array(2) {
[0]=>
string(4) "zxax"
[1]=>
int(3)
}
["capt1"]=>
array(2) {
[0]=>
string(1) "z"
[1]=>
int(3)
}
[1]=>
array(2) {
[0]=>
string(1) "z"
[1]=>
int(3)
}
[2]=>
array(2) {
[0]=>
string(1) "x"
[1]=>
int(4)
}
["letsmix"]=>
array(2) {
[0]=>
string(2) "ax"
[1]=>
int(5)
}
[3]=>
array(2) {
[0]=>
string(2) "ax"
[1]=>
int(5)
}
}

View File

@ -0,0 +1,22 @@
--TEST--
A (PCRE_ANCHORED) modififer
--FILE--
<?php
var_dump(preg_match('/\PN+/', '123abc', $m));
var_dump($m);
var_dump(preg_match('/\P{N}+/A', '123abc'));
var_dump(preg_match('/^\P{N}+/', '123abc'));
var_dump(preg_match('/^\P{N}+/A', '123abc'));
?>
--EXPECT--
int(1)
array(1) {
[0]=>
string(3) "abc"
}
int(0)
int(0)
int(0)

View File

@ -0,0 +1,29 @@
--TEST--
x (PCRE_EXTENDED) modififer
--FILE--
<?php
var_dump(preg_match('/a e i o u/', 'aeiou', $m));
var_dump($m);
var_dump(preg_match('/a e i o u/x', 'aeiou', $m));
var_dump($m);
var_dump(preg_match("/a e\ni\to\ru/x", 'aeiou', $m));
var_dump($m);
?>
--EXPECT--
int(0)
array(0) {
}
int(1)
array(1) {
[0]=>
string(5) "aeiou"
}
int(1)
array(1) {
[0]=>
string(5) "aeiou"
}

View File

@ -0,0 +1,14 @@
--TEST--
X (PCRE_EXTRA) modififer
--FILE--
<?php
var_dump(preg_match('/\y/', '\y'));
var_dump(preg_match('/\y/X', '\y'));
?>
--EXPECTF--
int(1)
Warning: preg_match(): Compilation failed: unrecognized character follows \ at offset 1 in %spcre_extra.php on line 4
bool(false)

View File

@ -0,0 +1,31 @@
--TEST--
U (PCRE_UNGREEDY) modififer
--FILE--
<?php
var_dump(preg_match('/<.*>/', '<aa> <bb> <cc>', $m));
var_dump($m);
var_dump(preg_match('/<.*>/U', '<aa> <bb> <cc>', $m));
var_dump($m);
var_dump(preg_match('/(?U)<.*>/', '<aa> <bb> <cc>', $m));
var_dump($m);
?>
--EXPECT--
int(1)
array(1) {
[0]=>
string(14) "<aa> <bb> <cc>"
}
int(1)
array(1) {
[0]=>
string(4) "<aa>"
}
int(1)
array(1) {
[0]=>
string(4) "<aa>"
}