Skip to content

Commit

Permalink
Tests/BackfillNumericSeparatorTest: use named data sets
Browse files Browse the repository at this point in the history
With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed.

With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number.

Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number.
Using named data sets also documents what exactly each data set is testing.

Aside from adding the data set name, this commit also adds the parameter name for each item in the data set, this time in an effort to make it more straight forward to update and add tests as it will be more obvious what each key in the data set signifies.

Includes:
* Making the data type in the docblock more specific.
  • Loading branch information
jrfnl committed Jan 14, 2024
1 parent 61aa313 commit 0fb1c2f
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions tests/Core/Tokenizer/BackfillNumericSeparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testBackfill($marker, $type, $value)
*
* @see testBackfill()
*
* @return array
* @return array<string, array<string, string>>
*/
public static function dataTestBackfill()
{
Expand All @@ -64,67 +64,67 @@ public static function dataTestBackfill()
}

return [
[
'decimal integer' => [
'marker' => '/* testSimpleLNumber */',
'type' => 'T_LNUMBER',
'value' => '1_000_000_000',
],
[
'float' => [
'marker' => '/* testSimpleDNumber */',
'type' => 'T_DNUMBER',
'value' => '107_925_284.88',
],
[
'float, scientific notation, negative exponent with sigh' => [
'marker' => '/* testFloat */',
'type' => 'T_DNUMBER',
'value' => '6.674_083e-11',
],
[
'float, scientific notation, positive exponent with sign' => [
'marker' => '/* testFloat2 */',
'type' => 'T_DNUMBER',
'value' => '6.674_083e+11',
],
[
'float, scientific notation, positive exponent without sign' => [
'marker' => '/* testFloat3 */',
'type' => 'T_DNUMBER',
'value' => '1_2.3_4e1_23',
],
[
'hexidecimal integer/float' => [
'marker' => '/* testHex */',
'type' => $testHexType,
'value' => '0xCAFE_F00D',
],
[
'hexidecimal integer/float with multiple underscores' => [
'marker' => '/* testHexMultiple */',
'type' => $testHexMultipleType,
'value' => '0x42_72_6F_77_6E',
],
[
'hexidecimal integer' => [
'marker' => '/* testHexInt */',
'type' => 'T_LNUMBER',
'value' => '0x42_72_6F',
],
[
'binary integer' => [
'marker' => '/* testBinary */',
'type' => 'T_LNUMBER',
'value' => '0b0101_1111',
],
[
'octal integer' => [
'marker' => '/* testOctal */',
'type' => 'T_LNUMBER',
'value' => '0137_041',
],
[
'octal integer using explicit octal notation' => [
'marker' => '/* testExplicitOctal */',
'type' => 'T_LNUMBER',
'value' => '0o137_041',
],
[
'octal integer using explicit octal notation with capital O' => [
'marker' => '/* testExplicitOctalCapitalised */',
'type' => 'T_LNUMBER',
'value' => '0O137_041',
],
[
'integer more than PHP_INT_MAX becomes a float' => [
'marker' => '/* testIntMoreThanMax */',
'type' => $testIntMoreThanMaxType,
'value' => '10_223_372_036_854_775_807',
Expand All @@ -138,8 +138,8 @@ public static function dataTestBackfill()
* Test that numbers using numeric separators which are considered parse errors and/or
* which aren't relevant to the backfill, do not incorrectly trigger the backfill anyway.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param array $expectedTokens The token type and content of the expected token sequence.
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param array<array<string, int|string>> $expectedTokens The token type and content of the expected token sequence.
*
* @dataProvider dataNoBackfill
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
Expand All @@ -165,14 +165,14 @@ public function testNoBackfill($testMarker, $expectedTokens)
*
* @see testBackfill()
*
* @return array
* @return array<string, array<string, string|array<array<string, int|string>>>>
*/
public static function dataNoBackfill()
{
return [
[
'/* testInvalid1 */',
[
'invalid: trailing underscore' => [
'testMarker' => '/* testInvalid1 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '100',
Expand All @@ -183,9 +183,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid2 */',
[
'invalid: two consecutive underscores' => [
'testMarker' => '/* testInvalid2 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '1',
Expand All @@ -196,9 +196,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid3 */',
[
'invalid: underscore directly before decimal point' => [
'testMarker' => '/* testInvalid3 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '1',
Expand All @@ -213,9 +213,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid4 */',
[
'invalid: underscore directly after decimal point' => [
'testMarker' => '/* testInvalid4 */',
'expectedTokens' => [
[
'code' => T_DNUMBER,
'content' => '1.',
Expand All @@ -226,9 +226,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid5 */',
[
'invalid: hex int - underscore directly after x' => [
'testMarker' => '/* testInvalid5 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '0',
Expand All @@ -239,9 +239,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid6 */',
[
'invalid: binary int - underscore directly after b' => [
'testMarker' => '/* testInvalid6 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '0',
Expand All @@ -252,9 +252,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid7 */',
[
'invalid: scientific float - underscore directly before e' => [
'testMarker' => '/* testInvalid7 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '1',
Expand All @@ -265,9 +265,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid8 */',
[
'invalid: scientific float - underscore directly after e' => [
'testMarker' => '/* testInvalid8 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '1',
Expand All @@ -278,9 +278,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid9 */',
[
'invalid: space between parts of the number' => [
'testMarker' => '/* testInvalid9 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '107_925_284',
Expand All @@ -295,9 +295,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid10 */',
[
'invalid: comment within the number' => [
'testMarker' => '/* testInvalid10 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '107_925_284',
Expand All @@ -312,9 +312,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid11 */',
[
'invalid: explicit octal int - underscore directly after o' => [
'testMarker' => '/* testInvalid11 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '0',
Expand All @@ -325,9 +325,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testInvalid12 */',
[
'invalid: explicit octal int - underscore directly after capital O' => [
'testMarker' => '/* testInvalid12 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '0',
Expand All @@ -338,9 +338,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* testCalc1 */',
[
'calculations should be untouched - int - int' => [
'testMarker' => '/* testCalc1 */',
'expectedTokens' => [
[
'code' => T_LNUMBER,
'content' => '667_083',
Expand All @@ -363,9 +363,9 @@ public static function dataNoBackfill()
],
],
],
[
'/* test Calc2 */',
[
'calculations should be untouched - scientific float + int' => [
'testMarker' => '/* test Calc2 */',
'expectedTokens' => [
[
'code' => T_DNUMBER,
'content' => '6.674_08e3',
Expand Down

0 comments on commit 0fb1c2f

Please sign in to comment.