Annotation of embedaddon/php/ext/standard/tests/strings/ltrim_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test ltrim() function : usage variations - test values for $str argument
                      3: --FILE--
                      4: <?php
                      5: 
                      6: /* Prototype  : string ltrim  ( string $str  [, string $charlist  ] )
                      7:  * Description: Strip whitespace (or other characters) from the beginning of a string.
                      8:  * Source code: ext/standard/string.c
                      9: */
                     10: 
                     11: echo "*** Testing ltrim() function: with unexpected inputs for 'str' argument ***\n";
                     12: 
                     13: //get an unset variable
                     14: $unset_var = '  string_val  ';
                     15: unset($unset_var);
                     16: 
                     17: //defining a class
                     18: class sample  {
                     19:   public function __toString() {
                     20:     return "  sample object  ";
                     21:   } 
                     22: }
                     23: 
                     24: //getting the resource
                     25: $file_handle = fopen(__FILE__, "r");
                     26: 
                     27: // array with different values for $input
                     28: $inputs =  array (
                     29: 
                     30:                  // integer values
                     31: /*1*/    0,
                     32:                  1,
                     33:                  255,
                     34:                  256,
                     35:              2147483647,
                     36:                  -2147483648,
                     37:                
                     38:                  // float values
                     39: /*7*/    10.5,
                     40:                  -20.5,
                     41:                  10.1234567e10,
                     42:                
                     43:                  // array values
                     44: /*10*/   array(),
                     45:                  array(0),
                     46:                  array(1, 2),
                     47:                
                     48:                  // boolean values
                     49: /*13*/   true,
                     50:                  false,
                     51:                  TRUE,
                     52:                  FALSE,
                     53:                
                     54:                  // null values
                     55: /*17*/   NULL,
                     56:                  null,
                     57:                
                     58:                  // objects
                     59: /*19*/   new sample(),
                     60:                
                     61:                  // resource
                     62: /*20*/   $file_handle,
                     63:                
                     64:                  // undefined variable
                     65: /*21*/   @$undefined_var,
                     66:                
                     67:                  // unset variable
                     68: /*22*/   @$unset_var
                     69: );
                     70: 
                     71: // loop through with each element of the $inputs array to test ltrim() function
                     72: $count = 1;
                     73: foreach($inputs as $input) {
                     74:   echo "-- Iteration $count --\n";
                     75:   // strip white space and any "minus" signs
                     76:   var_dump( ltrim($input, " \t-") );
                     77:   $count ++;
                     78: }
                     79: 
                     80: fclose($file_handle);  //closing the file handle
                     81: 
                     82: ?>
                     83: ===DONE===
                     84: --EXPECTF--
                     85: *** Testing ltrim() function: with unexpected inputs for 'str' argument ***
                     86: -- Iteration 1 --
                     87: string(1) "0"
                     88: -- Iteration 2 --
                     89: string(1) "1"
                     90: -- Iteration 3 --
                     91: string(3) "255"
                     92: -- Iteration 4 --
                     93: string(3) "256"
                     94: -- Iteration 5 --
                     95: string(10) "2147483647"
                     96: -- Iteration 6 --
                     97: string(10) "2147483648"
                     98: -- Iteration 7 --
                     99: string(4) "10.5"
                    100: -- Iteration 8 --
                    101: string(4) "20.5"
                    102: -- Iteration 9 --
                    103: string(12) "101234567000"
                    104: -- Iteration 10 --
                    105: 
                    106: Warning: ltrim() expects parameter 1 to be string, array given in %s on line %d
                    107: NULL
                    108: -- Iteration 11 --
                    109: 
                    110: Warning: ltrim() expects parameter 1 to be string, array given in %s on line %d
                    111: NULL
                    112: -- Iteration 12 --
                    113: 
                    114: Warning: ltrim() expects parameter 1 to be string, array given in %s on line %d
                    115: NULL
                    116: -- Iteration 13 --
                    117: string(1) "1"
                    118: -- Iteration 14 --
                    119: string(0) ""
                    120: -- Iteration 15 --
                    121: string(1) "1"
                    122: -- Iteration 16 --
                    123: string(0) ""
                    124: -- Iteration 17 --
                    125: string(0) ""
                    126: -- Iteration 18 --
                    127: string(0) ""
                    128: -- Iteration 19 --
                    129: string(15) "sample object  "
                    130: -- Iteration 20 --
                    131: 
                    132: Warning: ltrim() expects parameter 1 to be string, resource given in %s on line %d
                    133: NULL
                    134: -- Iteration 21 --
                    135: string(0) ""
                    136: -- Iteration 22 --
                    137: string(0) ""
                    138: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>