/** * Test if the parse method returns the `OperandNode` with the correct number. */ public function testParseReturnsNodeWithCorrectNumber() { $number = mt_rand(1, 100); $tokenStream = new TokenStream(); $tokenStream->push(new Token(Lexer::T_NUMBER, $number, 1)); $tokenStream->rewind(); $operand = new NumberOperand(); $node = $operand->parse(new Grammar(), $tokenStream); $this->assertSame($number, $node->evaluate()); }
/** * Test if the `parse` method throws an exception if the closing parentheses is missing * and the end of the stream is reached. * * @expectedException \com\mohiva\common\exceptions\SyntaxErrorException */ public function testParseThrowsExceptionIfEndOfStreamIsReached() { $tokenStream = new TokenStream(); $tokenStream->push(new Token(Lexer::T_OPEN_PARENTHESIS, '(', 1)); $tokenStream->push(new Token(Lexer::T_NUMBER, 100, 1)); $tokenStream->rewind(); $grammar = new Grammar(); $grammar->addOperand(new NumberOperand()); $operand = new ParenthesesOperand(); $operand->parse($grammar, $tokenStream); }
/** * Data provider which returns a TokenStream instance. * * @return array An array containing a TokenStream instance. */ public function tokenStreamProvider() { // user.name.split(" ").join("-") $stream = new TokenStream(); $stream->push(new TestToken(self::T_NAME)); $stream->push(new TestToken(self::T_POINT)); $stream->push(new TestToken(self::T_NAME)); $stream->push(new TestToken(self::T_POINT)); $stream->push(new TestToken(self::T_NAME)); $stream->push(new TestToken(self::T_OPEN_PARENTHESIS)); $stream->push(new TestToken(self::T_VALUE)); $stream->push(new TestToken(self::T_CLOSE_PARENTHESIS)); $stream->push(new TestToken(self::T_POINT)); $stream->push(new TestToken(self::T_NAME)); $stream->push(new TestToken(self::T_OPEN_PARENTHESIS)); $stream->push(new TestToken(self::T_VALUE)); $stream->push(new TestToken(self::T_CLOSE_PARENTHESIS)); $stream->rewind(); return array(array($stream)); }