]> granicus.if.org Git - php/commitdiff
New basic string tests - includes back-porting a few existing tests back to 5.2....
authorandy wharmby <wharmby@php.net>
Mon, 17 Aug 2009 10:37:30 +0000 (10:37 +0000)
committerandy wharmby <wharmby@php.net>
Mon, 17 Aug 2009 10:37:30 +0000 (10:37 +0000)
ext/standard/tests/strings/soundex_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/soundex_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/str_rot13_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/str_rot13_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/strnatcasecmp_error.phpt [new file with mode: 0644]
ext/standard/tests/strings/strnatcmp_basic.phpt [new file with mode: 0644]
ext/standard/tests/strings/strnatcmp_error.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/strings/soundex_basic.phpt b/ext/standard/tests/strings/soundex_basic.phpt
new file mode 100644 (file)
index 0000000..65bcb64
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--\r
+Test soundex() function : basic functionality\r
+--FILE--\r
+<?php\r
+/* Prototype  : string soundex  ( string $str  )\r
+ * Description: Calculate the soundex key of a string\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing soundex() : basic functionality ***\n";\r
+\r
+var_dump(soundex("Euler"));\r
+var_dump(soundex("Gauss"));  \r
+var_dump(soundex("Hilbert"));  \r
+var_dump(soundex("Knuth")); \r
+var_dump(soundex("Lloyd"));\r
+var_dump(soundex("Lukasiewicz"));\r
+\r
+var_dump(soundex("Euler")       == soundex("Ellery"));    // E460\r
+var_dump(soundex("Gauss")       == soundex("Ghosh"));     // G200\r
+var_dump(soundex("Hilbert")     == soundex("Heilbronn")); // H416\r
+var_dump(soundex("Knuth")       == soundex("Kant"));      // K530\r
+var_dump(soundex("Lloyd")       == soundex("Ladd"));      // L300\r
+var_dump(soundex("Lukasiewicz") == soundex("Lissajous")); // L222\r
+\r
+var_dump(soundex("Lukasiewicz") == soundex("Ghosh"));\r
+var_dump(soundex("Hilbert") == soundex("Ladd"));  \r
+?> \r
+===DONE===\r
+--EXPECT--\r
+*** Testing soundex() : basic functionality ***\r
+string(4) "E460"\r
+string(4) "G200"\r
+string(4) "H416"\r
+string(4) "K530"\r
+string(4) "L300"\r
+string(4) "L222"\r
+bool(true)\r
+bool(true)\r
+bool(true)\r
+bool(true)\r
+bool(true)\r
+bool(true)\r
+bool(false)\r
+bool(false)\r
\r
+===DONE===\r
diff --git a/ext/standard/tests/strings/soundex_error.phpt b/ext/standard/tests/strings/soundex_error.phpt
new file mode 100644 (file)
index 0000000..a81b9d2
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--\r
+Test soundex() function : error conditions\r
+--FILE--\r
+<?php\r
+/* Prototype  : string soundex  ( string $str  )\r
+ * Description: Calculate the soundex key of a string\r
+ * Source code: ext/standard/string.c\r
+*/\r
+               \r
+echo "\n*** Testing soundex error conditions ***";\r
+\r
+echo "-- Testing soundex() function with Zero arguments --\n";\r
+var_dump( soundex() );\r
+\r
+echo "\n\n-- Testing soundex() function with more than expected no. of arguments --\n";\r
+$str = "Euler";\r
+$extra_arg = 10;\r
+var_dump( soundex( $str, $extra_arg) );\r
+\r
+?> \r
+===DONE===\r
+--EXPECTF--\r
+*** Testing soundex error conditions ***-- Testing soundex() function with Zero arguments --\r
+\r
+Warning: soundex() expects exactly 1 parameter, 0 given in %s on line %d\r
+NULL\r
+\r
+\r
+-- Testing soundex() function with more than expected no. of arguments --\r
+\r
+Warning: soundex() expects exactly 1 parameter, 2 given in %s on line %d\r
+NULL\r
\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/str_rot13_basic.phpt b/ext/standard/tests/strings/str_rot13_basic.phpt
new file mode 100644 (file)
index 0000000..6a16cd5
--- /dev/null
@@ -0,0 +1,55 @@
+--TEST--\r
+Test soundex() function : basic functionality\r
+--FILE--\r
+<?php\r
+/* Prototype  : string str_rot13  ( string $str  )\r
+ * Description: Perform the rot13 transform on a string\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing str_rot13() : basic functionality ***\n";\r
+\r
+echo "\nBasic tests\n";\r
+var_dump(str_rot13("str_rot13() tests starting"));\r
+var_dump(str_rot13("abcdefghijklmnopqrstuvwxyz"));\r
+\r
+echo "\nEnsure numeric characters are left untouched\n";\r
+if (strcmp(str_rot13("0123456789"), "0123456789") == 0) {\r
+       echo "Strings equal : TEST PASSED\n"; \r
+} else {\r
+       echo "Strings unequal : TEST FAILED\n"; \r
+}\r
+\r
+echo "\nEnsure non-alphabetic characters are left untouched\n";\r
+if (strcmp(str_rot13("!%^&*()_-+={}[]:;@~#<,>.?"), "!%^&*()_-+={}[]:;@~#<,>.?")) {\r
+       echo "Strings equal : TEST PASSED\n"; \r
+} else {\r
+       echo "Strings unequal : TEST FAILED\n"; \r
+}\r
+\r
+echo "\nEnsure strings round trip\n";\r
+$str = "str_rot13() tests starting";\r
+$encode = str_rot13($str);\r
+$decode = str_rot13($encode);\r
+if (strcmp($str, $decode) == 0) {\r
+       echo "Strings equal : TEST PASSED\n"; \r
+} else {\r
+       echo "Strings unequal : TEST FAILED\n"; \r
+}\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+*** Testing str_rot13() : basic functionality ***\r
+\r
+Basic tests\r
+unicode(26) "fge_ebg13() grfgf fgnegvat"\r
+unicode(26) "nopqrstuvwxyzabcdefghijklm"\r
+\r
+Ensure numeric characters are left untouched\r
+Strings equal : TEST PASSED\r
+\r
+Ensure non-alphabetic characters are left untouched\r
+Strings unequal : TEST FAILED\r
+\r
+Ensure strings round trip\r
+Strings equal : TEST PASSED\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/str_rot13_error.phpt b/ext/standard/tests/strings/str_rot13_error.phpt
new file mode 100644 (file)
index 0000000..99a99f2
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--\r
+Test str_rot13() function : error conditions\r
+--FILE--\r
+<?php\r
+/* Prototype  : string str_rot13  ( string $str  )\r
+ * Description: Perform the rot13 transform on a string\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing str_rot13() : error conditions ***\n";\r
+\r
+echo "-- Testing str_rot13() function with Zero arguments --\n";\r
+var_dump( str_rot13() );\r
+\r
+echo "\n\n-- Testing str_rot13() function with more than expected no. of arguments --\n";\r
+$str = "str_rot13() tests starting";\r
+$extra_arg = 10;\r
+var_dump( str_rot13( $str, $extra_arg) );\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+*** Testing str_rot13() : error conditions ***\r
+-- Testing str_rot13() function with Zero arguments --\r
+\r
+Warning: str_rot13() expects exactly 1 parameter, 0 given in %s on line %d\r
+NULL\r
+\r
+\r
+-- Testing str_rot13() function with more than expected no. of arguments --\r
+\r
+Warning: str_rot13() expects exactly 1 parameter, 2 given in %s on line %d\r
+NULL\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/strnatcasecmp_error.phpt b/ext/standard/tests/strings/strnatcasecmp_error.phpt
new file mode 100644 (file)
index 0000000..45a15da
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--\r
+Test strnatcasecmp() function : error conditions \r
+--FILE--\r
+<?php\r
+/* Prototype  : int strnatcasecmp  ( string $str1  , string $str2  )\r
+ * Description: Case insensitive string comparisons using a "natural order" algorithm\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing strnatcasecmp() : error conditions ***\n";\r
+\r
+echo "-- Testing strnatcmp() function with Zero arguments --\n";\r
+var_dump( strnatcasecmp() );\r
+\r
+echo "\n\n-- Testing strnatcasecmp() function with more than expected no. of arguments --\n";\r
+$str1 = "abc1";\r
+$str2 = "ABC1";\r
+$extra_arg = 10;\r
+var_dump( strnatcasecmp( $str1, $str2, $extra_arg) );\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+*** Testing strnatcasecmp() : error conditions ***\r
+-- Testing strnatcmp() function with Zero arguments --\r
+\r
+Warning: strnatcasecmp() expects exactly 2 parameters, 0 given in %s on line %d\r
+NULL\r
+\r
+\r
+-- Testing strnatcasecmp() function with more than expected no. of arguments --\r
+\r
+Warning: strnatcasecmp() expects exactly 2 parameters, 3 given in %s on line %d\r
+NULL\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/strnatcmp_basic.phpt b/ext/standard/tests/strings/strnatcmp_basic.phpt
new file mode 100644 (file)
index 0000000..140bd48
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--\r
+Test strnatcmp() function : basic functionality\r
+--FILE--\r
+<?php\r
+/* Prototype  : int strnatcmp  ( string $str1  , string $str2  )\r
+ * Description: String comparisons using a "natural order" algorithm\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing strnatcmp() : basic functionality ***\n";\r
+\r
+$a1 = "abc1";\r
+$b1 = "abc10";\r
+$c1 = "abc15";\r
+$d1 = "abc2";\r
+\r
+$a2 = "ABC1";\r
+$b2 = "ABC10";\r
+$c2 = "ABC15";\r
+$d2 = "ABC2";\r
+\r
+echo "Less than tests\n";\r
+var_dump(strnatcmp($a1, $b1));\r
+var_dump(strnatcmp($a1, $c1));\r
+var_dump(strnatcmp($a1, $d1));\r
+var_dump(strnatcmp($b1, $c1));\r
+var_dump(strnatcmp($d1, $c1));\r
+\r
+var_dump(strnatcmp($a1, $b2));\r
+var_dump(strnatcmp($a1, $c2));\r
+var_dump(strnatcmp($a1, $d2));\r
+var_dump(strnatcmp($b1, $c2));\r
+var_dump(strnatcmp($d1, $c2));\r
+\r
+\r
+echo "Equal too tests\n";\r
+var_dump(strnatcmp($b1, $b1));\r
+var_dump(strnatcmp($b1, $b2)); \r
+\r
+echo "Greater than tests\n";\r
+var_dump(strnatcmp($b1, $a1));\r
+var_dump(strnatcmp($c1, $a1));\r
+var_dump(strnatcmp($d1, $a1));\r
+var_dump(strnatcmp($c1, $b1));\r
+var_dump(strnatcmp($c1, $d1));\r
+\r
+var_dump(strnatcmp($b1, $a2));\r
+var_dump(strnatcmp($c1, $a2));\r
+var_dump(strnatcmp($d1, $a2));\r
+var_dump(strnatcmp($c1, $b2));\r
+var_dump(strnatcmp($c1, $d2));\r
+?>\r
+===DONE===\r
+--EXPECT--\r
+*** Testing strnatcmp() : basic functionality ***\r
+Less than tests\r
+int(-1)\r
+int(-1)\r
+int(-1)\r
+int(-1)\r
+int(-1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+Equal too tests\r
+int(0)\r
+int(1)\r
+Greater than tests\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+int(1)\r
+===DONE===
\ No newline at end of file
diff --git a/ext/standard/tests/strings/strnatcmp_error.phpt b/ext/standard/tests/strings/strnatcmp_error.phpt
new file mode 100644 (file)
index 0000000..09cc668
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--\r
+Test strnatcmp() function : error conditions\r
+--FILE--\r
+<?php\r
+/* Prototype  : int strnatcmp  ( string $str1  , string $str2  )\r
+ * Description: String comparisons using a "natural order" algorithm\r
+ * Source code: ext/standard/string.c\r
+*/\r
+echo "*** Testing strnatcmp() : error conditions ***\n";\r
+\r
+echo "-- Testing strnatcmp() function with Zero arguments --\n";\r
+var_dump( strnatcmp() );\r
+\r
+echo "\n\n-- Testing strnatcmp() function with more than expected no. of arguments --\n";\r
+$str1 = "abc1";\r
+$str2 = "ABC1";\r
+$extra_arg = 10;\r
+var_dump( strnatcmp( $str1, $str2, $extra_arg) );\r
+\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+*** Testing strnatcmp() : error conditions ***\r
+-- Testing strnatcmp() function with Zero arguments --\r
+\r
+Warning: strnatcmp() expects exactly 2 parameters, 0 given in %s on line %d\r
+NULL\r
+\r
+\r
+-- Testing strnatcmp() function with more than expected no. of arguments --\r
+\r
+Warning: strnatcmp() expects exactly 2 parameters, 3 given in %s on line %d\r
+NULL\r
+===DONE===\r