mirror of
https://github.com/php/php-src.git
synced 2026-04-23 07:58:20 +02:00
120 lines
3.0 KiB
PHP
120 lines
3.0 KiB
PHP
--TEST--
|
|
Test str_repeat() function
|
|
--INI--
|
|
precision=14
|
|
--FILE--
|
|
<?php
|
|
/* Prototype: string str_repeat ( string $input, int $multiplier );
|
|
Description: Returns input repeated multiplier times. multiplier has to be
|
|
greater than or equal to 0. If the multiplier is set to 0, the function
|
|
will return an empty string.
|
|
*/
|
|
|
|
echo "*** Testing str_repeat() with possible strings ***";
|
|
$variations = array(
|
|
'a',
|
|
'foo',
|
|
'barbazbax',
|
|
"\x00",
|
|
'\0',
|
|
NULL,
|
|
TRUE,
|
|
4,
|
|
1.23,
|
|
"",
|
|
" "
|
|
);
|
|
|
|
/* variations in string and multiplier as an int */
|
|
foreach($variations as $input) {
|
|
echo "\n--- str_repeat() of '$input' ---\n" ;
|
|
for($n=0; $n<4; $n++) {
|
|
echo "-- after repeating $n times is => ";
|
|
echo str_repeat($input, $n)."\n";
|
|
}
|
|
}
|
|
|
|
echo "\n\n*** Testing error conditions ***\n";
|
|
try {
|
|
str_repeat($input[0], -1); // Invalid arg for multiplier
|
|
} catch (\Error $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
|
|
?>
|
|
|
|
DONE
|
|
--EXPECT--
|
|
*** Testing str_repeat() with possible strings ***
|
|
--- str_repeat() of 'a' ---
|
|
-- after repeating 0 times is =>
|
|
-- after repeating 1 times is => a
|
|
-- after repeating 2 times is => aa
|
|
-- after repeating 3 times is => aaa
|
|
|
|
--- str_repeat() of 'foo' ---
|
|
-- after repeating 0 times is =>
|
|
-- after repeating 1 times is => foo
|
|
-- after repeating 2 times is => foofoo
|
|
-- after repeating 3 times is => foofoofoo
|
|
|
|
--- str_repeat() of 'barbazbax' ---
|
|
-- after repeating 0 times is =>
|
|
-- after repeating 1 times is => barbazbax
|
|
-- after repeating 2 times is => barbazbaxbarbazbax
|
|
-- after repeating 3 times is => barbazbaxbarbazbaxbarbazbax
|
|
|
|
--- str_repeat() of ' |