Skip to content

Commit

Permalink
lexer bug if exclam mark on unclosed symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel committed Jul 30, 2015
1 parent 5139b6a commit d8fbbb3
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/figdice/classes/lexer/DFAStateSymbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function input(Lexer $lexer, $char) {
$lexer->pushOperator(new TokenMul());
}
else if($char == '!') {
if (! $this->closed) {
$lexer->pushOperand(new TokenSymbol($this->buffer));
}
$lexer->setStateComparison($char);
}
else if(self::isBlank($char)) {
Expand Down
75 changes: 75 additions & 0 deletions test/UniverseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* @author Gabriel Zerbib <gabriel@figdice.org>
* @copyright 2004-2015, Gabriel Zerbib.
* @version 2.1.1
* @package FigDice
*
* This file is part of FigDice.
*
* FigDice is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* FigDice is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FigDice. If not, see <http://www.gnu.org/licenses/>.
*/

use figdice\View;

/**
* Unit Test Class for basic View loading
*/
class UniverseTest extends PHPUnit_Framework_TestCase {

private function symbolize($expr, $universe)
{
$view = new View();
$view->loadString('<fig:text fig:text="' . $expr . '"/>');
foreach ($universe as $key => $value) {
$view->mount($key, $value);
}
return $view->render();
}

/**
* This test must be done with a real View object, instead of a Mock,
* because it activates the bubbling Universe resolution.
* TODO: At some point we will need to factor out the Universe resolution,
* and make it less adhering to the View code.
*/
public function testRelativeOneLevelSymbol()
{
$this->assertEquals(47, $this->symbolize('dummy', ['dummy' => 47]));
}

public function testRelativeTwoLevelSymbol()
{
$this->assertEquals(48, $this->symbolize('dummy/test', ['dummy' => ['test' => 48]]));
}

public function testAbsoluteOneLevelSymbol()
{
$this->assertEquals(47, $this->symbolize('/dummy', ['dummy' => 47]));
}

public function testAbsoluteTwoLevelSymbol()
{
$this->assertEquals(48, $this->symbolize('/dummy/test', ['dummy' => ['test' => 48]]));
}

public function testExclamMarkNextToSymbol()
{
$this->assertFalse($this->symbolize('dummy!=47', ['dummy' => 47]));
}
public function testExclamMarkAfterSymbol()
{
$this->assertFalse($this->symbolize('dummy !=47', ['dummy' => 47]));
}
}

0 comments on commit d8fbbb3

Please sign in to comment.