Skip to content

Commit

Permalink
Merge pull request #538 from PHPCSStandards/feature/tests-gettokensas…
Browse files Browse the repository at this point in the history
…string-minor-improvements

Tests/GetTokensAsStringTest: : minor improvements
  • Loading branch information
jrfnl authored Jan 2, 2024
2 parents 09b59fc + 67db64b commit a7dee62
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 136 deletions.
204 changes: 102 additions & 102 deletions Tests/BackCompat/BCFile/GetTokensAsStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public function testLengthBeyondEndOfFile()
*
* @dataProvider dataGetTokensAsString()
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param int|string|array $startTokenType The type of token(s) to look for for the start of the string.
* @param int $length Token length to get.
* @param string $expected The expected function return value.
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param int|string $startTokenType The type of token(s) to look for for the start of the string.
* @param int $length Token length to get.
* @param string $expected The expected function return value.
*
* @return void
*/
Expand All @@ -114,151 +114,151 @@ public function testGetTokensAsString($testMarker, $startTokenType, $length, $ex
*
* @see testGetTokensAsString() For the array format.
*
* @return array
* @return array<string, array<string, string|int>>
*/
public static function dataGetTokensAsString()
{
$php8Names = parent::usesPhp8NameTokens();

return [
'length-0' => [
'/* testCalculation */',
\T_LNUMBER,
0,
'',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 0,
'expected' => '',
],
'length-1' => [
'/* testCalculation */',
\T_LNUMBER,
1,
'1',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 1,
'expected' => '1',
],
'length-2' => [
'/* testCalculation */',
\T_LNUMBER,
2,
'1 ',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 2,
'expected' => '1 ',
],
'length-3' => [
'/* testCalculation */',
\T_LNUMBER,
3,
'1 +',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 3,
'expected' => '1 +',
],
'length-4' => [
'/* testCalculation */',
\T_LNUMBER,
4,
'1 + ',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 4,
'expected' => '1 + ',
],
'length-5' => [
'/* testCalculation */',
\T_LNUMBER,
5,
'1 + 2',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 5,
'expected' => '1 + 2',
],
'length-6' => [
'/* testCalculation */',
\T_LNUMBER,
6,
'1 + 2 ',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 6,
'expected' => '1 + 2 ',
],
'length-7' => [
'/* testCalculation */',
\T_LNUMBER,
7,
'1 + 2 +',
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 7,
'expected' => '1 + 2 +',
],
'length-8' => [
'/* testCalculation */',
\T_LNUMBER,
8,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 8,
'expected' => '1 + 2 +
',
],
'length-9' => [
'/* testCalculation */',
\T_LNUMBER,
9,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 9,
'expected' => '1 + 2 +
',
],
'length-10' => [
'/* testCalculation */',
\T_LNUMBER,
10,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 10,
'expected' => '1 + 2 +
// Comment.
',
],
'length-11' => [
'/* testCalculation */',
\T_LNUMBER,
11,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 11,
'expected' => '1 + 2 +
// Comment.
',
],
'length-12' => [
'/* testCalculation */',
\T_LNUMBER,
12,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 12,
'expected' => '1 + 2 +
// Comment.
3',
],
'length-13' => [
'/* testCalculation */',
\T_LNUMBER,
13,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 13,
'expected' => '1 + 2 +
// Comment.
3 ',
],
'length-14' => [
'/* testCalculation */',
\T_LNUMBER,
14,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 14,
'expected' => '1 + 2 +
// Comment.
3 +',
],
'length-34' => [
'/* testCalculation */',
\T_LNUMBER,
34,
'1 + 2 +
'testMarker' => '/* testCalculation */',
'startTokenType' => \T_LNUMBER,
'length' => 34,
'expected' => '1 + 2 +
// Comment.
3 + 4
+ 5 + 6 + 7 > 20;',
],
'namespace' => [
'/* testNamespace */',
\T_NAMESPACE,
($php8Names === true) ? 4 : 8,
'namespace Foo\Bar\Baz;',
'testMarker' => '/* testNamespace */',
'startTokenType' => \T_NAMESPACE,
'length' => ($php8Names === true) ? 4 : 8,
'expected' => 'namespace Foo\Bar\Baz;',
],
'use-with-comments' => [
'/* testUseWithComments */',
\T_USE,
17,
'use Foo /*comment*/ \ Bar
'testMarker' => '/* testUseWithComments */',
'startTokenType' => \T_USE,
'length' => 17,
'expected' => 'use Foo /*comment*/ \ Bar
// phpcs:ignore Stnd.Cat.Sniff -- For reasons.
\ Bah;',
],
'echo-with-tabs' => [
'/* testEchoWithTabs */',
\T_ECHO,
13,
'echo \'foo\',
'testMarker' => '/* testEchoWithTabs */',
'startTokenType' => \T_ECHO,
'length' => 13,
'expected' => 'echo \'foo\',
\'bar\' ,
\'baz\';',
],
'end-of-file' => [
'/* testEndOfFile */',
\T_ECHO,
4,
'echo $foo;',
'testMarker' => '/* testEndOfFile */',
'startTokenType' => \T_ECHO,
'length' => 4,
'expected' => 'echo $foo;',
],
];
}
Expand All @@ -268,10 +268,10 @@ public static function dataGetTokensAsString()
*
* @dataProvider dataGetOrigContent()
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param int|string|array $startTokenType The type of token(s) to look for for the start of the string.
* @param int $length Token length to get.
* @param string $expected The expected function return value.
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param int|string $startTokenType The type of token(s) to look for for the start of the string.
* @param int $length Token length to get.
* @param string $expected The expected function return value.
*
* @return void
*/
Expand All @@ -287,32 +287,32 @@ public function testGetOrigContent($testMarker, $startTokenType, $length, $expec
*
* @see testGetOrigContent() For the array format.
*
* @return array
* @return array<string, array<string, string|int>>
*/
public static function dataGetOrigContent()
{
return [
'use-with-comments' => [
'/* testUseWithComments */',
\T_USE,
17,
'use Foo /*comment*/ \ Bar
'testMarker' => '/* testUseWithComments */',
'startTokenType' => \T_USE,
'length' => 17,
'expected' => 'use Foo /*comment*/ \ Bar
// phpcs:ignore Stnd.Cat.Sniff -- For reasons.
\ Bah;',
],
'echo-with-tabs' => [
'/* testEchoWithTabs */',
\T_ECHO,
13,
'echo \'foo\',
'testMarker' => '/* testEchoWithTabs */',
'startTokenType' => \T_ECHO,
'length' => 13,
'expected' => 'echo \'foo\',
\'bar\' ,
\'baz\';',
],
'end-of-file' => [
'/* testEndOfFile */',
\T_ECHO,
4,
'echo $foo;',
'testMarker' => '/* testEndOfFile */',
'startTokenType' => \T_ECHO,
'length' => 4,
'expected' => 'echo $foo;',
],
];
}
Expand Down
Loading

0 comments on commit a7dee62

Please sign in to comment.