php-src/ext/standard/tests/general_functions/001.phpt
Stig Bakken 315f4f5658 @PHP 3 regression testing framework re-born (Stig)
Took the old PHP 3 regression testing framework and rewrote it in PHP.
Should work on both Windows and UNIX, however I have not tested it on
Windows.  See tests/README for how to write tests.  Added the PHP 3
tests and converted most of them.
2000-08-27 19:46:06 +00:00

56 lines
1.1 KiB
PHP

--TEST--
sprintf() function
--POST--
--GET--
--FILE--
<?php
$agent = sprintf("%.5s", "James Bond, 007");
echo("sprintf string truncate test: ");
if ($agent == "James") {
echo("passed\n");
} else {
echo("failed!\n");
}
echo("sprintf padding and align test: ");
$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
if ($test == "abc0020 fisketur !") {
echo("passed\n");
} else {
echo("failed!\n");
}
echo("sprintf octal and hex test: ");
$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
if ($test == " 200 400 BFFF 0034c385") {
echo("passed\n");
} else {
echo("failed!\n");
}
echo("sprintf octal binary test: ");
$test = sprintf("%b", 3457925);
if ($test == "1101001100001110000101") {
echo("passed\n");
} else {
echo("failed!\n");
}
echo("sprintf float test: ");
$test = sprintf("%0"."06.2f", 10000/3.0);
if ($test == "003333.33") {
echo("passed\n");
} else {
echo("failed!\n");
}
?>
--EXPECT--
sprintf string truncate test: passed
sprintf padding and align test: passed
sprintf octal and hex test: passed
sprintf octal binary test: passed
sprintf float test: passed