Ejemplo n.º 1
0
 public function testEatChars()
 {
     $buffer = new Buffer("abcdef");
     $buffer->nextLine();
     $chars = $buffer->eatChars(2);
     $this->assertSame("ab", $chars);
     $this->assertSame("cdef", $buffer->getLine());
     $this->assertSame(3, $buffer->getColumn());
     $chars = $buffer->eatChars(5);
     $this->assertSame("cdef", $chars);
     $this->assertSame("", $buffer->getLine());
     $this->assertSame(7, $buffer->getColumn());
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 3
0
 /**
  * Handles HAML multiline syntax
  *
  * Any line terminated by ` |` is concatenated with the following lines
  * also terminated by ` |`. Empty or whitespace-only lines are ignored. The
  * current line is replaced by the resulting line in $buf.
  *
  * @param Buffer $buf
  */
 public function handleMultiline($buf)
 {
     $line = $buf->getLine();
     if (!$this->isMultiline($line)) {
         return;
     }
     $line = substr(rtrim($line), 0, -1);
     while ($next = $buf->peekLine()) {
         if (trim($next) == '') {
             $buf->nextLine();
             continue;
         }
         if (!$this->isMultiline($next)) {
             break;
         }
         $line .= substr(trim($next), 0, -1);
         $buf->nextLine();
     }
     $buf->replaceLine($line);
 }
Ejemplo n.º 4
0
 protected function getMultilineCode(Buffer $buf)
 {
     $code = $buf->getLine();
     while (preg_match('/,\\s*$/', $code)) {
         $buf->nextLine();
         $line = trim($buf->getLine());
         if ('' !== $line) {
             $code .= ' ' . $line;
         }
     }
     return $code;
 }