Annotation of embedaddon/php/ext/standard/tests/strings/str_pad_variation4.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test str_pad() function : usage variations - unexpected inputs for '$pad_type' argument
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype  : string str_pad  ( string $input  , int $pad_length  [, string $pad_string  [, int $pad_type  ]] )
        !             6:  * Description: Pad a string to a certain length with another string
        !             7:  * Source code: ext/standard/string.c
        !             8: */
        !             9: 
        !            10: /* Test str_pad() function: with unexpected inputs for '$pad_type' 
        !            11:  *  and expected type for '$input', '$pad_length' and '$pad_string'
        !            12: */
        !            13: 
        !            14: echo "*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***\n";
        !            15: 
        !            16: //get an unset variable
        !            17: $unset_var = 'string_val';
        !            18: unset($unset_var);
        !            19: 
        !            20: //defining a class
        !            21: class sample  {
        !            22:   public function __toString() {
        !            23:     return "sample object";
        !            24:   } 
        !            25: }
        !            26: 
        !            27: // array with different values for $input
        !            28: $pad_types =  array (
        !            29: 
        !            30:                  // integer values
        !            31: /*1*/    0, // == STR_PAD_LEFT
        !            32:                  1, // == STR_PAD_RIGHT
        !            33:                  2, // == STR_PAD_BOTH
        !            34:                  -2, 
        !            35:                  2147483647,
        !            36:                  -2147483648,
        !            37:                        
        !            38:                  // float values
        !            39: /*7*/    10.5,
        !            40:                  -20.5,
        !            41:                  10.1234567e10,
        !            42:                  
        !            43:                  // string data
        !            44: /*10*/   "abc",
        !            45:                  "STR_PAD_LEFT",
        !            46:                  "2",
        !            47:                  "0x2",
        !            48:                  "02",
        !            49:                  
        !            50:                  // array values
        !            51: /*15*/   array(),
        !            52:                  array(0),
        !            53:                  array(1, 2),
        !            54:                
        !            55:                  // boolean values
        !            56: /*18*/   true,
        !            57:                  false,
        !            58:                  TRUE,
        !            59:                  FALSE,
        !            60:                
        !            61:                  // null vlaues
        !            62: /*22*/   NULL,
        !            63:                  null,
        !            64:                
        !            65:                  // objects
        !            66: /*24*/   new sample(),
        !            67:                
        !            68:                  // undefined variable
        !            69: /*25*/   @$undefined_var,
        !            70:                
        !            71:                  // unset variable
        !            72: /*26*/   @$unset_var
        !            73: );
        !            74: 
        !            75: //defining '$input' argument
        !            76: $input = "Test string";
        !            77: $pad_length = 20;
        !            78: $pad_string = "*";
        !            79: 
        !            80: // loop through with each element of the $pad_types array to test str_pad() function
        !            81: $count = 1;
        !            82: foreach($pad_types as $pad_type) {
        !            83:   echo "-- Iteration $count --\n";
        !            84:   var_dump( str_pad($input, $pad_length, $pad_string, $pad_type) );
        !            85:   $count ++;
        !            86: }
        !            87: 
        !            88: ?>
        !            89: ===DONE===
        !            90: --EXPECTF--
        !            91: *** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***
        !            92: -- Iteration 1 --
        !            93: string(20) "*********Test string"
        !            94: -- Iteration 2 --
        !            95: string(20) "Test string*********"
        !            96: -- Iteration 3 --
        !            97: string(20) "****Test string*****"
        !            98: -- Iteration 4 --
        !            99: 
        !           100: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           101: NULL
        !           102: -- Iteration 5 --
        !           103: 
        !           104: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           105: NULL
        !           106: -- Iteration 6 --
        !           107: 
        !           108: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           109: NULL
        !           110: -- Iteration 7 --
        !           111: 
        !           112: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           113: NULL
        !           114: -- Iteration 8 --
        !           115: 
        !           116: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           117: NULL
        !           118: -- Iteration 9 --
        !           119: 
        !           120: Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
        !           121: NULL
        !           122: -- Iteration 10 --
        !           123: 
        !           124: Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d
        !           125: NULL
        !           126: -- Iteration 11 --
        !           127: 
        !           128: Warning: str_pad() expects parameter 4 to be long, string given in %s on line %d
        !           129: NULL
        !           130: -- Iteration 12 --
        !           131: string(20) "****Test string*****"
        !           132: -- Iteration 13 --
        !           133: string(20) "****Test string*****"
        !           134: -- Iteration 14 --
        !           135: string(20) "****Test string*****"
        !           136: -- Iteration 15 --
        !           137: 
        !           138: Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
        !           139: NULL
        !           140: -- Iteration 16 --
        !           141: 
        !           142: Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
        !           143: NULL
        !           144: -- Iteration 17 --
        !           145: 
        !           146: Warning: str_pad() expects parameter 4 to be long, array given in %s on line %d
        !           147: NULL
        !           148: -- Iteration 18 --
        !           149: string(20) "Test string*********"
        !           150: -- Iteration 19 --
        !           151: string(20) "*********Test string"
        !           152: -- Iteration 20 --
        !           153: string(20) "Test string*********"
        !           154: -- Iteration 21 --
        !           155: string(20) "*********Test string"
        !           156: -- Iteration 22 --
        !           157: string(20) "*********Test string"
        !           158: -- Iteration 23 --
        !           159: string(20) "*********Test string"
        !           160: -- Iteration 24 --
        !           161: 
        !           162: Warning: str_pad() expects parameter 4 to be long, object given in %s on line %d
        !           163: NULL
        !           164: -- Iteration 25 --
        !           165: string(20) "*********Test string"
        !           166: -- Iteration 26 --
        !           167: string(20) "*********Test string"
        !           168: ===DONE===

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