Annotation of embedaddon/php/ext/json/tests/json_decode_basic.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test json_decode() function : basic functionality
                      3: --SKIPIF--
                      4: <?php
                      5: if (!extension_loaded("json")) {
                      6:        die('skip JSON extension not available in this build');
                      7: }       
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11: /* Prototype  : mixed json_decode  ( string $json  [, bool $assoc  ] )
                     12:  * Description: Decodes a JSON string
                     13:  * Source code: ext/json/php_json.c
                     14:  * Alias to functions: 
                     15:  */
                     16: echo "*** Testing json_decode() : basic functionality ***\n";
                     17: 
                     18: // array with different values for $string
                     19: $inputs =  array (
                     20:                '0',
                     21:                '123',
                     22:                '-123',
                     23:                '2147483647',
                     24:                '-2147483648',
                     25:                '123.456',
                     26:                '1230',
                     27:                '-1230',
                     28:                'true',
                     29:                'false',
                     30:                'null',
                     31:                '"abc"',
                     32:                '"Hello World\r\n"',
                     33:                '[]',
                     34:                '[1,2,3,4,5]',
                     35:                '{"myInt":99,"myFloat":123.45,"myNull":null,"myBool":true,"myString":"Hello World"}',
                     36:                '{"Jan":31,"Feb":29,"Mar":31,"April":30,"May":31,"June":30}',
                     37:                '""',
                     38:                '{}'
                     39: );  
                     40: 
                     41: // loop through with each element of the $inputs array to test json_decode() function
                     42: $count = 1;
                     43: foreach($inputs as $input) {
                     44:   echo "-- Iteration $count --\n";     
                     45:   var_dump(json_decode($input)); 
                     46:    var_dump(json_decode($input, TRUE)); 
                     47:   $count ++;
                     48: }
                     49: 
                     50: ?>
                     51: ===Done===
                     52: --EXPECTF-- 
                     53: *** Testing json_decode() : basic functionality ***
                     54: -- Iteration 1 --
                     55: int(0)
                     56: int(0)
                     57: -- Iteration 2 --
                     58: int(123)
                     59: int(123)
                     60: -- Iteration 3 --
                     61: int(-123)
                     62: int(-123)
                     63: -- Iteration 4 --
                     64: int(2147483647)
                     65: int(2147483647)
                     66: -- Iteration 5 --
                     67: int(-2147483648)
                     68: int(-2147483648)
                     69: -- Iteration 6 --
                     70: float(123.456)
                     71: float(123.456)
                     72: -- Iteration 7 --
                     73: int(1230)
                     74: int(1230)
                     75: -- Iteration 8 --
                     76: int(-1230)
                     77: int(-1230)
                     78: -- Iteration 9 --
                     79: bool(true)
                     80: bool(true)
                     81: -- Iteration 10 --
                     82: bool(false)
                     83: bool(false)
                     84: -- Iteration 11 --
                     85: NULL
                     86: NULL
                     87: -- Iteration 12 --
                     88: string(3) "abc"
                     89: string(3) "abc"
                     90: -- Iteration 13 --
                     91: string(13) "Hello World
                     92: "
                     93: string(13) "Hello World
                     94: "
                     95: -- Iteration 14 --
                     96: array(0) {
                     97: }
                     98: array(0) {
                     99: }
                    100: -- Iteration 15 --
                    101: array(5) {
                    102:   [0]=>
                    103:   int(1)
                    104:   [1]=>
                    105:   int(2)
                    106:   [2]=>
                    107:   int(3)
                    108:   [3]=>
                    109:   int(4)
                    110:   [4]=>
                    111:   int(5)
                    112: }
                    113: array(5) {
                    114:   [0]=>
                    115:   int(1)
                    116:   [1]=>
                    117:   int(2)
                    118:   [2]=>
                    119:   int(3)
                    120:   [3]=>
                    121:   int(4)
                    122:   [4]=>
                    123:   int(5)
                    124: }
                    125: -- Iteration 16 --
                    126: object(stdClass)#%d (5) {
                    127:   ["myInt"]=>
                    128:   int(99)
                    129:   ["myFloat"]=>
                    130:   float(123.45)
                    131:   ["myNull"]=>
                    132:   NULL
                    133:   ["myBool"]=>
                    134:   bool(true)
                    135:   ["myString"]=>
                    136:   string(11) "Hello World"
                    137: }
                    138: array(5) {
                    139:   ["myInt"]=>
                    140:   int(99)
                    141:   ["myFloat"]=>
                    142:   float(123.45)
                    143:   ["myNull"]=>
                    144:   NULL
                    145:   ["myBool"]=>
                    146:   bool(true)
                    147:   ["myString"]=>
                    148:   string(11) "Hello World"
                    149: }
                    150: -- Iteration 17 --
                    151: object(stdClass)#%d (6) {
                    152:   ["Jan"]=>
                    153:   int(31)
                    154:   ["Feb"]=>
                    155:   int(29)
                    156:   ["Mar"]=>
                    157:   int(31)
                    158:   ["April"]=>
                    159:   int(30)
                    160:   ["May"]=>
                    161:   int(31)
                    162:   ["June"]=>
                    163:   int(30)
                    164: }
                    165: array(6) {
                    166:   ["Jan"]=>
                    167:   int(31)
                    168:   ["Feb"]=>
                    169:   int(29)
                    170:   ["Mar"]=>
                    171:   int(31)
                    172:   ["April"]=>
                    173:   int(30)
                    174:   ["May"]=>
                    175:   int(31)
                    176:   ["June"]=>
                    177:   int(30)
                    178: }
                    179: -- Iteration 18 --
                    180: string(0) ""
                    181: string(0) ""
                    182: -- Iteration 19 --
                    183: object(stdClass)#%d (0) {
                    184: }
                    185: array(0) {
                    186: }
                    187: ===Done===

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