Annotation of embedaddon/php/ext/standard/tests/strings/vsprintf_variation8.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test vsprintf() function : usage variations - string formats with non-string values
! 3: --FILE--
! 4: <?php
! 5: /* Prototype : string vsprintf(string format, array args)
! 6: * Description: Return a formatted string
! 7: * Source code: ext/standard/formatted_print.c
! 8: */
! 9:
! 10: /*
! 11: * Test vsprintf() when different string formats and non-string values are passed to
! 12: * the '$format' and '$args' arguments of the function
! 13: */
! 14:
! 15: error_reporting(E_ALL & ~E_NOTICE);
! 16:
! 17: echo "*** Testing vsprintf() : string formats and non-string values ***\n";
! 18:
! 19: // defining array of string formats
! 20: $formats =
! 21: '%s %+s %-s
! 22: %ls %4s %-4s
! 23: %10.4s %-10.4s %04s %04.4s
! 24: %\'#2s %\'2s %\'$2s %\'_2s
! 25: %3$s %4$s %1$s %2$s';
! 26:
! 27: // Arrays of non string values for the format defined in $format.
! 28: // Each sub array contains non string values which correspond to each format in $format
! 29: $args_array = array(
! 30:
! 31: // array of float values
! 32: array(2.2, .2, 10.2,
! 33: 123456.234, -1234.6789, +1234.6789,
! 34: 2.1234567e10, +2.7654321e10, -2.7654321e10, 2.1234567e10,
! 35: 12345.780, 12.000000011111, -12.00000111111, -123456.234,
! 36: 3.33, +4.44, 1.11,-2.22 ),
! 37:
! 38: // array of int values
! 39: array(2, -2, +2,
! 40: 123456, -12346789, +12346789,
! 41: 123200, +20000, -40000, 22212,
! 42: 12345780, 1211111, -12111111, -12345634,
! 43: 3, +4, 1,-2 ),
! 44:
! 45:
! 46: // different arrays
! 47: array( array(0), array(1, 2), array(-1, -1),
! 48: array("123"), array('-123'), array("-123"),
! 49: array(true), array(false), array(TRUE), array(FALSE),
! 50: array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
! 51: array("3"), array("4"), array("1"), array("2") ),
! 52:
! 53: // array of boolean data
! 54: array( true, TRUE, false,
! 55: TRUE, FALSE, 1,
! 56: true, false, TRUE, FALSE,
! 57: 0, 1, 1, 0,
! 58: 1, TRUE, 0, FALSE),
! 59:
! 60: );
! 61:
! 62: // looping to test vsprintf() with different string formats from the above $format array
! 63: // and with non-string values from the above $args_array array
! 64: $counter = 1;
! 65: foreach($args_array as $args) {
! 66: echo "\n-- Iteration $counter --\n";
! 67: var_dump( vsprintf($formats, $args) );
! 68: $counter++;
! 69: }
! 70:
! 71: ?>
! 72: ===DONE===
! 73: --EXPECT--
! 74: *** Testing vsprintf() : string formats and non-string values ***
! 75:
! 76: -- Iteration 1 --
! 77: string(174) "2.2 0.2 10.2
! 78: 123456.234 -1234.6789 1234.6789
! 79: 2123 2765 -27654321000 2123
! 80: 12345.78 12.000000011111 -12.00000111111 -123456.234
! 81: 10.2 123456.234 2.2 0.2"
! 82:
! 83: -- Iteration 2 --
! 84: string(130) "2 -2 2
! 85: 123456 -12346789 12346789
! 86: 1232 2000 -40000 2221
! 87: 12345780 1211111 -12111111 -12345634
! 88: 2 123456 2 -2"
! 89:
! 90: -- Iteration 3 --
! 91: string(129) "Array Array Array
! 92: Array Array Array
! 93: Arra Arra Array Arra
! 94: Array Array Array Array
! 95: Array Array Array Array"
! 96:
! 97: -- Iteration 4 --
! 98: string(79) "1 1
! 99: 1 1
! 100: 1 0001 0000
! 101: #0 1 $1 _0
! 102: 1 1 1"
! 103: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>