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

1.1       misho       1: --TEST--
                      2: "ucfirst()" function
                      3: --INI--
                      4: precision=14
                      5: --FILE--
                      6: <?php
                      7: /* Make a string's first character uppercase */
                      8: 
                      9: echo "#### Basic and Various operations ####\n";
                     10: $str_array = array(
                     11:                    "testing ucfirst.",
                     12:                    "1.testing ucfirst",
                     13:                    "hELLO wORLD",
                     14:                    'hELLO wORLD',
                     15:                     "\0",              // Null 
                     16:                     "\x00",            // Hex Null
                     17:                     "\x000",
                     18:                     "abcd",            // double quoted string
                     19:                     'xyz',             // single quoted string
                     20:                     string,            // without quotes
                     21:                     "-3",
                     22:                     -3,
                     23:                     '-3.344',
                     24:                     -3.344,
                     25:                     NULL,
                     26:                     "NULL",
                     27:                     "0",
                     28:                     0,
                     29:                     TRUE,              // bool type
                     30:                     "TRUE",
                     31:                     "1",
                     32:                     1,
                     33:                     1.234444,
                     34:                     FALSE,
                     35:                     "FALSE",
                     36:                     " ",
                     37:                     "     ",
                     38:                     'b',               // single char
                     39:                     '\t',              // escape sequences
                     40:                     "\t",
                     41:                     "12",
                     42:                     "12twelve",                // int + string
                     43:                  );
                     44: /* loop to test working of ucfirst with different values */
                     45: foreach ($str_array as $string) {
                     46:   var_dump( ucfirst($string) );
                     47: }
                     48: 
                     49: 
                     50: 
                     51: echo "\n#### Testing Miscelleneous inputs ####\n";
                     52: 
                     53: echo "--- Testing arrays ---";
                     54: $str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array());
                     55: var_dump( ucfirst($str_arr) );  
                     56: 
                     57: echo "\n--- Testing objects ---\n";
                     58: /* we get "Catchable fatal error: saying Object of class could not be converted
                     59:         to string" by default when an object is passed instead of string:
                     60: The error can be  avoided by chosing the __toString magix method as follows: */
                     61: 
                     62: class string {
                     63:   function __toString() {
                     64:     return "hello, world";
                     65:   }
                     66: }
                     67: $obj_string = new string;
                     68: 
                     69: var_dump(ucfirst("$obj_string"));
                     70: 
                     71: 
                     72: echo "\n--- Testing Resources ---\n";
                     73: $filename1 = "dummy.txt";
                     74: $file1 = fopen($filename1, "w");                // creating new file
                     75: 
                     76: /* getting resource type for file handle */
                     77: $string1 = get_resource_type($file1);
                     78: $string2 = (int)get_resource_type($file1);      // converting stream type to int
                     79: 
                     80: /* $string1 is of "stream" type */
                     81: var_dump(ucfirst($string1)); 
                     82: 
                     83: /* $string2 holds a value of "int(0)" */
                     84: var_dump(ucfirst($string2));
                     85: 
                     86: fclose($file1);                                 // closing the file "dummy.txt"
                     87: unlink("$filename1");                           // deletes "dummy.txt"
                     88: 
                     89: 
                     90: echo "\n--- Testing a longer and heredoc string ---\n";
                     91: $string = <<<EOD
                     92: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     93: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     94: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     95: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     96: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     97: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     98: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                     99: @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
                    100: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    101: EOD;
                    102: var_dump(ucfirst($string));
                    103: 
                    104: echo "\n--- Testing a heredoc null string ---\n";
                    105: $str = <<<EOD
                    106: EOD;
                    107: var_dump(ucfirst($str));
                    108: 
                    109: 
                    110: echo "\n--- Testing simple and complex syntax strings ---\n";
                    111: $str = 'world';
                    112: 
                    113: /* Simple syntax */
                    114: var_dump(ucfirst("$str"));
                    115: var_dump(ucfirst("$str'S"));
                    116: var_dump(ucfirst("$strS"));
                    117: 
                    118: /* String with curly braces, complex syntax */
                    119: var_dump(ucfirst("${str}S"));
                    120: var_dump(ucfirst("{$str}S"));
                    121: 
                    122: echo "\n--- Nested ucfirst() ---\n";
                    123: var_dump(ucfirst(ucfirst("hello")));
                    124: 
                    125: 
                    126: echo "\n#### error conditions ####";
                    127: /* Zero arguments */
                    128: ucfirst();
                    129: /* More than expected no. of args */
                    130: ucfirst($str_array[0], $str_array[1]);
                    131: ucfirst((int)10, (int)20);
                    132: 
                    133: echo "Done\n";
                    134: ?>
                    135: --EXPECTF--
                    136: #### Basic and Various operations ####
                    137: 
                    138: Notice: Use of undefined constant string - assumed 'string' in %s on line %d
                    139: string(16) "Testing ucfirst."
                    140: string(17) "1.testing ucfirst"
                    141: string(11) "HELLO wORLD"
                    142: string(11) "HELLO wORLD"
                    143: string(1) ""
                    144: string(1) ""
                    145: string(2) "0"
                    146: string(4) "Abcd"
                    147: string(3) "Xyz"
                    148: string(6) "String"
                    149: string(2) "-3"
                    150: string(2) "-3"
                    151: string(6) "-3.344"
                    152: string(6) "-3.344"
                    153: string(0) ""
                    154: string(4) "NULL"
                    155: string(1) "0"
                    156: string(1) "0"
                    157: string(1) "1"
                    158: string(4) "TRUE"
                    159: string(1) "1"
                    160: string(1) "1"
                    161: string(8) "1.234444"
                    162: string(0) ""
                    163: string(5) "FALSE"
                    164: string(1) " "
                    165: string(5) "     "
                    166: string(1) "B"
                    167: string(2) "\t"
                    168: string(1) "    "
                    169: string(2) "12"
                    170: string(8) "12twelve"
                    171: 
                    172: #### Testing Miscelleneous inputs ####
                    173: --- Testing arrays ---
                    174: Warning: ucfirst() expects parameter 1 to be string, array given in %s on line %d
                    175: NULL
                    176: 
                    177: --- Testing objects ---
                    178: string(12) "Hello, world"
                    179: 
                    180: --- Testing Resources ---
                    181: string(6) "Stream"
                    182: string(1) "0"
                    183: 
                    184: --- Testing a longer and heredoc string ---
                    185: string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    186: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    187: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    188: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    189: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    190: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    191: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
                    192: @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
                    193: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                    194: 
                    195: --- Testing a heredoc null string ---
                    196: string(0) ""
                    197: 
                    198: --- Testing simple and complex syntax strings ---
                    199: string(5) "World"
                    200: string(7) "World'S"
                    201: 
                    202: Notice: Undefined variable: strS in %s on line %d
                    203: string(0) ""
                    204: string(6) "WorldS"
                    205: string(6) "WorldS"
                    206: 
                    207: --- Nested ucfirst() ---
                    208: string(5) "Hello"
                    209: 
                    210: #### error conditions ####
                    211: Warning: ucfirst() expects exactly 1 parameter, 0 given in %s on line %d
                    212: 
                    213: Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d
                    214: 
                    215: Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d
                    216: Done

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