php-src/ext/mbstring/tests/mb_ereg_replace_basic.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

62 lines
1.8 KiB
PHP

--TEST--
Test mb_ereg_replace() function : basic
--SKIPIF--
<?php
extension_loaded('mbstring') or die('skip');
function_exists('mb_ereg_replace') or die("skip mb_ereg_replace() is not available in this build");
?>
--FILE--
<?php
/* Prototype : string mb_ereg_replace(string $pattern, string $replacement,
* string $string [, string o$ption])
* Description: Replace regular expression for multibyte string
* Source code: ext/mbstring/php_mbregex.c
*/
/*
* Test Basic Functionality of mb_ereg_replace()
*/
echo "*** Testing mb_ereg_replace() : basic functionality ***\n";
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
$string_ascii = 'abc def';
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
echo "\n-- ASCII string 1 --\n";
$result_1 = mb_ereg_replace('(.*)def', '\\1 123', $string_ascii);
var_dump(bin2hex($result_1));
echo "\n-- ASCII string 2 --\n";
$result_2 = mb_ereg_replace('123', 'abc', $string_ascii);
var_dump(bin2hex($result_2));
echo "\n-- Multibyte string 1 --\n";
$regex1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ=='); //Japanese regex in UTF-8
$result_3 = mb_ereg_replace($regex1, '\\1_____\\2', $string_mb);
var_dump(bin2hex($result_3));
echo "\n-- Multibyte string 2 --\n";
$regex2 = base64_decode('5LiW55WM');
$result_4 = mb_ereg_replace($regex2, '_____', $string_mb);
var_dump(bin2hex($result_4));
echo "Done";
?>
--EXPECT--
*** Testing mb_ereg_replace() : basic functionality ***
-- ASCII string 1 --
string(16) "6162632020313233"
-- ASCII string 2 --
string(14) "61626320646566"
-- Multibyte string 1 --
string(72) "e697a5e69cace8aa9e5f5f5f5f5f31323334efbc95efbc96efbc97efbc98efbc99e38082"
-- Multibyte string 2 --
string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
Done