PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/vfprintf_variation17.php

http://github.com/facebook/hiphop-php
PHP | 53 lines | 32 code | 7 blank | 14 comment | 1 complexity | ef122cd5812f9be9bec92c6b8a8049e6 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
  3. * Description: Write a formatted string to a stream
  4. * Source code: ext/standard/formatted_print.c
  5. */
  6. /*
  7. * Test vfprintf() when different scientific formats and scientific values
  8. * are passed to the '$format' and '$args' arguments of the function
  9. */
  10. <<__EntryPoint>> function main(): void {
  11. echo "*** Testing vfprintf() : scientific formats and scientific values ***\n";
  12. // defining array of scientific formats
  13. $formats = varray[
  14. '%e %+e %-e',
  15. '%le %Le %4e %-4e',
  16. '%10.4e %-10.4e %.4e',
  17. '%\'#20e %\'20e %\'$20e %\'_20e',
  18. '%3$e %4$e %1$e %2$e'
  19. ];
  20. // Arrays of scientific values for the format defined in $format.
  21. // Each sub array contains scientific values which correspond to each format string in $format
  22. $args_array = varray[
  23. varray[0, 1e0, "10e2" ],
  24. varray[2.2e2, 10e10, 1000e-2, 1000e7],
  25. varray[-22e12, 10e20, 1.2e2],
  26. varray[1e1, +1e2, -1e3, "1e2_"],
  27. varray[3e3, 4e3, 1e3, 2e3]
  28. ];
  29. /* creating dumping file */
  30. $data_file = dirname(__FILE__) . '/vfprintf_variation17.txt';
  31. if (!($fp = fopen($data_file, 'wt')))
  32. return;
  33. // looping to test vfprintf() with different scientific formats from the above $format array
  34. // and with signed and other types of values from the above $args_array array
  35. $counter = 1;
  36. foreach($formats as $format) {
  37. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  38. vfprintf($fp, $format, $args_array[$counter-1]);
  39. $counter++;
  40. }
  41. fclose($fp);
  42. print_r(file_get_contents($data_file));
  43. echo "\n";
  44. unlink($data_file);
  45. echo "===DONE===\n";
  46. }