summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghubansh Kumar <kraghuba@php.net>2007-09-07 14:44:52 +0000
committerRaghubansh Kumar <kraghuba@php.net>2007-09-07 14:44:52 +0000
commita14ef42c0c66953cb177c8fd486d82b975a00410 (patch)
treea9f5f7a2a91b3d36b3d5198a4a7bd4c1ebb8f5e1
parent67b4492c47195cdb11660870e2465605596a0b46 (diff)
downloadphp-git-a14ef42c0c66953cb177c8fd486d82b975a00410.tar.gz
New testcases for ucwords() function
-rw-r--r--ext/standard/tests/strings/ucwords_basic.phpt85
-rw-r--r--ext/standard/tests/strings/ucwords_error.phpt42
-rw-r--r--ext/standard/tests/strings/ucwords_variation1.phpt199
-rw-r--r--ext/standard/tests/strings/ucwords_variation2.phpt99
-rw-r--r--ext/standard/tests/strings/ucwords_variation3.phpt97
-rw-r--r--ext/standard/tests/strings/ucwords_variation4.phpt125
6 files changed, 647 insertions, 0 deletions
diff --git a/ext/standard/tests/strings/ucwords_basic.phpt b/ext/standard/tests/strings/ucwords_basic.phpt
new file mode 100644
index 0000000000..b4942d3cf6
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_basic.phpt
@@ -0,0 +1,85 @@
+--TEST--
+Test ucwords() function : basic functionality
+--INI--
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing ucwords() : basic functionality ***\n";
+
+// lines with different whitespace charecter
+$str_array = array(
+ "testing ucwords",
+ 'testing ucwords',
+ 'testing\tucwords',
+ "testing\tucwords",
+ "testing\nucwords",
+ 'testing\nucwords',
+ "testing\vucwords",
+ 'testing\vucwords',
+ "testing",
+ 'testing',
+ ' testing',
+ " testing",
+ "testing ucwords",
+ 'testing ucwords',
+ 'testing\rucwords',
+ "testing\rucwords",
+ 'testing\fucwords',
+ "testing\fucwords"
+);
+
+// loop through the $strings array to test ucwords on each element
+$iteration = 1;
+for($index = 0; $index < count($str_array); $index++) {
+ echo "-- Iteration $iteration --\n";
+ var_dump( ucwords($str_array[$index]) );
+ $iteration++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : basic functionality ***
+-- Iteration 1 --
+string(15) "Testing Ucwords"
+-- Iteration 2 --
+string(15) "Testing Ucwords"
+-- Iteration 3 --
+string(16) "Testing\tucwords"
+-- Iteration 4 --
+string(15) "Testing Ucwords"
+-- Iteration 5 --
+string(15) "Testing
+Ucwords"
+-- Iteration 6 --
+string(16) "Testing\nucwords"
+-- Iteration 7 --
+string(16) "Testing\vucwords"
+-- Iteration 8 --
+string(16) "Testing\vucwords"
+-- Iteration 9 --
+string(7) "Testing"
+-- Iteration 10 --
+string(7) "Testing"
+-- Iteration 11 --
+string(8) " Testing"
+-- Iteration 12 --
+string(8) " Testing"
+-- Iteration 13 --
+string(16) "Testing Ucwords"
+-- Iteration 14 --
+string(16) "Testing Ucwords"
+-- Iteration 15 --
+string(16) "Testing\rucwords"
+-- Iteration 16 --
+string(15) "Testing
+Ucwords"
+-- Iteration 17 --
+string(16) "Testing\fucwords"
+-- Iteration 18 --
+string(16) "Testing\fucwords"
+Done
diff --git a/ext/standard/tests/strings/ucwords_error.phpt b/ext/standard/tests/strings/ucwords_error.phpt
new file mode 100644
index 0000000000..cd6e7513c3
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_error.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Test ucwords() function : error conditions
+--INI--
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+echo "*** Testing ucwords() : error conditions ***\n";
+
+// Zero argument
+echo "\n-- Testing ucwords() function with Zero arguments --\n";
+var_dump( ucwords() );
+
+// More than expected number of arguments
+echo "\n-- Testing ucwords() function with more than expected no. of arguments --\n";
+$str = 'string_val';
+$extra_arg = 10;
+
+var_dump( ucwords($str, $extra_arg) );
+
+// check if there were any changes made to $str
+var_dump($str);
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : error conditions ***
+
+-- Testing ucwords() function with Zero arguments --
+
+Warning: Wrong parameter count for ucwords() in %s on line %d
+NULL
+
+-- Testing ucwords() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for ucwords() in %s on line %d
+NULL
+string(10) "string_val"
+Done
diff --git a/ext/standard/tests/strings/ucwords_variation1.phpt b/ext/standard/tests/strings/ucwords_variation1.phpt
new file mode 100644
index 0000000000..3cb09e5781
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_variation1.phpt
@@ -0,0 +1,199 @@
+--TEST--
+Test ucwords() function : usage variations - unexpected input values
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * Test ucwords() by passing different values including scalar and non scalar values
+*/
+
+echo "*** Testing ucwords() : usage variations ***\n";
+// initialize all required variables
+
+// get an unset variable
+$unset_var = 'string_val';
+unset($unset_var);
+
+$fp = fopen(__FILE__, "r");
+
+class my
+{
+ function __toString() {
+ return "myString";
+ }
+}
+
+// array with different values
+$values = array (
+
+ // integer values
+ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // hex values
+ 0x10,
+ 0X20,
+ 0xAA,
+ -0XF5,
+
+ // octal values
+ 0123,
+ -0342,
+
+ // 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 my(),
+
+ // empty string
+ "",
+ '',
+
+ //NULL
+ NULL,
+ null,
+
+ // hex in string
+ "0x123",
+ '0x123',
+ "0xFF12",
+ "-0xFF12",
+
+ // undefined variable
+ @$undefined_var,
+
+ // unset variable
+ @$unset_var,
+
+ // resource variable
+ $fp
+);
+
+// loop through each element of the array and check the working of ucwords()
+// when $str arugment is supplied with different values
+echo "\n--- Testing ucwords() 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( ucwords($str) );
+
+ $counter ++;
+}
+
+// close the file handle
+fclose($fp);
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : usage variations ***
+
+--- Testing ucwords() 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(5) "-2345"
+-- Iteration 5 --
+string(2) "16"
+-- Iteration 6 --
+string(2) "32"
+-- Iteration 7 --
+string(3) "170"
+-- Iteration 8 --
+string(4) "-245"
+-- Iteration 9 --
+string(2) "83"
+-- Iteration 10 --
+string(4) "-226"
+-- Iteration 11 --
+string(4) "10.5"
+-- Iteration 12 --
+string(5) "-10.5"
+-- Iteration 13 --
+string(12) "105000000000"
+-- Iteration 14 --
+string(7) "1.06E-9"
+-- Iteration 15 --
+string(3) "0.5"
+-- Iteration 16 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 17 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 18 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 19 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 20 --
+
+Notice: Array to string conversion in %s on line %d
+string(5) "Array"
+-- Iteration 21 --
+string(1) "1"
+-- Iteration 22 --
+string(0) ""
+-- Iteration 23 --
+string(1) "1"
+-- Iteration 24 --
+string(0) ""
+-- Iteration 25 --
+string(8) "MyString"
+-- Iteration 26 --
+string(0) ""
+-- Iteration 27 --
+string(0) ""
+-- Iteration 28 --
+string(0) ""
+-- Iteration 29 --
+string(0) ""
+-- Iteration 30 --
+string(5) "0x123"
+-- Iteration 31 --
+string(5) "0x123"
+-- Iteration 32 --
+string(6) "0xFF12"
+-- Iteration 33 --
+string(7) "-0xFF12"
+-- Iteration 34 --
+string(0) ""
+-- Iteration 35 --
+string(0) ""
+-- Iteration 36 --
+string(14) "Resource Id #5"
+Done
diff --git a/ext/standard/tests/strings/ucwords_variation2.phpt b/ext/standard/tests/strings/ucwords_variation2.phpt
new file mode 100644
index 0000000000..14f392eb19
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_variation2.phpt
@@ -0,0 +1,99 @@
+--TEST--
+Test ucwords() function : usage variations - heredoc strings
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * test ucwords() with different string prepared using heredoc
+*/
+
+echo "*** Testing ucwords() : usage variations ***\n";
+
+// Null here doc string
+$null_string = <<<EOT
+EOT;
+
+// Heredoc string with blank line
+$blank_line = <<<EOT
+
+EOT;
+
+// here doc with multiline string
+$multiline_string = <<<EOT
+testing ucword() with
+multiline string using
+heredoc
+EOT;
+
+// here doc with diferent whitespaces
+$diff_whitespaces = <<<EOT
+testing\rucword(str)\twith
+multiline string\t\tusing
+heredoc\nstring.with\vdifferent\fwhite\vspaces
+EOT;
+
+// here doc with numeric values
+$numeric_string = <<<EOT
+12sting 123string 4567
+string\t123string\r12 test\n5test
+EOT;
+
+// heredoc with quote chars & slash
+$quote_char_string = <<<EOT
+it's bright,but i cann't see it.
+"things in double quote"
+'things in single quote'
+this\line is /with\slashs
+EOT;
+
+$heredoc_strings = array(
+ $null_string,
+ $blank_line,
+ $multiline_string,
+ $diff_whitespaces,
+ $numeric_string,
+ $quote_char_string
+);
+
+// loop through $heredoc_strings element and check the working on ucwords()
+$count = 1;
+for($index =0; $index < count($heredoc_strings); $index ++) {
+ echo "-- Iteration $count --\n";
+ var_dump( ucwords($heredoc_strings[$index]) );
+ $count ++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : usage variations ***
+-- Iteration 1 --
+string(0) ""
+-- Iteration 2 --
+string(0) ""
+-- Iteration 3 --
+string(52) "Testing Ucword() With
+Multiline String Using
+Heredoc"
+-- Iteration 4 --
+string(96) "Testing
+Ucword(str) With
+Multiline String Using
+Heredoc
+String.with\vdifferent\fwhite\vspaces"
+-- Iteration 5 --
+string(53) "12sting 123string 4567
+String 123string
+12 Test
+5test"
+-- Iteration 6 --
+string(108) "It's Bright,but I Cann't See It.
+"things In Double Quote"
+'things In Single Quote'
+This\line Is /with\slashs"
+Done
+
diff --git a/ext/standard/tests/strings/ucwords_variation3.phpt b/ext/standard/tests/strings/ucwords_variation3.phpt
new file mode 100644
index 0000000000..e6f7c405ac
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_variation3.phpt
@@ -0,0 +1,97 @@
+--TEST--
+Test ucwords() function : usage variations - single quoted string
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * test ucwords() with different string prepared using single quote
+*/
+
+echo "*** Testing ucwords() : usage variations ***\n";
+
+// different strings containing regular chars and special chars
+$str_array = array(
+ // multiple spaces
+ 'testing ucwords',
+ 't e s t i n g u c w o r d s ',
+
+ // brackets in sentence
+ 'testing function(ucwords)',
+ '(testing ( function (ucwords) )a )test',
+ '(t)',
+ ' ( t )t',
+
+ // using quote chars in sentence
+ '"testing",ucword,"test"',
+ '"t""t",test, t',
+ '\'t \'t\',test',
+
+ // using other white spaces
+ '\ttesting\ttesting\tucwords',
+ 'testing\rucwords testing ucwords',
+ 'testing\fucwords \f testing \nucwords',
+ '\ntesting\nucwords\n testing \n ucwords',
+ 'using\vvertical\vtab',
+
+ //using special chars in sentence
+ 't@@#$% %test ^test &test *test +test -test',
+ '!test ~test `test` =test= @test@test.com',
+ '/test/r\test\ucwords\t\y\y\u\3 \yy\ /uu/',
+
+ //only special chars
+ '!@#$%^&*()_+=-`~'
+);
+
+// loop through the $str_array array to test ucwords on each element
+$iteration = 1;
+for($index = 0; $index < count($str_array); $index++) {
+ echo "-- Iteration $iteration --\n";
+ var_dump( ucwords($str_array[$index]) );
+ $iteration++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : usage variations ***
+-- Iteration 1 --
+string(18) "Testing Ucwords"
+-- Iteration 2 --
+string(30) "T E S T I N G U C W O R D S "
+-- Iteration 3 --
+string(25) "Testing Function(ucwords)"
+-- Iteration 4 --
+string(38) "(testing ( Function (ucwords) )a )test"
+-- Iteration 5 --
+string(3) "(t)"
+-- Iteration 6 --
+string(7) " ( T )t"
+-- Iteration 7 --
+string(23) ""testing",ucword,"test""
+-- Iteration 8 --
+string(14) ""t""t",test, T"
+-- Iteration 9 --
+string(11) "'t 't',test"
+-- Iteration 10 --
+string(27) "\ttesting\ttesting\tucwords"
+-- Iteration 11 --
+string(32) "Testing\rucwords Testing Ucwords"
+-- Iteration 12 --
+string(37) "Testing\fucwords \f Testing \nucwords"
+-- Iteration 13 --
+string(39) "\ntesting\nucwords\n Testing \n Ucwords"
+-- Iteration 14 --
+string(20) "Using\vvertical\vtab"
+-- Iteration 15 --
+string(42) "T@@#$% %test ^test &test *test +test -test"
+-- Iteration 16 --
+string(40) "!test ~test `test` =test= @test@test.com"
+-- Iteration 17 --
+string(40) "/test/r\test\ucwords\t\y\y\u\3 \yy\ /uu/"
+-- Iteration 18 --
+string(16) "!@#$%^&*()_+=-`~"
+Done
diff --git a/ext/standard/tests/strings/ucwords_variation4.phpt b/ext/standard/tests/strings/ucwords_variation4.phpt
new file mode 100644
index 0000000000..1e5f242d18
--- /dev/null
+++ b/ext/standard/tests/strings/ucwords_variation4.phpt
@@ -0,0 +1,125 @@
+--TEST--
+Test ucwords() function : usage variations - double quoted string
+--FILE--
+<?php
+/* Prototype : string ucwords ( string $str )
+ * Description: Uppercase the first character of each word in a string
+ * Source code: ext/standard/string.c
+*/
+
+/*
+ * test ucwords() with different string prepared using double quote
+*/
+
+echo "*** Testing ucwords() : usage variations ***\n";
+
+// different strings containing regular chars and special chars
+$str_array = array(
+ // multiple spaces
+ "testing ucwords",
+ "t e s t i n g u c w o r d s ",
+
+ // brackets in sentence
+ "testing function(ucwords)",
+ "(testing ( function (ucwords) )a )test",
+ "(t)",
+ " ( t )t",
+
+ // using quote chars in sentence
+ "\"testing\",ucwords,\"test\"",
+ "\"t\"\"t\",test, t",
+ "\'t \'t\',test",
+ "Jack's pen",
+ "P't'y 't it's ",
+
+ // using other white spaces
+ "\ttesting\ttesting\tucwords",
+ "\\ttesting\\ttesting\tucwords",
+ "testing\rucwords testing ucwords",
+ "testing\\rucwords testing ucwords",
+ "testing\fucwords \f testing \nucwords",
+ "testing\\fucwords \\f testing \nucwords",
+ "\ntesting\nucwords\n testing \n ucwords",
+ "\\ntesting\\nucwords\\n testing \\n ucwords",
+ "using\vvertical\vtab",
+ "using\\vvertical\\vtab",
+
+ //using special chars in sentence
+ "t@@#$% %test ^test &test *test +test -test",
+ "!test ~test `test` =test= @test@test.com",
+ "/test/r\test\ucwords\t\y\y\u\3 \yy\ /uu/",
+
+ //only special chars
+ "!@#$%^&*()_+=-`~"
+);
+
+// loop through the $str_array array to test ucwords on each element
+$iteration = 1;
+for($index = 0; $index < count($str_array); $index++) {
+ echo "-- Iteration $iteration --\n";
+ var_dump( ucwords($str_array[$index]) );
+ $iteration++;
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing ucwords() : usage variations ***
+-- Iteration 1 --
+string(18) "Testing Ucwords"
+-- Iteration 2 --
+string(30) "T E S T I N G U C W O R D S "
+-- Iteration 3 --
+string(25) "Testing Function(ucwords)"
+-- Iteration 4 --
+string(38) "(testing ( Function (ucwords) )a )test"
+-- Iteration 5 --
+string(3) "(t)"
+-- Iteration 6 --
+string(7) " ( T )t"
+-- Iteration 7 --
+string(24) ""testing",ucwords,"test""
+-- Iteration 8 --
+string(14) ""t""t",test, T"
+-- Iteration 9 --
+string(14) "\'t \'t\',test"
+-- Iteration 10 --
+string(10) "Jack's Pen"
+-- Iteration 11 --
+string(14) "P't'y 't It's "
+-- Iteration 12 --
+string(24) " Testing Testing Ucwords"
+-- Iteration 13 --
+string(26) "\ttesting\ttesting Ucwords"
+-- Iteration 14 --
+string(31) "Testing
+Ucwords Testing Ucwords"
+-- Iteration 15 --
+string(32) "Testing\rucwords Testing Ucwords"
+-- Iteration 16 --
+string(36) "Testing\fucwords \f Testing
+Ucwords"
+-- Iteration 17 --
+string(36) "Testing\fucwords \f Testing
+Ucwords"
+-- Iteration 18 --
+string(35) "
+Testing
+Ucwords
+ Testing
+ Ucwords"
+-- Iteration 19 --
+string(39) "\ntesting\nucwords\n Testing \n Ucwords"
+-- Iteration 20 --
+string(20) "Using\vvertical\vtab"
+-- Iteration 21 --
+string(20) "Using\vvertical\vtab"
+-- Iteration 22 --
+string(42) "T@@#$% %test ^test &test *test +test -test"
+-- Iteration 23 --
+string(40) "!test ~test `test` =test= @test@test.com"
+-- Iteration 24 --
+string(37) "/test/r Est\ucwords \y\y\u \yy\ /uu/"
+-- Iteration 25 --
+string(16) "!@#$%^&*()_+=-`~"
+Done