Return to vsprintf_variation4.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test vsprintf() function : usage variations - int formats with non-integer values 3: --SKIPIF-- 4: <?php 5: if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); 6: ?> 7: --FILE-- 8: <?php 9: /* Prototype : string vsprintf(string format, array args) 10: * Description: Return a formatted string 11: * Source code: ext/standard/formatted_print.c 12: */ 13: 14: /* 15: * Test vsprintf() when different int formats and non-int values are passed to 16: * the '$format' and '$args' arguments of the function 17: */ 18: 19: echo "*** Testing vsprintf() : int formats and non-integer values ***\n"; 20: 21: // defining array of int formats 22: $formats = 23: '%d %+d %-d 24: %ld %Ld %4d %-4d 25: %10.4d %-10.4d %.4d %04.4d 26: %\'#2d %\'2d %\'$2d %\'_2d 27: %3$d %4$d %1$d %2$d'; 28: 29: // Arrays of non int values for the format defined in $format. 30: // Each sub array contains non int values which correspond to each format in $format 31: $args_array = array( 32: 33: // array of float values 34: array(2.2, .2, 10.2, 35: 123456.234, 123456.234, -1234.6789, +1234.6789, 36: 2e10, +2e5, 4e3, 22e+6, 37: 12345.780, 12.000000011111, -12.00000111111, -123456.234, 38: 3.33, +4.44, 1.11,-2.22 ), 39: 40: // array of strings 41: array(" ", ' ', 'hello', 42: '123hello', "123hello", '-123hello', '+123hello', 43: "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello', 44: "1234hello", "hello\0world", "NULL", "true", 45: "3", "4", '1', '2'), 46: 47: // different arrays 48: array( array(0), array(1, 2), array(-1, -1), 49: array("123"), array('123'), array('-123'), array("-123"), 50: array(true), array(false), array(TRUE), array(FALSE), 51: array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"), 52: array("3"), array("4"), array("1"), array("2") ), 53: 54: // array of boolean data 55: array( true, TRUE, false, 56: TRUE, 0, FALSE, 1, 57: true, false, TRUE, FALSE, 58: 0, 1, 1, 0, 59: 1, TRUE, 0, FALSE), 60: 61: ); 62: 63: // looping to test vsprintf() with different int formats from the above $format array 64: // and with non-int values from the above $args_array array 65: $counter = 1; 66: foreach($args_array as $args) { 67: echo "\n-- Iteration $counter --\n"; 68: var_dump( vsprintf($formats, $args) ); 69: $counter++; 70: } 71: 72: echo "Done"; 73: ?> 74: --EXPECTF-- 75: *** Testing vsprintf() : int formats and non-integer values *** 76: 77: -- Iteration 1 -- 78: string(112) "2 +0 10 79: 123456 d -1234 1234 80: -1474836480 200000 4000 22000000 81: 12345 12 -12 -123456 82: 10 123456 2 0" 83: 84: -- Iteration 2 -- 85: string(92) "0 +0 0 86: 123 d -123 123 87: 0 0 123456 0000 88: 1234 0 $0 _0 89: 0 123 0 0" 90: 91: -- Iteration 3 -- 92: string(81) "1 +1 1 93: 1 d 1 1 94: 1 1 1 0001 95: #1 1 $1 _1 96: 1 1 1 1" 97: 98: -- Iteration 4 -- 99: string(81) "1 +1 0 100: 1 d 0 1 101: 1 0 1 0000 102: #0 1 $1 _0 103: 0 1 1 1" 104: Done