Example #1
0
 public function testSimple()
 {
     $buffer = new Buffer("  abc\n    def\nghi");
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("  abc", $buffer->getLine());
     $this->assertTrue($buffer->match('~z*~A', $match));
     $this->assertSame(array('', 'pos' => array(array('lineno' => 1, 'column' => 0))), $match);
     $this->assertSame("  abc", $buffer->getLine());
     $this->assertTrue($buffer->match('~(\\s*)(a)~A', $match));
     $this->assertSame(array('  a', '  ', 'a', 'pos' => array(array('lineno' => 1, 'column' => 0), array('lineno' => 1, 'column' => 0), array('lineno' => 1, 'column' => 2))), $match);
     $this->assertSame("bc", $buffer->getLine());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("    def", $buffer->getLine());
     $this->assertSame(2, $buffer->getLineno());
     $this->assertSame(' ', $buffer->peekChar());
     $this->assertSame("    def", $buffer->getLine());
     $this->assertSame(1, $buffer->getColumn());
     $this->assertSame(' ', $buffer->eatChar());
     $this->assertSame("   def", $buffer->getLine());
     $this->assertSame(2, $buffer->getColumn());
     $buffer->skipWs();
     $this->assertSame('def', $buffer->getLine());
     $this->assertSame(5, $buffer->getColumn());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame('ghi', $buffer->getLine());
     $this->assertSame(3, $buffer->getLineno());
     $this->assertFalse($buffer->nextLine());
 }
Example #2
0
 public function testInjectLines()
 {
     $buffer = new Buffer("    abc\n    def\nghi");
     $buffer->injectLines(["  jkl", "  mop"], 1);
     $this->assertTrue($buffer->nextLine());
     //this skip magic comment
     $this->assertSame("  jkl", $buffer->getLine());
     $this->assertSame(1, $buffer->getLineno());
     $this->assertSame(1, $buffer->getColumn());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("  mop", $buffer->getLine());
     $this->assertSame(2, $buffer->getLineno());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("    abc", $buffer->getLine());
     $this->assertSame(3, $buffer->getLineno());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("    def", $buffer->getLine());
     $this->assertSame(4, $buffer->getLineno());
     $this->assertTrue($buffer->nextLine());
     $this->assertSame("ghi", $buffer->getLine());
     $this->assertSame(5, $buffer->getLineno());
     $this->assertFalse($buffer->nextLine());
 }
Example #3
0
 protected function syntaxError(Buffer $buf, $msg)
 {
     $this->column = $buf->getColumn();
     $this->lineno = $buf->getLineno();
     $msg = sprintf('%s in %s on line %d, column %d', $msg, $this->filename, $this->lineno, $this->column);
     return new SyntaxErrorException($msg);
 }