vprintf_variation6.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. Test vprintf() function : usage variations - float formats with non-float values
  3. --FILE--
  4. <?php
  5. /*
  6. * Test vprintf() when different float formats and non-float values are passed to
  7. * the '$format' and '$args' arguments of the function
  8. */
  9. echo "*** Testing vprintf() : float formats and non-float values ***\n";
  10. // defining array of float formats
  11. $formats =
  12. '%f %+f %-f
  13. %lf %4f %-4f
  14. %10.4f %-10.4f %04f %04.4f
  15. %\'#2f %\'2f %\'$2f %\'_2f
  16. %3$f %4$f %1$f %2$f';
  17. // Arrays of non float values for the format defined in $format.
  18. // Each sub array contains non float values which correspond to each format in $format
  19. $args_array = array(
  20. // array of int values
  21. array(2, -2, +2,
  22. 123456, -12346789, +12346789,
  23. 123200, +20000, -40000, 22212,
  24. 12345780, 1211111, -12111111, -12345634,
  25. 3, +4, 1,-2 ),
  26. // array of strings
  27. array(" ", ' ', 'hello',
  28. '123hello', '-123hello', '+123hello',
  29. "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
  30. "1234hello", "hello\0world", "NULL", "true",
  31. "3", "4", '1', '2'),
  32. // different arrays
  33. array( array(0), array(1, 2), array(-1, -1),
  34. array("123"), array('-123'), array("-123"),
  35. array(true), array(false), array(TRUE), array(FALSE),
  36. array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
  37. array("3"), array("4"), array("1"), array("2") ),
  38. // array of boolean data
  39. array( true, TRUE, false,
  40. TRUE, FALSE, 1,
  41. true, false, TRUE, FALSE,
  42. 0, 1, 1, 0,
  43. 1, TRUE, 0, FALSE),
  44. );
  45. // looping to test vprintf() with different float formats from the above $format array
  46. // and with non-float values from the above $args_array array
  47. $counter = 1;
  48. foreach($args_array as $args) {
  49. echo "\n-- Iteration $counter --\n";
  50. $result = vprintf($formats, $args);
  51. echo "\n";
  52. var_dump($result);
  53. $counter++;
  54. }
  55. ?>
  56. --EXPECT--
  57. *** Testing vprintf() : float formats and non-float values ***
  58. -- Iteration 1 --
  59. 2.000000 -2.000000 2.000000
  60. 123456.000000 -12346789.000000 12346789.000000
  61. 123200.0000 20000.0000 -40000.000000 22212.0000
  62. 12345780.000000 1211111.000000 -12111111.000000 -12345634.000000
  63. 2.000000 123456.000000 2.000000 -2.000000
  64. int(245)
  65. -- Iteration 2 --
  66. 0.000000 +0.000000 0.000000
  67. 123.000000 -123.000000 123.000000
  68. 0.0000 0.0000 123456.000000 0.0000
  69. 1234.000000 0.000000 0.000000 0.000000
  70. 0.000000 123.000000 0.000000 0.000000
  71. int(197)
  72. -- Iteration 3 --
  73. 1.000000 +1.000000 1.000000
  74. 1.000000 1.000000 1.000000
  75. 1.0000 1.0000 1.000000 1.0000
  76. 1.000000 1.000000 1.000000 1.000000
  77. 1.000000 1.000000 1.000000 1.000000
  78. int(180)
  79. -- Iteration 4 --
  80. 1.000000 +1.000000 0.000000
  81. 1.000000 0.000000 1.000000
  82. 1.0000 0.0000 1.000000 0.0000
  83. 0.000000 1.000000 1.000000 0.000000
  84. 0.000000 1.000000 1.000000 1.000000
  85. int(180)