GeezerVison is showing github.com — Fix TokensList::getPrevious which was not able to reach very first token · phpmyadmin/sql-parser@aa8a915
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/TokensList.php +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,7 +119,7 @@ public function getNext() |
119 | 119 | */ |
120 | 120 | public function getPrevious(): ?Token |
121 | 121 | { |
122 | | - for (; $this->idx > 0; --$this->idx) { |
| 122 | + for (; $this->idx >= 0; --$this->idx) { |
123 | 123 | if ( |
124 | 124 | ($this->tokens[$this->idx]->type !== Token::TYPE_WHITESPACE) |
125 | 125 | && ($this->tokens[$this->idx]->type !== Token::TYPE_COMMENT) |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/Lexer/TokensListTest.php +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,6 +79,7 @@ public function testGetPrevious(): void |
79 | 79 | $this->assertEquals($this->tokens[6], $list->getPrevious()); |
80 | 80 | $this->assertEquals($this->tokens[4], $list->getPrevious()); |
81 | 81 | $this->assertEquals($this->tokens[2], $list->getPrevious()); |
| 82 | + $this->assertEquals($this->tokens[0], $list->getPrevious()); |
82 | 83 | $this->assertNull($list->getPrevious()); |
83 | 84 | } |
84 | 85 |
|
|