Beispiel #1
0
 /**
  * @covers ::parse
  */
 public function testParseBooleanAnd()
 {
     $node = new AstBooleanAnd(new AstVariable('a'), new AstVariable('b'));
     $this->state->parser->shouldReceive('parseNode')->andReturn($x = new JitVariable(), $y = new JitVariable());
     $var = $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(JitVariable::class, $var);
     $graph = ['NoOp Assign', 'Assign JumpZ', 'JumpZ NoOp', 'JumpZ Assign', 'Assign Jump', 'Jump NoOp'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #2
0
 /**
  * @covers ::parse
  */
 public function testParseWithLabel()
 {
     $node = new AstGoto('foo');
     $noOp = new NoOp();
     $this->state->labels['foo'] = $noOp;
     $this->parser->parse($node, $this->state);
     $graph = ["NoOp Jump", "Jump NoOp"];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #3
0
 /**
  * @covers ::parse
  */
 public function testParseTernaryWithoutIf()
 {
     $node = new AstTernary(new AstVariable('a'), null, new AstVariable('c'));
     $this->state->parser->shouldReceive('parseNode')->andReturn(new JitVariable(), new JitVariable());
     $var = $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(JitVariable::class, $var);
     $graph = ['NoOp JumpZ', 'JumpZ NoOp', 'JumpZ Assign', 'NoOp Assign', 'Assign Jump', 'Jump NoOp', 'Assign NoOp'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #4
0
 /**
  * @covers ::parse
  */
 public function testParsePreInc()
 {
     $node = new AstPreInc($var = new AstVariable('a'));
     $this->state->parser->shouldReceive('parseNode')->andReturn($b = new JitVariable());
     $var = $this->parser->parse($node, $this->state);
     $this->assertSame($b, $var);
     $this->assertInstanceOf(JitBinaryOp::class, $this->state->last);
     $graph = ['NoOp BinaryOp'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #5
0
 /**
  * @covers ::parse
  */
 public function testParseIfWithElse()
 {
     $node = new AstIf($a = new AstVariable('a'), ['stmts' => [$b = new AstVariable('b')], 'else' => new AstElse([$c = new AstVariable('c')])]);
     $this->state->parser->shouldReceive('parseNode')->andReturn($jitA = new JitVariable());
     $this->state->parser->shouldReceive('parseStmtList');
     $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(NoOp::class, $this->state->last);
     $graph = ['NoOp JumpZ', 'JumpZ NoOp', 'JumpZ Jump', 'NoOp Jump', 'Jump NoOp', 'Jump NoOp'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #6
0
 /**
  * @covers ::parse
  */
 public function testParseReturn()
 {
     $node = new AstReturn($expr = new AstVariable('a'));
     $this->state->parser->shouldReceive('parseNode')->andReturn($b = new JitVariable());
     $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(JitReturn::class, $this->state->last);
     $this->assertSame($b, $this->state->last->getValue());
     $graph = ['NoOp Return'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #7
0
 /**
  * @covers ::parse
  */
 public function testParse()
 {
     $node = new Plus($a = new AstVariable('a'), $b = new AstVariable('b'));
     $this->state->parser->shouldReceive('parseNode')->andReturn(new JitVariable(), new JitVariable());
     $var = $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(JitVariable::class, $var);
     $this->assertInstanceOf(JitBinaryOp::class, $this->state->last);
     $graph = ["NoOp BinaryOp"];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }
Beispiel #8
0
 /**
  * @covers ::parse
  */
 public function testParseWithGotoQueue()
 {
     $node = new AstLabel('foo');
     $this->state->gotolist['foo'] = [$j = new Jump()];
     $this->parser->parse($node, $this->state);
     $this->assertInstanceOf(NoOp::class, $this->state->last);
     $graph = ['NoOp NoOp', 'Jump NoOp'];
     $this->assertEquals($graph, Dumper::dump($this->state->graph));
 }