Fix: comments parsing

This commit is contained in:
bzick 2013-05-30 22:41:58 +04:00
parent dad1a0ba73
commit 15744665a5
3 changed files with 33 additions and 4 deletions

View File

@ -141,12 +141,14 @@ class Template extends Render {
$pos = $start + 1; // try find tags after the current char
continue 2;
case "*": // if comment block
$end = strpos($this->_src, '*}', $start); // finding end of the comment block
$end = strpos($this->_src, '*}', $start) + 1; // finding end of the comment block
if($end === false) {
throw new CompileException("Unclosed comment block in line {$this->_line}", 0, 1, $this->_name, $this->_line);
}
$_frag = substr($this->_src, $this->_pos, $start - $end); // read the comment block for precessing
$this->_line += substr_count($_frag, "\n"); // count skipped lines in comment block
$this->_appendText(substr($this->_src, $pos, $start - $pos));
$comment = substr($this->_src, $start, $end - $start); // read the comment block for processing
$this->_line += substr_count($comment, "\n"); // count skipped lines in comment block
unset($comment);
$pos = $end + 1; // seek pointer
continue 2;
}

View File

@ -25,7 +25,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
}
$this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
$this->cytro->addModifier('dots', __CLASS__.'::dots');
$this->cytro->addModifier('dots', __CLASS__.'::concat');
$this->cytro->addModifier('concat', __CLASS__.'::concat');
}
public static function dots($value) {

View File

@ -0,0 +1,27 @@
<?php
namespace Cytro;
class CommentTest extends TestCase {
/**
* @dataProvider providerScalars
*/
public function testInline($tpl_val) {
$this->assertRender("before {* $tpl_val *} after", "before after");
$this->assertRender("before {* {{$tpl_val}} {{$tpl_val}} *} after", "before after");
$this->assertRender("before {*{{$tpl_val}}*} after", "before after");
}
/**
* @dataProvider providerScalars
*/
public function testMultiLine($tpl_val) {
$this->assertRender(
"before-1\nbefore-2 {* before-3\nbefore-4 $tpl_val after-1\nafter-2 *} after-3\nafter-4{* dummy *}\nafter-5",
"before-1\nbefore-2 after-3\nafter-4\nafter-5"
);
}
}