Annotation of embedaddon/php/ext/standard/tests/general_functions/001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: sprintf() function
! 3: --FILE--
! 4: <?php
! 5:
! 6: $agent = sprintf("%.5s", "James Bond, 007");
! 7:
! 8: echo("sprintf string truncate test: ");
! 9: if ($agent == "James") {
! 10: echo("passed\n");
! 11: } else {
! 12: echo("failed!\n");
! 13: }
! 14:
! 15: echo("sprintf padding and align test: ");
! 16: $test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
! 17: if ($test == "abc0020 fisketur !") {
! 18: echo("passed\n");
! 19: } else {
! 20: echo("failed!\n");
! 21: }
! 22:
! 23: echo("sprintf octal and hex test: ");
! 24: $test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
! 25: if ($test == " 200 400 BFFF 0034c385") {
! 26: echo("passed\n");
! 27: } else {
! 28: echo("failed!\n");
! 29: }
! 30:
! 31: echo("sprintf octal binary test: ");
! 32: $test = sprintf("%b", 3457925);
! 33: if ($test == "1101001100001110000101") {
! 34: echo("passed\n");
! 35: } else {
! 36: echo("failed!\n");
! 37: }
! 38:
! 39: echo("sprintf float test: ");
! 40: $test = sprintf("%0"."06.2f", 10000/3.0);
! 41: if ($test == "003333.33") {
! 42: echo("passed\n");
! 43: } else {
! 44: echo("failed!\n");
! 45: }
! 46:
! 47: echo sprintf("%.2f\n", "99.00");
! 48: echo sprintf("%.2f\n", 99.00);
! 49:
! 50: echo sprintf("%e\n", 1.234E-18);
! 51: echo sprintf("%e\n", 1.234E+18);
! 52: echo sprintf("%e\n", 9843243.12);
! 53: echo sprintf("%e\n", -9843243.12);
! 54:
! 55: ?>
! 56: --EXPECT--
! 57: sprintf string truncate test: passed
! 58: sprintf padding and align test: passed
! 59: sprintf octal and hex test: passed
! 60: sprintf octal binary test: passed
! 61: sprintf float test: passed
! 62: 99.00
! 63: 99.00
! 64: 1.234000e-18
! 65: 1.234000e+18
! 66: 9.843243e+6
! 67: -9.843243e+6
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>