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

1.1       misho       1: --TEST--
                      2: Test strcspn() function : usage variations - with heredoc strings, varying mask & default start and len args
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : proto int strcspn(string str, string mask [,int start [,int len]])
                      6:  * Description: Finds length of initial segment consisting entirely of characters not found in mask.
                      7:                 If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars) 
                      8:  * Source code: ext/standard/string.c
                      9:  * Alias to functions: none
                     10: */
                     11: 
                     12: /*
                     13: * Testing strcspn() : with heredoc string, varying mask and default start and len arguments
                     14: */
                     15: 
                     16: echo "*** Testing strcspn() : with different mask strings ***\n";
                     17: 
                     18: // initialing required variables
                     19: // defining different heredoc strings
                     20: $empty_heredoc = <<<EOT
                     21: EOT;
                     22: 
                     23: $heredoc_with_newline = <<<EOT
                     24: \n
                     25: 
                     26: EOT;
                     27: 
                     28: $heredoc_with_characters = <<<EOT
                     29: first line of heredoc string
                     30: second line of heredoc string
                     31: third line of heredocstring
                     32: EOT;
                     33: 
                     34: $heredoc_with_newline_and_tabs = <<<EOT
                     35: hello\tworld\nhello\nworld\n
                     36: EOT;
                     37: 
                     38: $heredoc_with_alphanumerics = <<<EOT
                     39: hello123world456
                     40: 1234hello\t1234
                     41: EOT;
                     42: 
                     43: $heredoc_with_embedded_nulls = <<<EOT
                     44: hello\0world\0hello
                     45: \0hello\0
                     46: EOT;
                     47: 
                     48: $heredoc_with_hexa_octal = <<<EOT
                     49: hello\0\100\xaaworld\0hello
                     50: \0hello\0
                     51: EOT;
                     52: 
                     53: $heredoc_strings = array(
                     54:                    $empty_heredoc,
                     55:                    $heredoc_with_newline,
                     56:                    $heredoc_with_characters,
                     57:                    $heredoc_with_newline_and_tabs,
                     58:                    $heredoc_with_alphanumerics,
                     59:                    $heredoc_with_embedded_nulls,
                     60:                    $heredoc_with_hexa_octal
                     61:                    );
                     62: 
                     63: // defining array of mask strings
                     64: $mask_array = array(
                     65:                    "",
                     66:                    '',
                     67:                    "\n\trsti \l",
                     68:                    '\n\trsti \l',
                     69:                    "\t",
                     70:                    "t\ ",
                     71:                    '\t',
                     72:                    "\t\ ",
                     73:                    " \t",
                     74:                     "\t\i\100\xaa"
                     75:                    );
                     76:                
                     77: 
                     78: // loop through each element of the arrays for string and mask arguments
                     79: 
                     80: $count = 1;
                     81: foreach($heredoc_strings as $str) {
                     82:   echo "\n-- Iteration $count --\n";
                     83:   foreach($mask_array as $mask) {
                     84:       var_dump( strcspn($str,$mask) ); // with default start and len value
                     85:   }
                     86:   $count++;
                     87: }
                     88: 
                     89: echo "Done"
                     90: ?>
                     91: --EXPECTF--
                     92: *** Testing strcspn() : with different mask strings ***
                     93: 
                     94: -- Iteration 1 --
                     95: int(0)
                     96: int(0)
                     97: int(0)
                     98: int(0)
                     99: int(0)
                    100: int(0)
                    101: int(0)
                    102: int(0)
                    103: int(0)
                    104: int(0)
                    105: 
                    106: -- Iteration 2 --
                    107: int(2)
                    108: int(2)
                    109: int(0)
                    110: int(2)
                    111: int(2)
                    112: int(2)
                    113: int(2)
                    114: int(2)
                    115: int(2)
                    116: int(2)
                    117: 
                    118: -- Iteration 3 --
                    119: int(86)
                    120: int(86)
                    121: int(1)
                    122: int(1)
                    123: int(86)
                    124: int(4)
                    125: int(4)
                    126: int(5)
                    127: int(5)
                    128: int(1)
                    129: 
                    130: -- Iteration 4 --
                    131: int(24)
                    132: int(24)
                    133: int(2)
                    134: int(2)
                    135: int(5)
                    136: int(24)
                    137: int(24)
                    138: int(5)
                    139: int(5)
                    140: int(5)
                    141: 
                    142: -- Iteration 5 --
                    143: int(31)
                    144: int(31)
                    145: int(2)
                    146: int(2)
                    147: int(26)
                    148: int(31)
                    149: int(31)
                    150: int(26)
                    151: int(26)
                    152: int(26)
                    153: 
                    154: -- Iteration 6 --
                    155: int(5)
                    156: int(5)
                    157: int(2)
                    158: int(2)
                    159: int(25)
                    160: int(25)
                    161: int(25)
                    162: int(25)
                    163: int(25)
                    164: int(25)
                    165: 
                    166: -- Iteration 7 --
                    167: int(5)
                    168: int(5)
                    169: int(2)
                    170: int(2)
                    171: int(27)
                    172: int(27)
                    173: int(27)
                    174: int(27)
                    175: int(27)
                    176: int(6)
                    177: Done

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