Annotation of embedaddon/php/ext/standard/tests/strings/trim1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test trim() function
! 3: --FILE--
! 4: <?php
! 5:
! 6: /* Prototype: string trim( string str [,string charlist] )
! 7: * Strip whitespace (or other characters) from the beginning and end of a string.
! 8: */
! 9:
! 10: /* trim with unset/null/boolean variable - retuns an empty string */
! 11: echo "\n";
! 12: $null_var = NULL;
! 13: var_dump( trim($null_var) );
! 14: $null_var = "";
! 15: var_dump( trim($null_var) );
! 16: $null_var = 0;
! 17: var_dump( trim($null_var) );
! 18: $bool_val = true;
! 19: var_dump( trim($null_var) );
! 20:
! 21: /* second arguemnt charlist as null - does not trim any white spaces */
! 22: var_dump( trim("\ttesting trim", "") );
! 23: var_dump( trim(" \ttesting trim ", NULL) );
! 24: var_dump( trim("\ttesting trim ", true) );
! 25:
! 26: /* Testing error conditions */
! 27: echo "\n*** Testing error conditions ***\n";
! 28:
! 29: //Zero arguments
! 30: var_dump( trim() );
! 31: // More than expected number of args */
! 32: var_dump( trim("\tstring\n", "\t\n", $null_var) );
! 33: var_dump( trim(NULL, "", NULL ) );
! 34:
! 35:
! 36: /* Use of class and objects */
! 37: echo "\n*** Testing with OBJECTS ***\n";
! 38: class string1
! 39: {
! 40: public function __toString() {
! 41: return "Object";
! 42: }
! 43: }
! 44: $obj = new string1;
! 45: var_dump( trim($obj, "Ot") );
! 46:
! 47: /* String with embedded NULL */
! 48: echo "\n*** Testing with String with embedded NULL ***\n";
! 49: var_dump( trim("\x0n1234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
! 50:
! 51: /* heredoc string */
! 52: $str = <<<EOD
! 53: us
! 54: ing heredoc string
! 55: EOD;
! 56:
! 57: echo "\n*** Testing with heredoc string ***\n";
! 58: var_dump( trim($str, "us\ning") );
! 59:
! 60: echo "\nDone";
! 61: ?>
! 62: --EXPECTF--
! 63:
! 64: string(0) ""
! 65: string(0) ""
! 66: string(1) "0"
! 67: string(1) "0"
! 68: string(13) " testing trim"
! 69: string(17) " testing trim "
! 70: string(15) " testing trim "
! 71:
! 72: *** Testing error conditions ***
! 73:
! 74: Warning: trim() expects at least 1 parameter, 0 given in %s on line %d
! 75: NULL
! 76:
! 77: Warning: trim() expects at most 2 parameters, 3 given in %s on line %d
! 78: NULL
! 79:
! 80: Warning: trim() expects at most 2 parameters, 3 given in %s on line %d
! 81: NULL
! 82:
! 83: *** Testing with OBJECTS ***
! 84: string(4) "bjec"
! 85:
! 86: *** Testing with String with embedded NULL ***
! 87: string(22) "234 05678 00efgh\xijkl"
! 88:
! 89: *** Testing with heredoc string ***
! 90: string(12) " heredoc str"
! 91:
! 92: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>