php-src/ext/standard/tests/strings/rtrim_basic.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

54 lines
1.5 KiB
PHP

--TEST--
Test rtrim() function : basic functionality
--FILE--
<?php
/* Prototype : string rtrim ( string $str [, string $charlist ] )
* Description: Strip whitespace (or other characters) from the end of a string.
* Source code: ext/standard/string.c
*/
echo "*** Testing rtrim() : basic functionality ***\n";
$text = "---These are a few words--- \t\r\n\0\x0B ";
$hello = "!===Hello World===!";
$alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$binary = "Example string\x0A\x0D";
echo "\n-- Trim string with all white space characters --\n";
var_dump(rtrim($text));
echo "\n-- Trim non-whitespace from a string --\n";
var_dump(rtrim($hello, "=!"));
echo "\n-- Trim some non-white space characters from a string --\n";
var_dump(rtrim($hello, "!dlWro="));
echo "\n-- Trim some non-white space characters from a string using a character range --\n";
var_dump(rtrim($alpha, "A..Z"));
echo "\n-- Trim the ASCII control characters at the beginning of a string --\n";
var_dump(rtrim($binary, "\x00..\x1F"));
?>
===DONE===
--EXPECT--
*** Testing rtrim() : basic functionality ***
-- Trim string with all white space characters --
string(27) "---These are a few words---"
-- Trim non-whitespace from a string --
string(15) "!===Hello World"
-- Trim some non-white space characters from a string --
string(10) "!===Hello "
-- Trim some non-white space characters from a string using a character range --
string(10) "0123456789"
-- Trim the ASCII control characters at the beginning of a string --
string(14) "Example string"
===DONE===