PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/strings/str_repeat.php

http://github.com/facebook/hiphop-php
PHP | 58 lines | 42 code | 8 blank | 8 comment | 1 complexity | e5631052371a0fff8fa0f1a48e2bc8da 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. <?php
  2. /* Prototype: string str_repeat ( string $input, int $multiplier );
  3. Description: Returns input repeated multiplier times. multiplier has to be
  4. greater than or equal to 0. If the multiplier is set to 0, the function
  5. will return an empty string.
  6. */
  7. echo "*** Testing str_repeat() with possible strings ***";
  8. $variations = array(
  9. 'a',
  10. 'foo',
  11. 'barbazbax',
  12. "\x00",
  13. '\0',
  14. NULL,
  15. TRUE,
  16. 4,
  17. 1.23,
  18. "",
  19. " "
  20. );
  21. /* variations in string and multiplier as an integer */
  22. foreach($variations as $input) {
  23. echo "\n--- str_repeat() of '$input' ---\n" ;
  24. for($n=0; $n<4; $n++) {
  25. echo "-- after repeating $n times is => ";
  26. echo str_repeat($input, $n)."\n";
  27. }
  28. }
  29. /* variations in multiplier as well as string to be repeated. Same varient
  30. values are used as string to be repeated as well as multiplier */
  31. echo "\n\n*** Testing str_repeat() with various strings & multiplier value ***";
  32. foreach ( $variations as $input ) {
  33. echo "\n--- str_repeat() of '$input' ---\n" ;
  34. foreach ( $variations as $multiplier ) {
  35. echo "-- after repeating '$multiplier' times is => ";
  36. var_dump( str_repeat($input, $multiplier) );
  37. }
  38. }
  39. echo "\n*** Testing str_repeat() with complex strings containing
  40. other than 7-bit chars ***\n";
  41. $str = chr(0).chr(128).chr(129).chr(234).chr(235).chr(254).chr(255);
  42. var_dump(str_repeat($str, chr(51))); // ASCII value of '3' given
  43. var_dump(str_repeat($str, 3));
  44. echo "\n\n*** Testing error conditions ***";
  45. var_dump( str_repeat() ); // Zero args
  46. var_dump( str_repeat($input[0]) ); // args < expected
  47. var_dump( str_repeat($input[0], 3, 4) ); // args > expected
  48. var_dump( str_repeat($input[0], -1) ); // Invalid arg for multiplier
  49. echo "Done\n";
  50. ?>