Commit 19287dec by Seldaek

+ Allowed string concatenation assignments with {$foo.="bar"}

git-svn-id: svn://dwoo.org/dwoo/trunk@243 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent b7950d49
......@@ -2,6 +2,7 @@
+ Added {template} plugin that allows you to define sub-templates and then
call them (even recursively)
+ Added {load_templates} to load external sub-templates into your file
+ Allowed string concatenation assignments with {$foo.="bar"}
* Many new unit tests to improve code coverage and a bunch of bug fixes
that resulted, but I didn't really keep track of them
* Fixed a bug with parsing AND/OR keywords in conditionals when they were
......
......@@ -1392,7 +1392,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$out .= $match[1] . $expr;
}
}
} else if ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) {
} else if ($curBlock === 'root' && preg_match('#^(\s*(?:[+/*%-.]=|=|\+\+|--)\s*)(.*)#s', $substr, $match)) {
if($this->debug) echo 'PARSING POST-VAR ASSIGNMENT '.$substr.'<br />';
// parse assignment
$value = $match[2];
......@@ -1968,6 +1968,11 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$hasExpression = !empty($match[4]);
$hasMethodCall = !empty($match[3]);
if (substr($key, -1) == ".") {
$key = substr($key, 0, -1);
$matchedLength--;
}
if ($hasMethodCall) {
$matchedLength -= strlen($match[3]) + strlen(substr($match[1], strrpos($match[1], '->')));
$key = substr($match[1], 1, strrpos($match[1], '->')-1);
......
......@@ -394,6 +394,19 @@ replace="BAR"
$this->assertEquals("moo8", $this->dwoo->get($tpl, array('foo'=>0), $this->compiler));
}
public function testAssignAndConcatenate()
{
$tpl = new Dwoo_Template_String('{$foo="test"}{$foo.="test"}{$foo}');
$tpl->forceCompilation();
$this->assertEquals("testtest", $this->dwoo->get($tpl, array('foo'=>0), $this->compiler));
$tpl = new Dwoo_Template_String('{$foo.="baz"}{$foo|upper}');
$tpl->forceCompilation();
$this->assertEquals("BARBAZ", $this->dwoo->get($tpl, array('foo'=>'bar'), $this->compiler));
}
public function testSetStringValToTrueWhenUsingNamedParams()
{
$this->dwoo->addPlugin('test', create_function('Dwoo $dwoo, $name, $bool=false', 'return $bool ? $name."!" : $name."?";'));
......
......@@ -3,6 +3,7 @@
error_reporting(E_ALL|E_STRICT);
if (!ini_get('date.timezone'))
date_default_timezone_set('CET');
define('DWOO_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'cache');
define('DWOO_COMPILE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'compiled');
......@@ -34,7 +35,7 @@ class DwooTests extends PHPUnit_Framework_TestSuite {
$suite = new self('Dwoo - Unit Tests Report');
foreach (new DirectoryIterator(dirname(__FILE__)) as $file) {
if (!$file->isDot() && !$file->isDir() && (string) $file !== 'DwooTests.php' && substr((string) $file, -4) === '.php') {
if (!$file->isDir() && substr((string) $file, -4) == '.php' && (string) $file !== 'DwooTests.php' && (string) $file !== 'run-tests.php' && substr((string) $file, -4) === '.php') {
require_once $file->getPathname();
$class = basename($file, '.php');
// to have an optional test suite, it should implement a public static function isRunnable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment