Annotation of embedaddon/php/ext/standard/tests/strings/vsprintf_variation11.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test vsprintf() function : usage variations - octal formats with octal 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 octal formats and octal values are passed to
                     16:  * the '$format' and '$args' arguments of the function
                     17: */
                     18: 
                     19: echo "*** Testing vsprintf() : octal formats with octal values ***\n";
                     20: 
                     21: // defining array of octal formats
                     22: $formats = array(
                     23:   "%o",
                     24:   "%+o %-o %O",
                     25:   "%lo %Lo, %4o %-4o",
                     26:   "%10.4o %-10.4o %04o %04.4o",
                     27:   "%'#2o %'2o %'$2o %'_2o",
                     28:   "%o %o %o %o",
                     29:   "%% %%o %10 o%",
                     30:   '%3$o %4$o %1$o %2$o'
                     31: );
                     32: 
                     33: // Arrays of octal values for the format defined in $format.
                     34: // Each sub array contains octal values which correspond to each format string in $format
                     35: $args_array = array(
                     36:   array(00),
                     37:   array(-01, 01, +022),
                     38:   array(-020000000000, 020000000000, 017777777777, -017777777777),
                     39:   array(0123456, 012345678, -01234567, 01234567),
                     40:   array(0111, 02222, -0333333, -044444444),
                     41:   array(0x123b, 0xfAb, 0123, 01293),
                     42:   array(01234, 05678, -01234, 02345),
                     43:   array(03, 04, 01, 02)
                     44: 
                     45: );
                     46: 
                     47: // looping to test vsprintf() with different octal formats from the above $formats array
                     48: // and with octal values from the above $args_array array
                     49: $counter = 1;
                     50: foreach($formats as $format) {
                     51:   echo "\n-- Iteration $counter --\n";   
                     52:   var_dump( vsprintf($format, $args_array[$counter-1]) );
                     53:   $counter++;
                     54: }
                     55: 
                     56: echo "Done";
                     57: ?>
                     58: 
                     59: --EXPECTF--
                     60: *** Testing vsprintf() : octal formats with octal values ***
                     61: 
                     62: -- Iteration 1 --
                     63: string(1) "0"
                     64: 
                     65: -- Iteration 2 --
                     66: string(14) "37777777777 1 "
                     67: 
                     68: -- Iteration 3 --
                     69: string(38) "20000000000 o, 17777777777 20000000001"
                     70: 
                     71: -- Iteration 4 --
                     72: string(38) "                      37776543211 0000"
                     73: 
                     74: -- Iteration 5 --
                     75: string(32) "111 2222 37777444445 37733333334"
                     76: 
                     77: -- Iteration 6 --
                     78: string(17) "11073 7653 123 12"
                     79: 
                     80: -- Iteration 7 --
                     81: string(6) "% %o o"
                     82: 
                     83: -- Iteration 8 --
                     84: string(7) "1 2 3 4"
                     85: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>