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

1.1       misho       1: --TEST--
                      2: Test chr() and ord() functions
                      3: --FILE--
                      4: <?php
                      5: /* Prototype: string chr ( int $ascii );
                      6:    Description: Returns a one-character string containing the character specified by ascii. 
                      7: 
                      8:    Prototype: int ord ( string $string );
                      9:    Description: Returns the ASCII value of the first character of string
                     10: */
                     11: echo "*** Testing ord() & chr() basic operations ***\n";
                     12: for($i=0; $i<256; $i++) echo !ord(chr($i)) == $i;
                     13: 
                     14: /* miscelleous input */
                     15: echo "\n*** Testing chr() usage variations ***\n";
                     16: $arr_test = array( 
                     17:   "true", 
                     18:   "false",
                     19:   true,
                     20:   false,
                     21:   "",             
                     22:   " ",           
                     23:   "a",
                     24:   299,
                     25:   321,
                     26:   NULL,
                     27:   '\0',
                     28:   "0",
                     29:   -312, 
                     30:   12.999,
                     31:   -1.05009,
                     32:   1100011,
                     33:   "aaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddd",
                     34:   "abcd\nabcd\tabcd\0abcd\rabcdNULLabcdefgh",
                     35:   "abcd\x00abcd\x00abcd\x00abcdefghij",
                     36: );
                     37: $counter=1;
                     38: foreach($arr_test as $var){
                     39:   echo "-- Iteration $counter --\n";
                     40:   var_dump( chr($var) );
                     41:   $counter++;
                     42: }
                     43: 
                     44: echo "\n*** Testing ord() usage variations ***\n";
                     45: $counter=1;
                     46: foreach($arr_test as $var){
                     47:   echo "-- Iteration $counter --\n";
                     48:   var_dump( ord($var) );
                     49:   $counter++;
                     50: }
                     51: 
                     52: /* Error conditions */
                     53: echo "\n*** Testing chr() error conditions ***\n";
                     54: //zero arguments
                     55: var_dump( chr() ); 
                     56: // more than expected no. of args
                     57: var_dump( chr($arr_test[0], $arr_test[1]) ); 
                     58: 
                     59: 
                     60: echo "\n*** Testing ord() error conditions ***\n";
                     61: // zero arguments
                     62: var_dump( ord() ); 
                     63: // more than expected no. of args
                     64: var_dump( ord($arr_test[0], $arr_test[1]) ); 
                     65: 
                     66: echo "Done\n";
                     67: ?>
                     68: --EXPECTF--
                     69: *** Testing ord() & chr() basic operations ***
                     70: 
                     71: *** Testing chr() usage variations ***
                     72: -- Iteration 1 --
                     73: string(1) ""
                     74: -- Iteration 2 --
                     75: string(1) ""
                     76: -- Iteration 3 --
                     77: string(1) "&"
                     78: -- Iteration 4 --
                     79: string(1) ""
                     80: -- Iteration 5 --
                     81: string(1) ""
                     82: -- Iteration 6 --
                     83: string(1) ""
                     84: -- Iteration 7 --
                     85: string(1) ""
                     86: -- Iteration 8 --
                     87: string(1) "+"
                     88: -- Iteration 9 --
                     89: string(1) "A"
                     90: -- Iteration 10 --
                     91: string(1) ""
                     92: -- Iteration 11 --
                     93: string(1) ""
                     94: -- Iteration 12 --
                     95: string(1) ""
                     96: -- Iteration 13 --
                     97: string(1) "È"
                     98: -- Iteration 14 --
                     99: string(1) ""
                    100: -- Iteration 15 --
                    101: string(1) "ÿ"
                    102: -- Iteration 16 --
                    103: string(1) "ë"
                    104: -- Iteration 17 --
                    105: string(1) ""
                    106: -- Iteration 18 --
                    107: string(1) ""
                    108: -- Iteration 19 --
                    109: string(1) ""
                    110: 
                    111: *** Testing ord() usage variations ***
                    112: -- Iteration 1 --
                    113: int(116)
                    114: -- Iteration 2 --
                    115: int(102)
                    116: -- Iteration 3 --
                    117: int(49)
                    118: -- Iteration 4 --
                    119: int(0)
                    120: -- Iteration 5 --
                    121: int(0)
                    122: -- Iteration 6 --
                    123: int(32)
                    124: -- Iteration 7 --
                    125: int(97)
                    126: -- Iteration 8 --
                    127: int(50)
                    128: -- Iteration 9 --
                    129: int(51)
                    130: -- Iteration 10 --
                    131: int(0)
                    132: -- Iteration 11 --
                    133: int(92)
                    134: -- Iteration 12 --
                    135: int(48)
                    136: -- Iteration 13 --
                    137: int(45)
                    138: -- Iteration 14 --
                    139: int(49)
                    140: -- Iteration 15 --
                    141: int(45)
                    142: -- Iteration 16 --
                    143: int(49)
                    144: -- Iteration 17 --
                    145: int(97)
                    146: -- Iteration 18 --
                    147: int(97)
                    148: -- Iteration 19 --
                    149: int(97)
                    150: 
                    151: *** Testing chr() error conditions ***
                    152: 
                    153: Warning: Wrong parameter count for chr() in %s on line %d
                    154: NULL
                    155: 
                    156: Warning: Wrong parameter count for chr() in %s on line %d
                    157: NULL
                    158: 
                    159: *** Testing ord() error conditions ***
                    160: 
                    161: Warning: ord() expects exactly 1 parameter, 0 given in %s on line %d
                    162: NULL
                    163: 
                    164: Warning: ord() expects exactly 1 parameter, 2 given in %s on line %d
                    165: NULL
                    166: Done

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