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

1.1       misho       1: --TEST--
                      2: Test chunk_split() function : usage variations - different heredoc strings as 'str' argument 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : string chunk_split(string $str [, int $chunklen [, string $ending]])
                      6:  * Description: Returns split line
                      7:  * Source code: ext/standard/string.c
                      8:  * Alias to functions: none
                      9: */
                     10: 
                     11: /*
                     12: * Passing different heredoc strings as 'str' argument to the chunk_split() 
                     13: * with 'chunklen' 4 and default value of 'ending' that is "\r\n"
                     14: */
                     15: 
                     16: echo "*** Testing chunk_split() : heredoc strings as 'str' argument ***\n";
                     17: 
                     18: // Initializing required variables
                     19: $chunklen = 4;
                     20: 
                     21: // Null heredoc string
                     22: $heredoc_null = <<<EOT1
                     23: EOT1;
                     24: 
                     25: // heredoc string with single character
                     26: $heredoc_char = <<<EOT2
                     27: a
                     28: EOT2;
                     29: 
                     30: // simple heredoc string
                     31: $heredoc_str = <<<EOT3
                     32: This is simple heredoc string
                     33: EOT3;
                     34: 
                     35: // heredoc with special characters
                     36: $heredoc_spchar = <<<EOT4
                     37: This checks heredoc with $, %, &, chars
                     38: EOT4;
                     39: 
                     40: // blank heredoc string
                     41: $heredoc_blank = <<<EOT5
                     42: 
                     43: EOT5;
                     44: 
                     45: // heredoc with different white space characters
                     46: $heredoc_escchar = <<<EOT6
                     47: This checks\t chunk_split()\nEscape\rchars
                     48: EOT6;
                     49: 
                     50: // heredoc with multiline
                     51: $heredoc_multiline= <<<EOT7
                     52: This is to check chunk_split
                     53: function with multiline
                     54: heredoc
                     55: EOT7;
                     56: 
                     57: // heredoc with quotes and slashes
                     58: $heredoc_quote_slash = <<<EOT8
                     59: "To check " in heredoc"
                     60: I'm sure it'll work also with \
                     61: which is single slash
                     62: EOT8;
                     63: 
                     64: //different heredoc strings for 'str'
                     65: $heredoc_arr = array(
                     66:   $heredoc_null,
                     67:   $heredoc_blank,
                     68:   $heredoc_char,
                     69:   $heredoc_str,
                     70:   $heredoc_multiline,
                     71:   $heredoc_spchar,
                     72:   $heredoc_escchar,
                     73:   $heredoc_quote_slash
                     74: );
                     75: 
                     76: 
                     77: // loop through each element of the heredoc_arr for 'str'
                     78: $count = 0;
                     79: foreach($heredoc_arr as $str) {
                     80:   echo "-- Iteration ".($count+1). " --\n";
                     81:   var_dump( chunk_split( $str, $chunklen) );
                     82:   $count++;
                     83: };
                     84:  
                     85: echo "Done"
                     86: ?>
                     87: --EXPECTF--
                     88: *** Testing chunk_split() : heredoc strings as 'str' argument ***
                     89: -- Iteration 1 --
                     90: string(2) "
                     91: "
                     92: -- Iteration 2 --
                     93: string(2) "
                     94: "
                     95: -- Iteration 3 --
                     96: string(3) "a
                     97: "
                     98: -- Iteration 4 --
                     99: string(45) "This
                    100:  is 
                    101: simp
                    102: le h
                    103: ered
                    104: oc s
                    105: trin
                    106: g
                    107: "
                    108: -- Iteration 5 --
                    109: string(90) "This
                    110:  is 
                    111: to c
                    112: heck
                    113:  chu
                    114: nk_s
                    115: plit
                    116: 
                    117: fun
                    118: ctio
                    119: n wi
                    120: th m
                    121: ulti
                    122: line
                    123: 
                    124: her
                    125: edoc
                    126: "
                    127: -- Iteration 6 --
                    128: string(59) "This
                    129:  che
                    130: cks 
                    131: here
                    132: doc 
                    133: with
                    134:  $, 
                    135: %, &
                    136: , ch
                    137: ars
                    138: "
                    139: -- Iteration 7 --
                    140: string(59) "This
                    141:  che
                    142: cks    
                    143:  chu
                    144: nk_s
                    145: plit
                    146: ()
                    147: E
                    148: scap
                    149: e
ch
                    150: ars
                    151: "
                    152: -- Iteration 8 --
                    153: string(117) ""To 
                    154: chec
                    155: k " 
                    156: in h
                    157: ered
                    158: oc"
                    159: 
                    160: I'm 
                    161: sure
                    162:  it'
                    163: ll w
                    164: ork 
                    165: also
                    166:  wit
                    167: h \
                    168: 
                    169: whic
                    170: h is
                    171:  sin
                    172: gle 
                    173: slas
                    174: h
                    175: "
                    176: Done

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