PageRenderTime 37ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 76 lines | 46 code | 13 blank | 17 comment | 1 complexity | 48cad247b29c0678711e4cb03edda3cf 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 string formats and string values are passed to
  8. * the '$format' and '$args' arguments of the function
  9. */
  10. <<__EntryPoint>> function main(): void {
  11. echo "*** Testing vfprintf() : string formats with strings ***\n";
  12. // defining different heredoc strings
  13. $heredoc_string = <<<EOT
  14. This is string defined
  15. using heredoc.
  16. EOT;
  17. /* heredoc string with only numerics */
  18. $heredoc_numeric_string = <<<EOT
  19. 123456 3993
  20. 4849 string
  21. EOT;
  22. /* empty heardoc string */
  23. $heredoc_empty_string = <<<EOT
  24. EOT;
  25. // defining array of string formats
  26. $formats = varray[
  27. "%s",
  28. "%+s %-s %S",
  29. "%ls %Ls, %4s %-4s",
  30. "%10.4s %-10.4s %04s %04.4s",
  31. "%'#2s %'2s %'$2s %'_2s",
  32. "%% %%s %10 s%",
  33. '%3$s %4$s %1$s %2$s'
  34. ];
  35. // Arrays of string values for the format defined in $format.
  36. // Each sub array contains string values which correspond to each format string in $format
  37. $args_array = varray[
  38. varray[" "],
  39. varray["hello\0world", "hello\0", "\0hello"],
  40. varray["@#$%&*", "@#$%&*", "\x55F", "\001"],
  41. varray["sunday", 'monday', "tuesday", 'wednesday'],
  42. varray[$heredoc_string, "abcdef", $heredoc_numeric_string, $heredoc_empty_string],
  43. varray["one", "two", 'three', 'four'],
  44. varray["three", 'four', 'one', "two"]
  45. ];
  46. /* creating dumping file */
  47. $data_file = dirname(__FILE__) . '/vfprintf_variation7.txt';
  48. if (!($fp = fopen($data_file, 'wt')))
  49. return;
  50. // looping to test vfprintf() with different string formats from the above $format array
  51. // and with string from the above $args_array array
  52. $counter = 1;
  53. foreach($formats as $format) {
  54. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  55. vfprintf($fp, $format, $args_array[$counter-1]);
  56. $counter++;
  57. }
  58. fclose($fp);
  59. print_r(file_get_contents($data_file));
  60. echo "\n";
  61. unlink($data_file);
  62. echo "===DONE===\n";
  63. }