@@ -18,22 +18,26 @@ class BackfillExplicitOctalNotationTest extends AbstractMethodUnitTest
18
18
/**
19
19
* Test that explicitly-defined octal values are tokenized as a single number and not as a number and a string.
20
20
*
21
- * @param array $testData The data required for the specific test case.
21
+ * @param string $marker The comment which prefaces the target token in the test file.
22
+ * @param string $value The expected content of the token
23
+ * @param int|string $nextToken The expected next token.
24
+ * @param string $nextContent The expected content of the next token.
22
25
*
23
26
* @dataProvider dataExplicitOctalNotation
24
27
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
25
28
*
26
29
* @return void
27
30
*/
28
- public function testExplicitOctalNotation ($ testData )
31
+ public function testExplicitOctalNotation ($ marker , $ value , $ nextToken , $ nextContent )
29
32
{
30
33
$ tokens = self ::$ phpcsFile ->getTokens ();
31
34
32
- $ number = $ this ->getTargetToken ($ testData [ ' marker ' ] , [T_LNUMBER ]);
35
+ $ number = $ this ->getTargetToken ($ marker , [T_LNUMBER ]);
33
36
34
- $ this ->assertSame (constant ($ testData ['type ' ]), $ tokens [$ number ]['code ' ]);
35
- $ this ->assertSame ($ testData ['type ' ], $ tokens [$ number ]['type ' ]);
36
- $ this ->assertSame ($ testData ['value ' ], $ tokens [$ number ]['content ' ]);
37
+ $ this ->assertSame ($ value , $ tokens [$ number ]['content ' ], 'Content of integer token does not match expectation ' );
38
+
39
+ $ this ->assertSame ($ nextToken , $ tokens [($ number + 1 )]['code ' ], 'Next token is not the expected type, but ' .$ tokens [($ number + 1 )]['type ' ]);
40
+ $ this ->assertSame ($ nextContent , $ tokens [($ number + 1 )]['content ' ], 'Next token did not have the expected contents ' );
37
41
38
42
}//end testExplicitOctalNotation()
39
43
@@ -49,39 +53,58 @@ public function dataExplicitOctalNotation()
49
53
{
50
54
return [
51
55
[
52
- [
53
- 'marker ' => '/* testExplicitOctal */ ' ,
54
- 'type ' => 'T_LNUMBER ' ,
55
- 'value ' => '0o137041 ' ,
56
- ],
56
+ 'marker ' => '/* testExplicitOctal */ ' ,
57
+ 'value ' => '0o137041 ' ,
58
+ 'nextToken ' => T_SEMICOLON ,
59
+ 'nextContent ' => '; ' ,
60
+ ],
61
+ [
62
+ 'marker ' => '/* testExplicitOctalCapitalised */ ' ,
63
+ 'value ' => '0O137041 ' ,
64
+ 'nextToken ' => T_SEMICOLON ,
65
+ 'nextContent ' => '; ' ,
66
+ ],
67
+ [
68
+ 'marker ' => '/* testExplicitOctalWithNumericSeparator */ ' ,
69
+ 'value ' => '0o137_041 ' ,
70
+ 'nextToken ' => T_SEMICOLON ,
71
+ 'nextContent ' => '; ' ,
72
+ ],
73
+ [
74
+ 'marker ' => '/* testInvalid1 */ ' ,
75
+ 'value ' => '0 ' ,
76
+ 'nextToken ' => T_STRING ,
77
+ 'nextContent ' => 'o_137 ' ,
78
+ ],
79
+ [
80
+ 'marker ' => '/* testInvalid2 */ ' ,
81
+ 'value ' => '0 ' ,
82
+ 'nextToken ' => T_STRING ,
83
+ 'nextContent ' => 'O_41 ' ,
57
84
],
58
85
[
59
- [
60
- 'marker ' => '/* testExplicitOctalCapitalised */ ' ,
61
- 'type ' => 'T_LNUMBER ' ,
62
- 'value ' => '0O137041 ' ,
63
- ],
86
+ 'marker ' => '/* testInvalid3 */ ' ,
87
+ 'value ' => '0 ' ,
88
+ 'nextToken ' => T_STRING ,
89
+ 'nextContent ' => 'o91 ' ,
64
90
],
65
91
[
66
- [
67
- 'marker ' => '/* testExplicitOctalWithNumericSeparator */ ' ,
68
- 'type ' => 'T_LNUMBER ' ,
69
- 'value ' => '0o137_041 ' ,
70
- ],
92
+ 'marker ' => '/* testInvalid4 */ ' ,
93
+ 'value ' => '0O2 ' ,
94
+ 'nextToken ' => T_LNUMBER ,
95
+ 'nextContent ' => '82 ' ,
71
96
],
72
97
[
73
- [
74
- 'marker ' => '/* testInvalid1 */ ' ,
75
- 'type ' => 'T_LNUMBER ' ,
76
- 'value ' => '0 ' ,
77
- ],
98
+ 'marker ' => '/* testInvalid5 */ ' ,
99
+ 'value ' => '0o2 ' ,
100
+ 'nextToken ' => T_LNUMBER ,
101
+ 'nextContent ' => '8_2 ' ,
78
102
],
79
103
[
80
- [
81
- 'marker ' => '/* testInvalid2 */ ' ,
82
- 'type ' => 'T_LNUMBER ' ,
83
- 'value ' => '0 ' ,
84
- ],
104
+ 'marker ' => '/* testInvalid6 */ ' ,
105
+ 'value ' => '0o2 ' ,
106
+ 'nextToken ' => T_STRING ,
107
+ 'nextContent ' => '_82 ' ,
85
108
],
86
109
];
87
110
0 commit comments