File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 2222
2323namespace PHPCSUtils \Tests \BackCompat \BCFile ;
2424
25+ use PHP_CodeSniffer \Util \Tokens ;
2526use PHPCSUtils \BackCompat \BCFile ;
2627use PHPCSUtils \TestUtils \UtilityMethodTestCase ;
2728
3536final class FindEndOfStatementTest extends UtilityMethodTestCase
3637{
3738
39+ /**
40+ * Test that end of statement is NEVER before the "current" token.
41+ *
42+ * @return void
43+ */
44+ public function testEndIsNeverLessThanCurrentToken ()
45+ {
46+ $ tokens = self ::$ phpcsFile ->getTokens ();
47+ $ errors = [];
48+
49+ for ($ i = 0 ; $ i < self ::$ phpcsFile ->numTokens ; $ i ++) {
50+ if (isset (Tokens::$ emptyTokens [$ tokens [$ i ]['code ' ]]) === true ) {
51+ continue ;
52+ }
53+
54+ $ end = BCFile::findEndOfStatement (self ::$ phpcsFile , $ i );
55+
56+ // Collect all the errors.
57+ if ($ end < $ i ) {
58+ $ errors [] = sprintf (
59+ 'End of statement for token %1$d (%2$s: %3$s) on line %4$d is %5$d (%6$s), which is less than %1$d ' ,
60+ $ i ,
61+ $ tokens [$ i ]['type ' ],
62+ $ tokens [$ i ]['content ' ],
63+ $ tokens [$ i ]['line ' ],
64+ $ end ,
65+ $ tokens [$ end ]['type ' ]
66+ );
67+ }
68+ }
69+
70+ $ this ->assertSame ([], $ errors );
71+ }
72+
3873 /**
3974 * Test a simple assignment.
4075 *
Original file line number Diff line number Diff line change 1010
1111namespace PHPCSUtils \Tests \BackCompat \BCFile ;
1212
13+ use PHP_CodeSniffer \Util \Tokens ;
1314use PHPCSUtils \BackCompat \BCFile ;
1415use PHPCSUtils \TestUtils \UtilityMethodTestCase ;
1516
2324final class FindStartOfStatementTest extends UtilityMethodTestCase
2425{
2526
27+ /**
28+ * Test that start of statement is NEVER beyond the "current" token.
29+ *
30+ * @return void
31+ */
32+ public function testStartIsNeverMoreThanCurrentToken ()
33+ {
34+ $ tokens = self ::$ phpcsFile ->getTokens ();
35+ $ errors = [];
36+
37+ for ($ i = 0 ; $ i < self ::$ phpcsFile ->numTokens ; $ i ++) {
38+ if (isset (Tokens::$ emptyTokens [$ tokens [$ i ]['code ' ]]) === true ) {
39+ continue ;
40+ }
41+
42+ $ start = BCFile::findStartOfStatement (self ::$ phpcsFile , $ i );
43+
44+ // Collect all the errors.
45+ if ($ start > $ i ) {
46+ $ errors [] = sprintf (
47+ 'Start of statement for token %1$d (%2$s: %3$s) on line %4$d is %5$d (%6$s), which is more than %1$d ' ,
48+ $ i ,
49+ $ tokens [$ i ]['type ' ],
50+ $ tokens [$ i ]['content ' ],
51+ $ tokens [$ i ]['line ' ],
52+ $ start ,
53+ $ tokens [$ start ]['type ' ]
54+ );
55+ }
56+ }
57+
58+ $ this ->assertSame ([], $ errors );
59+ }
60+
2661 /**
2762 * Test a simple assignment.
2863 *
You can’t perform that action at this time.
0 commit comments