123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace PhpCsFixer\Tests;
- use PhpCsFixer\Tokenizer\Token;
- use PhpCsFixer\Utils;
- use PHPUnit\Framework\TestCase;
- final class UtilsTest extends TestCase
- {
-
- public function testCamelCaseToUnderscore($expected, $input = null)
- {
- if (null !== $input) {
- $this->assertSame($expected, Utils::camelCaseToUnderscore($input));
- }
- $this->assertSame($expected, Utils::camelCaseToUnderscore($expected));
- }
-
- public function provideCamelCaseToUnderscoreCases()
- {
- return [
- [
- 'dollar_close_curly_braces',
- 'DollarCloseCurlyBraces',
- ],
- [
- 'utf8_encoder_fixer',
- 'utf8EncoderFixer',
- ],
- [
- 'terminated_with_number10',
- 'TerminatedWithNumber10',
- ],
- [
- 'utf8_encoder_fixer',
- ],
- ];
- }
-
- public function testCmpInt($expected, $left, $right)
- {
- $this->assertSame($expected, Utils::cmpInt($left, $right));
- }
- public function provideCmpIntCases()
- {
- return [
- [0, 1, 1],
- [0, -1, -1],
- [-1, 10, 20],
- [-1, -20, -10],
- [1, 20, 10],
- [1, -10, -20],
- ];
- }
-
- public function testSplitLines(array $expected, $input)
- {
- $this->assertSame($expected, Utils::splitLines($input));
- }
- public function provideSplitLinesCases()
- {
- return [
- [
- ["\t aaa\n", " bbb\n", "\t"],
- "\t aaa\n bbb\n\t",
- ],
- [
- ["aaa\r\n", " bbb\r\n"],
- "aaa\r\n bbb\r\n",
- ],
- [
- ["aaa\r\n", " bbb\n"],
- "aaa\r\n bbb\n",
- ],
- [
- ["aaa\r\n\n\n\r\n", " bbb\n"],
- "aaa\r\n\n\n\r\n bbb\n",
- ],
- ];
- }
-
- public function testCalculateTrailingWhitespaceIndent($spaces, $input)
- {
- $token = new Token([T_WHITESPACE, $input]);
- $this->assertSame($spaces, Utils::calculateTrailingWhitespaceIndent($token));
- }
- public function provideCalculateTrailingWhitespaceIndentCases()
- {
- return [
- [' ', "\n\n "],
- [' ', "\r\n\r\r\r "],
- ["\t", "\r\n\t"],
- ['', "\t\n\r"],
- ['', "\n"],
- ['', ''],
- ];
- }
- public function testCalculateTrailingWhitespaceIndentFail()
- {
- $this->setExpectedException(
- \InvalidArgumentException::class,
- 'The given token must be whitespace, got "T_STRING".'
- );
- $token = new Token([T_STRING, 'foo']);
- Utils::calculateTrailingWhitespaceIndent($token);
- }
- }
|