From: Raghubansh Kumar Date: Sat, 29 Sep 2007 16:59:07 +0000 (+0000) Subject: New testcases for strrchr() function X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND_IN_5_3~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1aa583004465a391583f260285a4a26c62a35109;p=php New testcases for strrchr() function --- diff --git a/ext/standard/tests/strings/strrchr_basic.phpt b/ext/standard/tests/strings/strrchr_basic.phpt new file mode 100644 index 0000000000..f396834837 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test strrchr() function : basic functionality +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: basic functionality *** +string(12) "Hello, World" +string(12) "Hello, World" +string(12) "Hello, World" +string(12) "Hello, World" +bool(false) +bool(false) +string(5) "World" +string(5) "World" +string(7) ", World" +string(7) ", World" +string(12) "Hello, World" +string(12) "Hello, World" +string(4) "orld" +string(4) "orld" +bool(false) +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_error.phpt b/ext/standard/tests/strings/strrchr_error.phpt new file mode 100644 index 0000000000..8c2881aa53 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test strrchr() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: error conditions *** + +-- Testing strrchr() function with Zero arguments -- +Warning: Wrong parameter count for strrchr() in %s on line %d +NULL + +-- Testing strrchr() function with less than expected no. of arguments -- +Warning: Wrong parameter count for strrchr() in %s on line %d +NULL + +-- Testing strrchr() function with more than expected no. of arguments -- +Warning: Wrong parameter count for strrchr() in %s on line %d +NULL +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation1.phpt b/ext/standard/tests/strings/strrchr_variation1.phpt new file mode 100644 index 0000000000..91290ecf93 Binary files /dev/null and b/ext/standard/tests/strings/strrchr_variation1.phpt differ diff --git a/ext/standard/tests/strings/strrchr_variation10.phpt b/ext/standard/tests/strings/strrchr_variation10.phpt new file mode 100644 index 0000000000..5de3b22ffc --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation10.phpt @@ -0,0 +1,188 @@ +--TEST-- +Test strrchr() function : usage variations - unexpected inputs for needle +--FILE-- + 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // empty string + "", + '', + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +// loop through each element of the array and check the working of strrchr() +$count = 1; +for($index = 0; $index < count($haystacks); $index++) { + echo "-- Iteration $count --\n"; + var_dump( strrchr($haystacks[$index], $needles[$index]) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strrchr() function with unexpected inputs for needle *** +-- Iteration 1 -- +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- +bool(false) +-- Iteration 8 -- +bool(false) +-- Iteration 9 -- +bool(false) +-- Iteration 10 -- +bool(false) +-- Iteration 11 -- +bool(false) +-- Iteration 12 -- +bool(false) +-- Iteration 13 -- +bool(false) +-- Iteration 14 -- +bool(false) +-- Iteration 15 -- +bool(false) +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +bool(false) +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- +bool(false) +-- Iteration 20 -- +bool(false) +-- Iteration 21 -- + +Notice: Object of class sample could not be converted to int in %s on line %d +bool(false) +-- Iteration 22 -- +bool(false) +-- Iteration 23 -- +bool(false) +-- Iteration 24 -- +bool(false) +-- Iteration 25 -- +bool(false) +-- Iteration 26 -- +bool(false) +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation11.phpt b/ext/standard/tests/strings/strrchr_variation11.phpt new file mode 100644 index 0000000000..d04710d7d7 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation11.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test strrchr() function : usage variations - unexpected inputs for haystack and needle +--FILE-- + 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // objects + new sample(), + + // empty string + "", + '', + + // null vlaues + NULL, + null, + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + + +// loop through each element of the array and check the working of strrchr() +$counter = 1; +for($index = 0; $index < count($values); $index ++) { + echo "-- Iteration $counter --\n"; + $haystack = $values[$index]; + + var_dump( strrchr($values[$index], $values[$index]) ); + $counter ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strrchr() function: with unexpected inputs for haystack and needle *** +-- Iteration 1 -- +bool(false) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(false) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(false) +-- Iteration 6 -- +bool(false) +-- Iteration 7 -- +bool(false) +-- Iteration 8 -- +bool(false) +-- Iteration 9 -- +bool(false) +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +bool(false) +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +bool(false) +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +bool(false) +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +bool(false) +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +bool(false) +-- Iteration 15 -- +bool(false) +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +bool(false) +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- + +Notice: Object of class sample could not be converted to int in %s on line %d +bool(false) +-- Iteration 20 -- +bool(false) +-- Iteration 21 -- +bool(false) +-- Iteration 22 -- +bool(false) +-- Iteration 23 -- +bool(false) +-- Iteration 24 -- +bool(false) +-- Iteration 25 -- +bool(false) +-- Iteration 26 -- +bool(false) +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation12.phpt b/ext/standard/tests/strings/strrchr_variation12.phpt new file mode 100644 index 0000000000..c31e0c86ce Binary files /dev/null and b/ext/standard/tests/strings/strrchr_variation12.phpt differ diff --git a/ext/standard/tests/strings/strrchr_variation2.phpt b/ext/standard/tests/strings/strrchr_variation2.phpt new file mode 100644 index 0000000000..0b15ceeeb2 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation2.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test strrchr() function : usage variations - single quoted strings +--FILE-- +?@hello123456he \x234 \101 '; +$needle = array( + //regular strings + 'l', + 'L', + 'HELLO', + 'hEllo', + + //escape characters + '\t', + '\T', + ' ', + '\n', + '\N', + ' +', //new line + + //nulls + '\0', + NULL, + null, + + //boolean false + FALSE, + false, + + //empty string + '', + + //special chars + ' ', + '$', + ' $', + '&', + '!#', + '%\o', + '\o,', + '()', + '*+', + '+', + '-', + '.', + '.;', + ':;', + ';', + '<=>', + '>', + '=>', + '?', + '@', + '@hEllo', + + '12345', //decimal numeric string + '\x23', //hexadecimal numeric string + '#', //hexadecimal numeric string + '\101', //octal numeric string + 'A', + '456HEE', //numerics + chars + 42, //needle as int(ASCII value of '*') + $haystack //haystack as needle +); + +/* loop through to get the position of the needle in haystack string */ +$count = 1; +for($index=0; $index +--EXPECTF-- +*** Testing strrchr() function: with various single quoted strings *** +-- Iteration 1 -- +string(22) "lo123456he \x234 \101 " + +-- Iteration 2 -- +bool(false) + +-- Iteration 3 -- +string(63) "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 4 -- +string(14) "he \x234 \101 " + +-- Iteration 5 -- +string(5) "\101 " + +-- Iteration 6 -- +string(5) "\101 " + +-- Iteration 7 -- +string(1) " " + +-- Iteration 8 -- +string(5) "\101 " + +-- Iteration 9 -- +string(5) "\101 " + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +string(5) "\101 " + +-- Iteration 12 -- +bool(false) + +-- Iteration 13 -- +bool(false) + +-- Iteration 14 -- +bool(false) + +-- Iteration 15 -- +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +string(1) " " + +-- Iteration 18 -- +string(47) "$&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 19 -- +string(1) " " + +-- Iteration 20 -- +string(46) "&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 21 -- +string(45) "!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 22 -- +string(43) "%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 23 -- +string(5) "\101 " + +-- Iteration 24 -- +string(39) "()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 25 -- +string(37) "*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 26 -- +string(36) "+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 27 -- +string(35) "-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 28 -- +string(34) "./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 29 -- +string(34) "./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 30 -- +string(32) ":;<=>?@hello123456he \x234 \101 " + +-- Iteration 31 -- +string(31) ";<=>?@hello123456he \x234 \101 " + +-- Iteration 32 -- +string(30) "<=>?@hello123456he \x234 \101 " + +-- Iteration 33 -- +string(28) ">?@hello123456he \x234 \101 " + +-- Iteration 34 -- +string(29) "=>?@hello123456he \x234 \101 " + +-- Iteration 35 -- +string(27) "?@hello123456he \x234 \101 " + +-- Iteration 36 -- +string(26) "@hello123456he \x234 \101 " + +-- Iteration 37 -- +string(26) "@hello123456he \x234 \101 " + +-- Iteration 38 -- +string(2) "1 " + +-- Iteration 39 -- +string(5) "\101 " + +-- Iteration 40 -- +string(44) "#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 41 -- +string(5) "\101 " + +-- Iteration 42 -- +bool(false) + +-- Iteration 43 -- +string(7) "4 \101 " + +-- Iteration 44 -- +string(37) "*+-./:;<=>?@hello123456he \x234 \101 " + +-- Iteration 45 -- +string(63) "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 " +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation3.phpt b/ext/standard/tests/strings/strrchr_variation3.phpt new file mode 100644 index 0000000000..1d0aa30091 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation3.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test strrchr() function : usage variations - multi line heredoc string for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +string(19) "ing heredoc syntax." +bool(false) +string(8) " syntax." +string(63) "Example of string +spanning multiple lines +using heredoc syntax." +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation4.phpt b/ext/standard/tests/strings/strrchr_variation4.phpt new file mode 100644 index 0000000000..8b2c10bf25 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation4.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test strrchr() function : usage variations - heredoc string containing special chars for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +string(24) "!$#$^^&*(special) +chars." +string(31) "_")!#@@!$#$^^&*(special) +chars." +string(16) "(special) +chars." +string(21) "$^^&*(special) +chars." +string(16) "(special) +chars." +string(19) "^&*(special) +chars." +string(76) "Example of heredoc string contains +$#%^*&*_("_")!#@@!$#$^^&*(special) +chars." +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation5.phpt b/ext/standard/tests/strings/strrchr_variation5.phpt new file mode 100644 index 0000000000..fe9b91f1d7 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation5.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test strrchr() function : usage variations - heredoc string containing escape sequences for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +string(33) " st + +ch + using +\escape \seque +ce" +string(9) "\seque +ce" +string(25) " + using +\escape \seque +ce" +string(9) "\seque +ce" +string(33) " st + +ch + using +\escape \seque +ce" +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation6.phpt b/ext/standard/tests/strings/strrchr_variation6.phpt new file mode 100644 index 0000000000..ba0ffadbd7 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation6.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test strrchr() function : usage variations - heredoc string containing quote chars for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +string(3) "te'" +string(32) "" +'things' 'in' 'single' 'quote'" +bool(false) +string(14) "ingle' 'quote'" +string(6) "quote'" +string(32) "" +'things' 'in' 'single' 'quote'" +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation7.phpt b/ext/standard/tests/strings/strrchr_variation7.phpt new file mode 100644 index 0000000000..210ce81329 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation7.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test strrchr() function : usage variations - heredoc string containing blank line for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +string(1) " +" +bool(false) +bool(false) +string(1) " +" +bool(false) +bool(false) +string(1) " +" +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation8.phpt b/ext/standard/tests/strings/strrchr_variation8.phpt new file mode 100644 index 0000000000..3e298a0b3a --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation8.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test strrchr() function : usage variations - empty heredoc string for 'haystack' +--FILE-- + +--EXPECTF-- +*** Testing strrchr() function: with heredoc strings *** +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Done *** diff --git a/ext/standard/tests/strings/strrchr_variation9.phpt b/ext/standard/tests/strings/strrchr_variation9.phpt new file mode 100644 index 0000000000..cd4c5b2c32 --- /dev/null +++ b/ext/standard/tests/strings/strrchr_variation9.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test strrchr() function : usage variations - unexpected inputs for haystack +--FILE-- + 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // null vlaues + NULL, + null, + + // objects + new sample(), + + // empty string + "", + '', + + // resource + $file_handle, + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var +); + +$needles = array ( + //integer numeric strings + "0", + "1", + "2", + "-2", + + //float numeric strings + "10.5", + "-10.5", + "10.5e10", + "10.6E-10", + ".5", + + //regular strings + "array", + "a", + "r", + "y", + "ay", + "true", + "false", + "TRUE", + "FALSE", + "NULL", + "null", + "object", + + //empty string + "", + '', + + //resource variable in string form + "\$file_handle", + + //undefined variable in string form + @"$undefined_var", + @"$unset_var" +); + +// loop through each element of the array and check the working of strrchr() +$count = 1; +for($index = 0; $index < count($haystacks); $index++) { + echo "-- Iteration $count --\n"; + var_dump( strrchr($haystacks[$index], $needles[$index]) ); + $count ++; +} + +fclose($file_handle); //closing the file handle + +echo "*** Done ***"; +?> +--EXPECTF-- +*** Testing strrchr() function: with unexpected inputs for haystack *** +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(4) "2345" +-- Iteration 4 -- +string(5) "-2345" +-- Iteration 5 -- +string(4) "10.5" +-- Iteration 6 -- +string(5) "-10.5" +-- Iteration 7 -- +string(12) "105000000000" +-- Iteration 8 -- +string(7) "1.06E-9" +-- Iteration 9 -- +string(2) ".5" +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +string(2) "ay" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +string(2) "ay" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +string(3) "ray" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +string(1) "y" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +string(2) "ay" +-- Iteration 15 -- +bool(false) +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +bool(false) +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- +bool(false) +-- Iteration 20 -- +bool(false) +-- Iteration 21 -- +string(6) "object" +-- Iteration 22 -- +bool(false) +-- Iteration 23 -- +bool(false) +-- Iteration 24 -- +bool(false) +-- Iteration 25 -- +bool(false) +-- Iteration 26 -- +bool(false) +*** Done ***