-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from PHPCSStandards/feature/new-common-stripc…
…olors-method New Common::stripColors() method
- Loading branch information
Showing
4 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Tests for the \PHP_CodeSniffer\Util\Sniffs\Common::stripColors() method. | ||
* | ||
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> | ||
* @copyright 2024 Juliette Reinders Folmer. All rights reserved. | ||
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\Util; | ||
|
||
use PHP_CodeSniffer\Util\Common; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Tests for the \PHP_CodeSniffer\Util\Sniffs\Common::stripColors() method. | ||
* | ||
* @covers \PHP_CodeSniffer\Util\Common::stripColors | ||
*/ | ||
final class StripColorsTest extends TestCase | ||
{ | ||
|
||
|
||
/** | ||
* Test stripping color codes from a text. | ||
* | ||
* @param string $text The text provided. | ||
* @param string $expected Expected function output. | ||
* | ||
* @dataProvider dataStripColors | ||
* | ||
* @return void | ||
*/ | ||
public function testStripColors($text, $expected) | ||
{ | ||
$this->assertSame($expected, Common::stripColors($text)); | ||
|
||
}//end testStripColors() | ||
|
||
|
||
/** | ||
* Data provider. | ||
* | ||
* @see testStripColors() | ||
* | ||
* @return array<string, array<string, string>> | ||
*/ | ||
public static function dataStripColors() | ||
{ | ||
return [ | ||
'Text is empty' => [ | ||
'text' => '', | ||
'expected' => '', | ||
], | ||
'Text enclosed in color code' => [ | ||
'text' => "\033[36mSome text\033[0m", | ||
'expected' => 'Some text', | ||
], | ||
'Text containing color code' => [ | ||
'text' => "Some text \033[33mSome other text", | ||
'expected' => 'Some text Some other text', | ||
], | ||
'Text enclosed in color code, bold' => [ | ||
'text' => "\033[1;32mSome text\033[0m", | ||
'expected' => 'Some text', | ||
], | ||
'Text enclosed in color code, with escaped text' => [ | ||
'text' => "\033[30;1m\\n\033[0m", | ||
'expected' => '\n', | ||
], | ||
'Text enclosed in color code, bold, dark, italic' => [ | ||
'text' => "\033[1;2;3mtext\033[0m", | ||
'expected' => 'text', | ||
], | ||
'Text enclosed in color code, foreground color' => [ | ||
'text' => "\033[38;5;255mtext\033[0m", | ||
'expected' => 'text', | ||
], | ||
'Text enclosed in color code, foreground color and background color' => [ | ||
'text' => "\033[38;5;200;48;5;255mtext\033[0m", | ||
'expected' => 'text', | ||
], | ||
'Multiline text containing multiple color codes' => [ | ||
'text' => "First \033[36mSecond\033[0m | ||
Third \033[1;2;3mFourth | ||
Next line\033[0m Last", | ||
'expected' => 'First Second | ||
Third Fourth | ||
Next line Last', | ||
], | ||
]; | ||
|
||
}//end dataStripColors() | ||
|
||
|
||
}//end class |