1
0
mirror of https://github.com/php/php-src.git synced 2026-04-20 06:21:12 +02:00
Files
archived-php-src/ext/standard/tests/strings/trim1.phpt
Peter Kokot d679f02295 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:33:09 +02:00

92 lines
2.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--TEST--
Test trim() function
--FILE--
<?php
/* Prototype: string trim( string str [,string charlist] )
* Strip whitespace (or other characters) from the beginning and end of a string.
*/
/* trim with unset/null/boolean variable - returns an empty string */
echo "\n";
$null_var = NULL;
var_dump( trim($null_var) );
$null_var = "";
var_dump( trim($null_var) );
$null_var = 0;
var_dump( trim($null_var) );
$bool_val = true;
var_dump( trim($null_var) );
/* second argument charlist as null - does not trim any white spaces */
var_dump( trim("\ttesting trim", "") );
var_dump( trim(" \ttesting trim ", NULL) );
var_dump( trim("\ttesting trim ", true) );
/* Testing error conditions */
echo "\n*** Testing error conditions ***\n";
//Zero arguments
var_dump( trim() );
// More than expected number of args */
var_dump( trim("\tstring\n", "\t\n", $null_var) );
var_dump( trim(NULL, "", NULL ) );
/* Use of class and objects */
echo "\n*** Testing with OBJECTS ***\n";
class string1
{
public function __toString() {
return "Object";
}
}
$obj = new string1;
var_dump( trim($obj, "Ot") );
/* String with embedded NULL */
echo "\n*** Testing with String with embedded NULL ***\n";
var_dump( trim("\x0n1234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
/* heredoc string */
$str = <<<EOD
us
ing heredoc string
EOD;
echo "\n*** Testing with heredoc string ***\n";
var_dump( trim($str, "us\ning") );
echo "\nDone";
?>
--EXPECTF--
string(0) ""
string(0) ""
string(1) "0"
string(1) "0"
string(13) " testing trim"
string(17) " testing trim "
string(15) " testing trim "
*** Testing error conditions ***
Warning: trim() expects at least 1 parameter, 0 given in %s on line %d
NULL
Warning: trim() expects at most 2 parameters, 3 given in %s on line %d
NULL
Warning: trim() expects at most 2 parameters, 3 given in %s on line %d
NULL
*** Testing with OBJECTS ***
string(4) "bjec"
*** Testing with String with embedded NULL ***
string(22) "2340567800efgh\xijkl"
*** Testing with heredoc string ***
string(12) " heredoc str"
Done