]> granicus.if.org Git - php/commitdiff
New testcases for strtok() function
authorRaghubansh Kumar <kraghuba@php.net>
Sat, 22 Sep 2007 07:39:57 +0000 (07:39 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Sat, 22 Sep 2007 07:39:57 +0000 (07:39 +0000)
ext/standard/tests/strings/strtok_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation1.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation2.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation3.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation4.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation5.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation6.phpt [new file with mode: 0644]
ext/standard/tests/strings/strtok_variation7.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/strtok_basic.phpt b/ext/standard/tests/strings/strtok_basic.phpt
new file mode 100644 (file)
index 0000000..6ba48f4
--- /dev/null
@@ -0,0 +1,63 @@
+--TEST--
+Test strtok() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : basic functionality
+*/
+
+echo "*** Testing strtok() : basic functionality ***\n";
+
+// Initialize all required variables
+$str = 'This testcase test strtok() function.';
+$token = ' ().';
+
+echo "\nThe Input string is:\n\"$str\"\n";
+echo "\nThe token string is:\n\"$token\"\n";
+
+// using strtok() with $str argument
+echo "\n--- Token 1 ---\n";
+var_dump( strtok($str, $token) );
+
+for( $i = 2; $i <=7; $i++ )  {
+  echo "\n--- Token $i ---\n";
+  var_dump( strtok($token) );
+}
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..d83085b
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--
+Test strtok() function : error conditions 
+--FILE--
+<?php
+/* Prototype  : string strtok ( string $str, string $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() for error conditions
+*/
+
+echo "*** Testing strtok() : error conditions ***\n";
+
+// Zero argument
+echo "\n-- Testing strtok() function with Zero arguments --\n";
+var_dump( strtok() );
+
+// More than expected number of arguments
+echo "\n-- Testing strtok() function with more than expected no. of arguments --\n";
+$str = 'sample string';
+$token = ' ';
+$extra_arg = 10;
+
+var_dump( strtok($str, $token, $extra_arg) );
+var_dump( $str );
+
+// Less than expected number of arguments 
+echo "\n-- Testing strtok() with less than expected no. of arguments --\n";
+$str = 'string val';
+var_dump( strtok($str));
+var_dump( $str );
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..5841d28
--- /dev/null
@@ -0,0 +1,172 @@
+--TEST--
+Test strtok() function : usage variations - first argument as non-string
+--FILE--
+<?php
+/* Prototype  : string strtok ( string $str, string $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with first argument as non-string
+*/
+
+echo "*** Testing strtok() : with first argument as non-string ***\n";
+// initialize all required variables
+$token = '-';
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring a class
+class sample  {
+  public function __toString() {
+  return "obj-ect";
+  }
+}
+
+// Defining resource
+$file_handle = fopen(__FILE__, 'r');
+
+// array with different values
+$values =  array (
+
+  // integer values
+  0,
+  1,
+  12345,
+  -2345,
+
+  // float values
+  10.5,
+  -10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  // array values
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => '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 (file)
index 0000000..e08005c
--- /dev/null
@@ -0,0 +1,172 @@
+--TEST--
+Test strtok() function : usage variations - with different token strings
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with different token strings
+*/
+
+echo "*** Testing strtok() : with different token strings ***\n";
+// initialize all required variables
+$str = 'this testcase test strtok() function ';
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+// declaring a class
+class sample  {
+  public function __toString() {
+  return "obj-ect";
+  }
+} 
+
+// Defining resource
+$file_handle = fopen(__FILE__, 'r');
+
+// array with different values
+$values =  array (
+
+  // integer values
+  0,
+  1,
+  12345,
+  -2345,
+
+  // float values
+  10.5,
+  -10.5,
+  10.5e10,
+  10.6E-10,
+  .5,
+
+  // array values
+  array(),
+  array(0),
+  array(1),
+  array(1, 2),
+  array('color' => '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 (file)
index 0000000..3026d86
--- /dev/null
@@ -0,0 +1,150 @@
+--TEST--
+Test strtok() function : usage variations - with heredoc strings
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with heredoc strings
+*/
+
+echo "*** Testing strtok() : with heredoc strings ***\n";
+
+// defining different heredoc strings
+$empty_heredoc = <<<EOT
+EOT;
+
+$heredoc_with_newline = <<<EOT
+\n
+
+EOT;
+
+$heredoc_with_characters = <<<EOT
+first line of heredoc string
+second line of heredoc string
+third line of heredocstring
+EOT;
+
+$heredoc_with_newline_and_tabs = <<<EOT
+hello\tworld\nhello\nworld\n
+EOT;
+
+$heredoc_with_alphanumerics = <<<EOT
+hello123world456
+1234hello\t1234
+EOT;
+
+$heredoc_with_embedded_nulls = <<<EOT
+hello\0world\0hello
+\0hello\0
+EOT;
+
+$heredoc_strings = array(
+                   $empty_heredoc,
+                   $heredoc_with_newline,
+                   $heredoc_with_characters,
+                   $heredoc_with_newline_and_tabs,
+                   $heredoc_with_alphanumerics,
+                   $heredoc_with_embedded_nulls
+                   );
+
+// loop through each element of the array and check the working of strtok()
+// when supplied with different string values
+
+$count = 1;
+foreach($heredoc_strings as $string)  {
+  echo "\n--- Iteration $count ---\n";
+  var_dump( strtok($string, "5o\0\n\t") );
+  for($counter = 1; $counter <= 10; $counter++)  {
+    var_dump( strtok("5o\0\n\t") );
+  }
+  $count++;
+}
+
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..6f4fa66
--- /dev/null
@@ -0,0 +1,110 @@
+--TEST--
+Test strtok() function : usage variations - with embedded nulls in the strings
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with embedded nulls in the strings
+*/
+
+echo "*** Testing strtok() : with embedded nulls in the strings ***\n";
+
+// defining varous strings with embedded nulls
+$strings_with_nulls = array(
+                          "\0",
+                          '\0',
+                           "hello\0world",
+                           "\0hel\0lo",
+                           "hello\0",
+                           "\0\0hello\tworld\0\0",
+                           "\\0he\0llo\\0",
+                           'hello\0\0'
+                           );
+
+// loop through each element of the array and check the working of strtok()
+// when supplied with different string values
+
+$counter = 1;
+foreach( $strings_with_nulls as $string )  {
+  echo "\n--- Iteration $counter ---\n";
+  var_dump( strtok($string, "\0") );
+  for($count = 1; $count <= 5; $count++)  {
+    var_dump( strtok("\0") );
+  }
+  $counter++;
+}
+
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..c49f7de
--- /dev/null
@@ -0,0 +1,150 @@
+--TEST--
+Test strtok() function : usage variations - miscellaneous inputs
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with miscellaneous combinations of string and token
+*/
+
+echo "*** Testing strtok() : with miscellaneous inputs ***\n";
+
+// defining arrays for input strings and tokens
+$string_array = array(
+                      "HELLO WORLD",
+                      "hello world",
+                      "_HELLO_WORLD_",
+                      "/thello/t/wor/ttld",
+                      "hel/lo/t/world",
+                       "one:$:two:!:three:#:four",
+                      "\rhello/r/wor\rrld",
+                      chr(0),
+                       chr(0).chr(0),
+                       chr(0).'hello'.chr(0),
+                       'hello'.chr(0).'world'
+                    );
+$token_array = array( 
+                     "wr",
+                     "hello world",
+                     "__",
+                      "t/",
+                     '/t',
+                     ":",
+                     "\r",
+                     "\0",
+                     "\0",
+                     "\0",
+                     "\0",
+                   );
+
+// loop through each element of the array and check the working of strtok()
+// when supplied with different string and token values
+
+$counter =1;
+foreach( $string_array as $string )  {
+  echo "\n--- Iteration $counter ---\n";
+  var_dump( strtok($string, $token_array[$counter-1]) ); 
+  for( $count = 1; $count <=5; $count++ )  {
+    var_dump( strtok($token_array[$counter-1]) );
+  }
+  $counter++;
+}                    
+                     
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..5a77f6f
--- /dev/null
@@ -0,0 +1,160 @@
+--TEST--
+Test strtok() function : usage variations - invalid escape sequences as tokens
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : with invalid escape sequences in token
+*/
+
+echo "*** Testing strtok() : with invalid escape sequences in token ***\n";
+
+// defining arrays for input strings and tokens
+$string_array = array(
+                      "khellok worldk",
+                      "\khello\k world\k",
+                      "/khello\k world/k",
+                      "/hellok/ world"
+                    );
+$token_array = array( 
+                      "k",
+                      "/ ",
+                      "/k",
+                      "\k",
+                      "\\\\\\\k\h\e\l\o\w\r\l\d" 
+                   );
+
+// loop through each element of the array and check the working of strtok()
+// when supplied with different string and token values
+
+$counter =1;
+foreach( $string_array as $string )  {
+  echo "\n--- Iteration $counter ---\n";
+  foreach( $token_array as $token )  { 
+    var_dump( strtok($string, $token) ); 
+    for( $count = 1; $count <=3; $count++ )  {
+      var_dump( strtok($token) );
+    }
+    echo "\n";
+  }
+  $counter++;
+}                    
+                     
+
+echo "Done\n";
+?>
+--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 (file)
index 0000000..28cbf7d
--- /dev/null
@@ -0,0 +1,108 @@
+--TEST--
+Test strtok() function : usage variations - modifying the input string while tokenising
+--FILE--
+<?php
+/* Prototype  : string strtok ( str $str, str $token )
+ * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Testing strtok() : modifying the input string while it is getting tokenised
+*/
+
+echo "*** Testing strtok() : with modification of input string in between tokenising ***\n";
+
+$str = "this is a sample string";
+$token = " ";
+
+echo "\n*** Testing strtok() when string being tokenised is prefixed with another string in between the process ***\n";
+var_dump( strtok($str, $token) ); 
+// adding a string to the input string which is being tokenised
+$str = "extra string ".$str;
+for( $count = 1; $count <=6; $count++ )  {
+  echo "\n-- Token $count is --\n";
+  var_dump( strtok($token) );
+  echo "\n-- Input str is \"$str\" --\n";
+}
+                     
+echo "\n*** Testing strtok() when string being tokenised is suffixed with another string in between the process ***\n";
+var_dump( strtok($str, $token) ); 
+// adding a string to the input string which is being tokenised
+$str = $str." extra string";
+for( $count = 1; $count <=10; $count++ )  {
+  echo "\n-- Token $count is --\n";
+  var_dump( strtok($token) );
+}
+
+echo "Done\n";
+?>
+--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