Annotation of embedaddon/php/ext/standard/tests/array/natcasesort_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test natcasesort() function : usage variations - Pass arrays of different data types
                      3: --FILE--
                      4: <?php
                      5: 
                      6: /* Prototype  : bool natcasesort(array &$array_arg)
                      7:  * Description: Sort an array using case-insensitive natural sort
                      8:  * Source code: ext/standard/array.c
                      9:  */
                     10: 
                     11: /*
                     12:  * Pass arrays of different data types to natcasesort() to test how they are sorted
                     13:  */
                     14: 
                     15: echo "*** Testing natcasesort() : usage variation ***\n";
                     16: 
                     17: //get an unset variable
                     18: $unset_var = 10;
                     19: unset ($unset_var);
                     20: 
                     21: // get a class
                     22: class classA
                     23: {
                     24:   public function __toString() {
                     25:     return "Class A object";
                     26:   }
                     27: }
                     28: 
                     29: // heredoc string
                     30: $heredoc = <<<EOT
                     31: hello world
                     32: EOT;
                     33: 
                     34: // get a resource variable
                     35: $fp = fopen(__FILE__, "r");
                     36: 
                     37: // arrays of different data types to be passed to $array_arg argument
                     38: $inputs = array(
                     39: 
                     40:        // int data
                     41: /*1*/  'int' => array(
                     42:           0,
                     43:        1,
                     44:        12345,
                     45:        -2345,
                     46:        ),
                     47: 
                     48:        // float data
                     49: /*2*/  'float' => array(
                     50:        10.5,
                     51:        -10.5,
                     52:        12.3456789000e10,
                     53:        12.3456789000E-10,
                     54:        .5,
                     55:        ),
                     56: 
                     57:        // null data
                     58: /*3*/ 'null' => array(
                     59:        NULL,
                     60:        null,
                     61:        ),
                     62: 
                     63:        // boolean data
                     64: /*4*/ 'bool' => array(
                     65:        true,
                     66:        false,
                     67:        TRUE,
                     68:        FALSE,
                     69:        ),
                     70:        
                     71:        // empty data
                     72: /*5*/ 'empty string' => array(
                     73:        "",
                     74:        '',
                     75:        ),
                     76:        
                     77: /*6*/ 'empty array' => array(
                     78:        ),
                     79: 
                     80:        // string data
                     81: /*7*/ 'string' => array(
                     82:        "string",
                     83:        'string',
                     84:        $heredoc,
                     85:        ),
                     86:        
                     87:        // object data
                     88: /*8*/ 'object' => array(
                     89:        new classA(),
                     90:        ),
                     91: 
                     92:        // undefined data
                     93: /*9*/ 'undefined' => array(
                     94:        @$undefined_var,
                     95:        ),
                     96: 
                     97:        // unset data
                     98: /*10*/ 'unset' => array(
                     99:        @$unset_var,
                    100:        ),
                    101: 
                    102:        // resource variable
                    103: /*11*/ 'resource' => array(
                    104:        $fp
                    105:        ),
                    106: );
                    107: // loop through each element of $inputs to check the behavior of natcasesort()
                    108: $iterator = 1;
                    109: foreach($inputs as $input) {
                    110:        echo "\n-- Iteration $iterator --\n";
                    111:        var_dump( natcasesort($input) );
                    112:        var_dump($input);
                    113:        $iterator++;
                    114: };
                    115: 
                    116: fclose($fp);
                    117: 
                    118: echo "Done";
                    119: ?>
                    120: 
                    121: --EXPECTF--
                    122: *** Testing natcasesort() : usage variation ***
                    123: 
                    124: -- Iteration 1 --
                    125: bool(true)
                    126: array(4) {
                    127:   [3]=>
                    128:   int(-2345)
                    129:   [0]=>
                    130:   int(0)
                    131:   [1]=>
                    132:   int(1)
                    133:   [2]=>
                    134:   int(12345)
                    135: }
                    136: 
                    137: -- Iteration 2 --
                    138: bool(true)
                    139: array(5) {
                    140:   [1]=>
                    141:   float(-10.5)
                    142:   [4]=>
                    143:   float(0.5)
                    144:   [3]=>
                    145:   float(1.23456789E-9)
                    146:   [0]=>
                    147:   float(10.5)
                    148:   [2]=>
                    149:   float(123456789000)
                    150: }
                    151: 
                    152: -- Iteration 3 --
                    153: bool(true)
                    154: array(2) {
                    155:   [1]=>
                    156:   NULL
                    157:   [0]=>
                    158:   NULL
                    159: }
                    160: 
                    161: -- Iteration 4 --
                    162: bool(true)
                    163: array(4) {
                    164:   [3]=>
                    165:   bool(false)
                    166:   [1]=>
                    167:   bool(false)
                    168:   [0]=>
                    169:   bool(true)
                    170:   [2]=>
                    171:   bool(true)
                    172: }
                    173: 
                    174: -- Iteration 5 --
                    175: bool(true)
                    176: array(2) {
                    177:   [1]=>
                    178:   string(0) ""
                    179:   [0]=>
                    180:   string(0) ""
                    181: }
                    182: 
                    183: -- Iteration 6 --
                    184: bool(true)
                    185: array(0) {
                    186: }
                    187: 
                    188: -- Iteration 7 --
                    189: bool(true)
                    190: array(3) {
                    191:   [2]=>
                    192:   string(11) "hello world"
                    193:   [1]=>
                    194:   string(6) "string"
                    195:   [0]=>
                    196:   string(6) "string"
                    197: }
                    198: 
                    199: -- Iteration 8 --
                    200: bool(true)
                    201: array(1) {
                    202:   [0]=>
                    203:   object(classA)#%d (0) {
                    204:   }
                    205: }
                    206: 
                    207: -- Iteration 9 --
                    208: bool(true)
                    209: array(1) {
                    210:   [0]=>
                    211:   NULL
                    212: }
                    213: 
                    214: -- Iteration 10 --
                    215: bool(true)
                    216: array(1) {
                    217:   [0]=>
                    218:   NULL
                    219: }
                    220: 
                    221: -- Iteration 11 --
                    222: bool(true)
                    223: array(1) {
                    224:   [0]=>
                    225:   resource(%d) of type (stream)
                    226: }
                    227: Done

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