Space should end open numbers (#113)
This commit is contained in:
parent
d1b060749e
commit
cbada2b920
2 changed files with 39 additions and 8 deletions
|
@ -124,6 +124,8 @@ class Tokenizer
|
|||
continue 2;
|
||||
|
||||
case ' ' == $ch || "\n" == $ch || "\r" == $ch || "\t" == $ch:
|
||||
$this->emptyNumberBufferAsLiteral();
|
||||
$this->emptyStrBufferAsVariable();
|
||||
$this->tokens[] = new Token(Token::Space, '');
|
||||
|
||||
continue 2;
|
||||
|
|
|
@ -26,7 +26,7 @@ class MathTest extends TestCase
|
|||
/**
|
||||
* @dataProvider providerExpressions
|
||||
*/
|
||||
public function testCalculating($expression) : void
|
||||
public function testCalculating(string $expression) : void
|
||||
{
|
||||
$calculator = new MathExecutor();
|
||||
|
||||
|
@ -250,6 +250,42 @@ class MathTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider incorrectExpressions
|
||||
*/
|
||||
public function testIncorrectExpressionException(string $expression) : void
|
||||
{
|
||||
$calculator = new MathExecutor();
|
||||
$calculator->setVars(['a' => 12, 'b' => 24]);
|
||||
$this->expectException(IncorrectExpressionException::class);
|
||||
$calculator->execute($expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Incorrect Expressions data provider
|
||||
*
|
||||
* These expressions should not pass validation
|
||||
*/
|
||||
public function incorrectExpressions()
|
||||
{
|
||||
return [
|
||||
['1 * + '],
|
||||
[' 2 3'],
|
||||
['2 3 '],
|
||||
[' 2 4 3 '],
|
||||
['$a $b'],
|
||||
['$a [3, 4, 5]'],
|
||||
['$a (3 + 4)'],
|
||||
['$a "string"'],
|
||||
['5 "string"'],
|
||||
['"string" $a'],
|
||||
['$a round(12.345)'],
|
||||
['round(12.345) $a'],
|
||||
['4 round(12.345)'],
|
||||
['round(12.345) 4'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testUnknownFunctionException() : void
|
||||
{
|
||||
$calculator = new MathExecutor();
|
||||
|
@ -257,13 +293,6 @@ class MathTest extends TestCase
|
|||
$calculator->execute('1 * fred("wilma") + 3');
|
||||
}
|
||||
|
||||
public function testIncorrectExpressionException() : void
|
||||
{
|
||||
$calculator = new MathExecutor();
|
||||
$this->expectException(IncorrectExpressionException::class);
|
||||
$calculator->execute('1 * + ');
|
||||
}
|
||||
|
||||
public function testZeroDivision() : void
|
||||
{
|
||||
$calculator = new MathExecutor();
|
||||
|
|
Loading…
Reference in a new issue