wharmby Sat Jan 17 15:47:59 2009 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/strings ltrim_error.phpt
ltrim_variation2.phpt
ltrim_basic.phpt
ltrim_variation1.phpt
Log:
New ltrim() tests. Tested on Windows, Linux and Linux 64 bit
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/ltrim_error.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/ltrim_error.phpt
+++ php-src/ext/standard/tests/strings/ltrim_error.phpt
--TEST--
Test ltrim() function : error conditions
--FILE--
<?php
/* Prototype : string ltrim ( string $str [, string $charlist ] )
* Description: Strip whitespace (or other characters) from the beginning of a
string.
* Source code: ext/standard/string.c
*/
echo "*** Testing ltrim() : error conditions ***\n";
echo "\n-- Testing ltrim() function with no arguments --\n";
var_dump( ltrim() );
echo "\n-- Testing ltrim() function with more than expected no. of arguments
--\n";
$extra_arg = 10;
var_dump( ltrim("Hello World", "Heo", $extra_arg) );
$hello = " Hello World\n";
echo "\n-- Test ltrim function with various invalid charlists\n";
var_dump(ltrim($hello, "..a"));
var_dump(ltrim($hello, "a.."));
var_dump(ltrim($hello, "z..a"));
var_dump(ltrim($hello, "a..b..c"));
?>
===DONE===
--EXPECTF--
*** Testing ltrim() : error conditions ***
-- Testing ltrim() function with no arguments --
Warning: ltrim() expects at least 1 parameter, 0 given in %s on line %d
NULL
-- Testing ltrim() function with more than expected no. of arguments --
Warning: ltrim() expects at most 2 parameters, 3 given in %s on line %d
NULL
-- Test ltrim function with various invalid charlists
Warning: ltrim(): Invalid '..'-range, no character to the left of '..' in %s on
line %d
unicode(14) " Hello World
"
Warning: ltrim(): Invalid '..'-range, no character to the right of '..' in %s
on line %d
unicode(14) " Hello World
"
Warning: ltrim(): Invalid '..'-range, '..'-range needs to be incrementing in %s
on line %d
unicode(14) " Hello World
"
Warning: ltrim(): Invalid '..'-range in %s on line %d
unicode(14) " Hello World
"
===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/ltrim_variation2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/ltrim_variation2.phpt
+++ php-src/ext/standard/tests/strings/ltrim_variation2.phpt
--TEST--
Test ltrim() function : usage variations - test values for $charlist argument
--FILE--
<?php
/* Prototype : string ltrim ( string $str [, string $charlist ] )
* Description: Strip whitespace (or other characters) from the beginning of a
string.
* Source code: ext/standard/string.c
*/
echo "*** Testing ltrim() function: with unexpected inputs for 'charlist'
argument ***\n";
//get an unset variable
$unset_var = ' string_val ';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return " sample object ";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
255,
256,
2147483647,
-2147483648,
// float values
/*7*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*10*/ array(),
array(0),
array(1, 2),
// boolean values
/*13*/ true,
false,
TRUE,
FALSE,
// null values
/*17*/ NULL,
null,
// objects
/*19*/ new sample(),
// resource
/*20*/ $file_handle,
// undefined variable
/*21*/ @$undefined_var,
// unset variable
/*22*/ @$unset_var
);
// loop through with each element of the $inputs array to test ltrim() function
$count = 1;
foreach($inputs as $charlist) {
echo "-- Iteration $count --\n";
// strip white space and any "minus" signs
var_dump( ltrim("!---Hello World---!", $charlist) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing ltrim() function: with unexpected inputs for 'charlist' argument ***
-- Iteration 1 --
unicode(19) "!---Hello World---!"
-- Iteration 2 --
unicode(19) "!---Hello World---!"
-- Iteration 3 --
unicode(19) "!---Hello World---!"
-- Iteration 4 --
unicode(19) "!---Hello World---!"
-- Iteration 5 --
unicode(19) "!---Hello World---!"
-- Iteration 6 --
unicode(19) "!---Hello World---!"
-- Iteration 7 --
unicode(19) "!---Hello World---!"
-- Iteration 8 --
unicode(19) "!---Hello World---!"
-- Iteration 9 --
unicode(19) "!---Hello World---!"
-- Iteration 10 --
Warning: ltrim() expects parameter 2 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 11 --
Warning: ltrim() expects parameter 2 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 12 --
Warning: ltrim() expects parameter 2 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 13 --
unicode(19) "!---Hello World---!"
-- Iteration 14 --
unicode(19) "!---Hello World---!"
-- Iteration 15 --
unicode(19) "!---Hello World---!"
-- Iteration 16 --
unicode(19) "!---Hello World---!"
-- Iteration 17 --
unicode(19) "!---Hello World---!"
-- Iteration 18 --
unicode(19) "!---Hello World---!"
-- Iteration 19 --
unicode(19) "!---Hello World---!"
-- Iteration 20 --
Warning: ltrim() expects parameter 2 to be string (Unicode or binary), resource
given in %s on line %d
NULL
-- Iteration 21 --
unicode(19) "!---Hello World---!"
-- Iteration 22 --
unicode(19) "!---Hello World---!"
===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/ltrim_basic.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/ltrim_basic.phpt
+++ php-src/ext/standard/tests/strings/ltrim_basic.phpt
--TEST--
Test ltrim() function : basic functionality
--FILE--
<?php
/* Prototype : string ltrim ( string $str [, string $charlist ] )
* Description: Strip whitespace (or other characters) from the beginning of a
string.
* Source code: ext/standard/string.c
*/
echo "*** Testing ltrim() : basic functionality ***\n";
$text = " \t\r\n\0\x0B ---These are a few words--- ";
$hello = "!===Hello World===!";
$binary = "\x09\x0AExample string";
$alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
echo "\n-- Trim string with all white space characters --\n";
var_dump(ltrim($text));
echo "\n-- Trim non-whitespace from a string --\n";
var_dump(ltrim($hello, "=!"));
echo "\n-- Trim some non-white space characters from a string --\n";
var_dump(ltrim($hello, "!oleH="));
echo "\n-- Trim some non-white space characters from a string suing a character
range --\n";
var_dump(ltrim($alpha, "A..Z"));
echo "\n-- Trim the ASCII control characters at the beginning of a string --\n";
var_dump(ltrim($binary, "\x00..\x1F"));
?>
===DONE===
--EXPECT--
*** Testing ltrim() : basic functionality ***
-- Trim string with all white space characters --
unicode(29) "---These are a few words--- "
-- Trim non-whitespace from a string --
unicode(15) "Hello World===!"
-- Trim some non-white space characters from a string --
unicode(10) " World===!"
-- Trim some non-white space characters from a string suing a character range --
unicode(10) "0123456789"
-- Trim the ASCII control characters at the beginning of a string --
unicode(14) "Example string"
===DONE===
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/ltrim_variation1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/ltrim_variation1.phpt
+++ php-src/ext/standard/tests/strings/ltrim_variation1.phpt
--TEST--
Test ltrim() function : usage variations - test values for $str argument
--FILE--
<?php
/* Prototype : string ltrim ( string $str [, string $charlist ] )
* Description: Strip whitespace (or other characters) from the beginning of a
string.
* Source code: ext/standard/string.c
*/
echo "*** Testing ltrim() function: with unexpected inputs for 'str' argument
***\n";
//get an unset variable
$unset_var = ' string_val ';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return " sample object ";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $input
$inputs = array (
// integer values
/*1*/ 0,
1,
255,
256,
2147483647,
-2147483648,
// float values
/*7*/ 10.5,
-20.5,
10.1234567e10,
// array values
/*10*/ array(),
array(0),
array(1, 2),
// boolean values
/*13*/ true,
false,
TRUE,
FALSE,
// null values
/*17*/ NULL,
null,
// objects
/*19*/ new sample(),
// resource
/*20*/ $file_handle,
// undefined variable
/*22*/ @$undefined_var,
// unset variable
/*23*/ @$unset_var
);
// loop through with each element of the $inputs array to test ltrim() function
$count = 1;
foreach($inputs as $input) {
echo "-- Iteration $count --\n";
// strip white space and any "minus" signs
var_dump( ltrim($input, " \t-") );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===DONE===
--EXPECTF--
*** Testing ltrim() function: with unexpected inputs for 'str' argument ***
-- Iteration 1 --
unicode(1) "0"
-- Iteration 2 --
unicode(1) "1"
-- Iteration 3 --
unicode(3) "255"
-- Iteration 4 --
unicode(3) "256"
-- Iteration 5 --
unicode(10) "2147483647"
-- Iteration 6 --
unicode(10) "2147483648"
-- Iteration 7 --
unicode(4) "10.5"
-- Iteration 8 --
unicode(4) "20.5"
-- Iteration 9 --
unicode(12) "101234567000"
-- Iteration 10 --
Warning: ltrim() expects parameter 1 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 11 --
Warning: ltrim() expects parameter 1 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 12 --
Warning: ltrim() expects parameter 1 to be string (Unicode or binary), array
given in %s on line %d
NULL
-- Iteration 13 --
unicode(1) "1"
-- Iteration 14 --
unicode(0) ""
-- Iteration 15 --
unicode(1) "1"
-- Iteration 16 --
unicode(0) ""
-- Iteration 17 --
unicode(0) ""
-- Iteration 18 --
unicode(0) ""
-- Iteration 19 --
unicode(15) "sample object "
-- Iteration 20 --
Warning: ltrim() expects parameter 1 to be string (Unicode or binary), resource
given in %s on line %d
NULL
-- Iteration 21 --
unicode(0) ""
-- Iteration 22 --
unicode(0) ""
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php