From eb3f8fda655946f9904638b443f1347d038ab1cc Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Sat, 22 Sep 2007 07:39:57 +0000 Subject: [PATCH] New testcases for strtok() function --- ext/standard/tests/strings/strtok_basic.phpt | 63 +++++++ ext/standard/tests/strings/strtok_error.phpt | 55 ++++++ .../tests/strings/strtok_variation1.phpt | 172 ++++++++++++++++++ .../tests/strings/strtok_variation2.phpt | 172 ++++++++++++++++++ .../tests/strings/strtok_variation3.phpt | 150 +++++++++++++++ .../tests/strings/strtok_variation4.phpt | 110 +++++++++++ .../tests/strings/strtok_variation5.phpt | 150 +++++++++++++++ .../tests/strings/strtok_variation6.phpt | 160 ++++++++++++++++ .../tests/strings/strtok_variation7.phpt | 108 +++++++++++ 9 files changed, 1140 insertions(+) create mode 100644 ext/standard/tests/strings/strtok_basic.phpt create mode 100644 ext/standard/tests/strings/strtok_error.phpt create mode 100644 ext/standard/tests/strings/strtok_variation1.phpt create mode 100644 ext/standard/tests/strings/strtok_variation2.phpt create mode 100644 ext/standard/tests/strings/strtok_variation3.phpt create mode 100644 ext/standard/tests/strings/strtok_variation4.phpt create mode 100644 ext/standard/tests/strings/strtok_variation5.phpt create mode 100644 ext/standard/tests/strings/strtok_variation6.phpt create mode 100644 ext/standard/tests/strings/strtok_variation7.phpt diff --git a/ext/standard/tests/strings/strtok_basic.phpt b/ext/standard/tests/strings/strtok_basic.phpt new file mode 100644 index 0000000000..6ba48f41e3 --- /dev/null +++ b/ext/standard/tests/strings/strtok_basic.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test strtok() function : basic functionality +--FILE-- + +--EXPECTF-- +*** Testing strtok() : basic functionality *** + +The Input string is: +"This testcase test strtok() function." + +The token string is: +" ()." + +--- Token 1 --- +string(4) "This" + +--- Token 2 --- +string(8) "testcase" + +--- Token 3 --- +string(4) "test" + +--- Token 4 --- +string(6) "strtok" + +--- Token 5 --- +string(8) "function" + +--- Token 6 --- +bool(false) + +--- Token 7 --- +bool(false) +Done diff --git a/ext/standard/tests/strings/strtok_error.phpt b/ext/standard/tests/strings/strtok_error.phpt new file mode 100644 index 0000000000..d83085b0c6 --- /dev/null +++ b/ext/standard/tests/strings/strtok_error.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test strtok() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing strtok() : error conditions *** + +-- Testing strtok() function with Zero arguments -- + +Warning: Wrong parameter count for strtok() in %s on line %d +NULL + +-- Testing strtok() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for strtok() in %s on line %d +NULL +string(13) "sample string" + +-- Testing strtok() with less than expected no. of arguments -- +bool(false) +string(10) "string val" +Done diff --git a/ext/standard/tests/strings/strtok_variation1.phpt b/ext/standard/tests/strings/strtok_variation1.phpt new file mode 100644 index 0000000000..5841d28580 --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation1.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test strtok() function : usage variations - first argument as non-string +--FILE-- + 'red-color', 'item' => 'pen-color'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // objects + new sample(), + + // empty string + "", + '', + + // null vlaues + NULL, + null, + + // undefined variable + $undefined_var, + + // unset variable + $unset_var, + + // resource + $file_handle +); + + +// loop through each element of the array and check the working of strtok() +// when $str arugment is supplied with different values + +echo "\n--- Testing strtok() by supplying different values for 'str' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) { + echo "-- Iteration $counter --\n"; + $str = $values [$index]; + + var_dump( strtok($str, $token) ); + + $counter ++; +} + +//closing the resource +fclose($file_handle); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with first argument as non-string *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'str' argument --- +-- Iteration 1 -- +string(1) "0" +-- Iteration 2 -- +string(1) "1" +-- Iteration 3 -- +string(5) "12345" +-- Iteration 4 -- +string(4) "2345" +-- Iteration 5 -- +string(4) "10.5" +-- Iteration 6 -- +string(4) "10.5" +-- Iteration 7 -- +string(12) "105000000000" +-- Iteration 8 -- +string(5) "1.06E" +-- Iteration 9 -- +string(3) "0.5" +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +string(5) "Array" +-- Iteration 15 -- +string(1) "1" +-- Iteration 16 -- +bool(false) +-- Iteration 17 -- +string(1) "1" +-- Iteration 18 -- +bool(false) +-- Iteration 19 -- +string(3) "obj" +-- 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 -- +string(14) "Resource id #%d" +Done diff --git a/ext/standard/tests/strings/strtok_variation2.phpt b/ext/standard/tests/strings/strtok_variation2.phpt new file mode 100644 index 0000000000..e08005ca7d --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation2.phpt @@ -0,0 +1,172 @@ +--TEST-- +Test strtok() function : usage variations - with different token strings +--FILE-- + 'red', 'item' => 'pen'), + + // boolean values + true, + false, + TRUE, + FALSE, + + // objects + new sample(), + + // empty string + "", + '', + + // null vlaues + NULL, + null, + + // undefined variable + $undefined_var, + + // unset variable + $unset_var, + + // resource + $file_handle +); + + +// loop through each element of the array and check the working of strtok() +// when $token arugment is supplied with different values + +echo "\n--- Testing strtok() by supplying different values for 'token' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) { + echo "-- Iteration $counter --\n"; + $token = $values [$index]; + + var_dump( strtok($str, $token) ); + + $counter ++; +} + +// closing the resource +fclose($file_handle); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing strtok() : with different token strings *** + +Notice: Undefined variable: undefined_var in %s on line %d + +Notice: Undefined variable: unset_var in %s on line %d + +--- Testing strtok() by supplying different values for 'token' argument --- +-- Iteration 1 -- +string(37) "this testcase test strtok() function " +-- Iteration 2 -- +string(37) "this testcase test strtok() function " +-- Iteration 3 -- +string(37) "this testcase test strtok() function " +-- Iteration 4 -- +string(37) "this testcase test strtok() function " +-- Iteration 5 -- +string(37) "this testcase test strtok() function " +-- Iteration 6 -- +string(37) "this testcase test strtok() function " +-- Iteration 7 -- +string(37) "this testcase test strtok() function " +-- Iteration 8 -- +string(37) "this testcase test strtok() function " +-- Iteration 9 -- +string(37) "this testcase test strtok() function " +-- Iteration 10 -- + +Notice: Array to string conversion in %s on line %d +string(10) "this testc" +-- Iteration 11 -- + +Notice: Array to string conversion in %s on line %d +string(10) "this testc" +-- Iteration 12 -- + +Notice: Array to string conversion in %s on line %d +string(10) "this testc" +-- Iteration 13 -- + +Notice: Array to string conversion in %s on line %d +string(10) "this testc" +-- Iteration 14 -- + +Notice: Array to string conversion in %s on line %d +string(10) "this testc" +-- Iteration 15 -- +string(37) "this testcase test strtok() function " +-- Iteration 16 -- +string(37) "this testcase test strtok() function " +-- Iteration 17 -- +string(37) "this testcase test strtok() function " +-- Iteration 18 -- +string(37) "this testcase test strtok() function " +-- Iteration 19 -- +string(4) "his " +-- Iteration 20 -- +string(37) "this testcase test strtok() function " +-- Iteration 21 -- +string(37) "this testcase test strtok() function " +-- Iteration 22 -- +string(37) "this testcase test strtok() function " +-- Iteration 23 -- +string(37) "this testcase test strtok() function " +-- Iteration 24 -- +string(37) "this testcase test strtok() function " +-- Iteration 25 -- +string(37) "this testcase test strtok() function " +-- Iteration 26 -- +string(2) "th" +Done diff --git a/ext/standard/tests/strings/strtok_variation3.phpt b/ext/standard/tests/strings/strtok_variation3.phpt new file mode 100644 index 0000000000..3026d86a01 --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation3.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test strtok() function : usage variations - with heredoc strings +--FILE-- + +--EXPECTF-- +*** Testing strtok() : with heredoc strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(11) "first line " +string(7) "f hered" +string(8) "c string" +string(3) "sec" +string(8) "nd line " +string(7) "f hered" +string(8) "c string" +string(11) "third line " +string(7) "f hered" +string(7) "cstring" +bool(false) + +--- Iteration 4 --- +string(4) "hell" +string(1) "w" +string(3) "rld" +string(4) "hell" +string(1) "w" +string(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(4) "hell" +string(4) "123w" +string(4) "rld4" +string(1) "6" +string(8) "1234hell" +string(4) "1234" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(4) "hell" +string(1) "w" +string(3) "rld" +string(4) "hell" +string(4) "hell" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/standard/tests/strings/strtok_variation4.phpt b/ext/standard/tests/strings/strtok_variation4.phpt new file mode 100644 index 0000000000..6f4fa6621b --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation4.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test strtok() function : usage variations - with embedded nulls in the strings +--FILE-- + +--EXPECTF-- +*** Testing strtok() : with embedded nulls in the strings *** + +--- Iteration 1 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +string(2) "\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(5) "hello" +string(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +string(3) "hel" +string(2) "lo" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(11) "hello world" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 7 --- +string(4) "\0he" +string(5) "llo\0" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +string(9) "hello\0\0" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/standard/tests/strings/strtok_variation5.phpt b/ext/standard/tests/strings/strtok_variation5.phpt new file mode 100644 index 0000000000..c49f7ded9f --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation5.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test strtok() function : usage variations - miscellaneous inputs +--FILE-- + +--EXPECTF-- +*** Testing strtok() : with miscellaneous inputs *** + +--- Iteration 1 --- +string(11) "HELLO WORLD" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 2 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 3 --- +string(5) "HELLO" +string(5) "WORLD" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 4 --- +string(5) "hello" +string(3) "wor" +string(2) "ld" +bool(false) +bool(false) +bool(false) + +--- Iteration 5 --- +string(3) "hel" +string(2) "lo" +string(5) "world" +bool(false) +bool(false) +bool(false) + +--- Iteration 6 --- +string(3) "one" +string(1) "$" +string(3) "two" +string(1) "!" +string(5) "three" +string(1) "#" + +--- Iteration 7 --- +string(11) "hello/r/wor" +string(3) "rld" +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 8 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 9 --- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 10 --- +string(5) "hello" +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) + +--- Iteration 11 --- +string(5) "hello" +string(5) "world" +bool(false) +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/standard/tests/strings/strtok_variation6.phpt b/ext/standard/tests/strings/strtok_variation6.phpt new file mode 100644 index 0000000000..5a77f6f9e9 --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation6.phpt @@ -0,0 +1,160 @@ +--TEST-- +Test strtok() function : usage variations - invalid escape sequences as tokens +--FILE-- + +--EXPECTF-- +*** Testing strtok() : with invalid escape sequences in token *** + +--- Iteration 1 --- +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(7) "khellok" +string(6) "worldk" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(1) " " +string(1) "r" +bool(false) +bool(false) + + +--- Iteration 2 --- +string(1) "\" +string(6) "hello\" +string(7) " world\" +bool(false) + +string(9) "\khello\k" +string(7) "world\k" +bool(false) +bool(false) + +string(1) "\" +string(6) "hello\" +string(7) " world\" +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(1) " " +string(1) "r" +bool(false) +bool(false) + + +--- Iteration 3 --- +string(1) "/" +string(6) "hello\" +string(7) " world/" +bool(false) + +string(8) "khello\k" +string(5) "world" +string(1) "k" +bool(false) + +string(6) "hello\" +string(6) " world" +bool(false) +bool(false) + +string(1) "/" +string(5) "hello" +string(7) " world/" +bool(false) + +string(1) "/" +string(1) " " +string(1) "r" +string(1) "/" + + +--- Iteration 4 --- +string(6) "/hello" +string(7) "/ world" +bool(false) +bool(false) + +string(6) "hellok" +string(5) "world" +bool(false) +bool(false) + +string(5) "hello" +string(6) " world" +bool(false) +bool(false) + +string(6) "/hello" +string(7) "/ world" +bool(false) +bool(false) + +string(1) "/" +string(2) "/ " +string(1) "r" +bool(false) + +Done diff --git a/ext/standard/tests/strings/strtok_variation7.phpt b/ext/standard/tests/strings/strtok_variation7.phpt new file mode 100644 index 0000000000..28cbf7d917 --- /dev/null +++ b/ext/standard/tests/strings/strtok_variation7.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test strtok() function : usage variations - modifying the input string while tokenising +--FILE-- + +--EXPECTF-- +*** Testing strtok() : with modification of input string in between tokenising *** + +*** Testing strtok() when string being tokenised is prefixed with another string in between the process *** +string(4) "this" + +-- Token 1 is -- +string(2) "is" + +-- Input str is "extra string this is a sample string" -- + +-- Token 2 is -- +string(1) "a" + +-- Input str is "extra string this is a sample string" -- + +-- Token 3 is -- +string(6) "sample" + +-- Input str is "extra string this is a sample string" -- + +-- Token 4 is -- +string(6) "string" + +-- Input str is "extra string this is a sample string" -- + +-- Token 5 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +-- Token 6 is -- +bool(false) + +-- Input str is "extra string this is a sample string" -- + +*** Testing strtok() when string being tokenised is suffixed with another string in between the process *** +string(5) "extra" + +-- Token 1 is -- +string(6) "string" + +-- Token 2 is -- +string(4) "this" + +-- Token 3 is -- +string(2) "is" + +-- Token 4 is -- +string(1) "a" + +-- Token 5 is -- +string(6) "sample" + +-- Token 6 is -- +string(6) "string" + +-- Token 7 is -- +bool(false) + +-- Token 8 is -- +bool(false) + +-- Token 9 is -- +bool(false) + +-- Token 10 is -- +bool(false) +Done -- 2.40.0