rtrim.phpt 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Testing rtrim() function
  3. --FILE--
  4. <?php
  5. /* Testing for Error conditions */
  6. /* Invalid Number of Arguments */
  7. echo "\n *** Output for Error Conditions ***\n";
  8. rtrim();
  9. rtrim("", " ", 1);
  10. /* Testing the Normal behaviour of rtrim() function */
  11. echo "\n *** Output for Normal Behaviour ***\n";
  12. var_dump ( rtrim("rtrim test \t\0 ") ); /* without second Argument */
  13. var_dump ( rtrim("rtrim test " , "") ); /* no characters in second Argument */
  14. var_dump ( rtrim("rtrim test ", NULL) ); /* with NULL as second Argument */
  15. var_dump ( rtrim("rtrim test ", true) ); /* with boolean value as second Argument */
  16. var_dump ( rtrim("rtrim test ", " ") ); /* with single space as second Argument */
  17. var_dump ( rtrim("rtrim test \t\n\r\0\x0B", "\t\n\r\0\x0B") ); /* with multiple escape sequences as second Argument */
  18. var_dump ( rtrim("rtrim testABCXYZ", "A..Z") ); /* with characters range as second Argument */
  19. var_dump ( rtrim("rtrim test0123456789", "0..9") ); /* with numbers range as second Argument */
  20. var_dump ( rtrim("rtrim test$#@", "#@$") ); /* with some special characters as second Argument */
  21. /* Use of class and objects */
  22. echo "\n*** Checking with OBJECTS ***\n";
  23. class string1 {
  24. public function __toString() {
  25. return "Object";
  26. }
  27. }
  28. $obj = new string1;
  29. var_dump( rtrim($obj, "tc") );
  30. /* String with embedded NULL */
  31. echo "\n*** String with embedded NULL ***\n";
  32. var_dump( rtrim("234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
  33. /* heredoc string */
  34. $str = <<<EOD
  35. us
  36. ing heredoc string
  37. EOD;
  38. echo "\n *** Using heredoc string ***\n";
  39. var_dump( rtrim($str, "ing") );
  40. echo "Done\n";
  41. ?>
  42. --EXPECTF--
  43. *** Output for Error Conditions ***
  44. Warning: rtrim() expects at least 1 parameter, 0 given in %s on line %d
  45. Warning: rtrim() expects at most 2 parameters, 3 given in %s on line %d
  46. *** Output for Normal Behaviour ***
  47. string(10) "rtrim test"
  48. string(13) "rtrim test "
  49. string(18) "rtrim test "
  50. string(18) "rtrim test "
  51. string(10) "rtrim test"
  52. string(11) "rtrim test "
  53. string(10) "rtrim test"
  54. string(10) "rtrim test"
  55. string(10) "rtrim test"
  56. *** Checking with OBJECTS ***
  57. string(4) "Obje"
  58. *** String with embedded NULL ***
  59. string(22) "234�05678�00efgh\xijkl"
  60. *** Using heredoc string ***
  61. string(18) "us
  62. ing heredoc str"
  63. Done