Пример #1
0
 /**
  * Test the `addOperator` and `getOperatorTable` accessors.
  */
 public function testOperatorTableAccessors()
 {
     $operator = new BinaryOperator(1, 1, BinaryOperator::LEFT, function () {
     });
     $token = new Token($operator->getCode(), 1, 1);
     $grammar = new Grammar();
     $grammar->addOperator($operator);
     $this->assertSame($operator, $grammar->getOperatorTable()->getBinaryOperator($token));
 }
Пример #2
0
 /**
  * Test all getters for the values set with the constructor.
  */
 public function testConstructorAccessors()
 {
     $code = mt_rand(1, 100);
     $precedence = mt_rand(1, 100);
     $closure = function () {
     };
     $operator = new BinaryOperator($code, $precedence, BinaryOperator::LEFT, $closure);
     $this->assertSame($code, $operator->getCode());
     $this->assertSame($precedence, $operator->getPrecedence());
     $this->assertSame($closure, $operator->getNode());
 }
Пример #3
0
 /**
  * Test if the `isTernary` method returns false if the given token is not the `if` or an `else` token
  * of a ternary operator.
  */
 public function testIsTernaryReturnsFalse()
 {
     $operator = new BinaryOperator(1, 10, BinaryOperator::LEFT, function () {
     });
     $token = new Token($operator->getCode(), '+', 1);
     $table = new OperatorTable();
     $table->addOperator($operator);
     $this->assertFalse($table->isTernary($token));
 }