break down regex to digestable chunks, fix multiple param problem with method calls,

add object method testing to unit_test cases
This commit is contained in:
mohrt
2004-09-09 22:01:33 +00:00
parent f36648c39c
commit 614e9c89e2
2 changed files with 33 additions and 5 deletions

View File

@@ -151,14 +151,16 @@ class Smarty_Compiler extends Smarty {
// $foo->bar($foo->bar())
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
$this->_obj_params_regexp = '\((?:\w+|(?:'
$this->_obj_restricted_param_regexp = '(?:'
. $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?))))*)?\)';
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)';
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?)';
// matches valid modifier syntax:
// |foo
// |@foo

View File

@@ -3,6 +3,16 @@
require_once './config.php';
require_once SMARTY_DIR . 'Smarty.class.php';
require_once 'PHPUnit.php';
class Obj {
var $val = 'val';
var $arr = array('one' => 'one');
function meth($a="a", $b="b") {
return "$a:$b";
}
}
class SmartyTest extends PHPUnit_TestCase {
// contains the object handle of the string class
@@ -230,6 +240,22 @@ class SmartyTest extends PHPUnit_TestCase {
$this->smarty->assign('foo', 'bar');
$this->assertEquals($this->smarty->fetch('assign_var.tpl'), 'bar');
}
// test assigning and calling an object
function test_obj_meth() {
$obj = new Obj();
$this->smarty->assign('obj', $obj);
$this->smarty->assign('foo', 'foo');
$this->assertEquals(
'foo:2.5
2.5:foo
2.5:b
val:foo
foo:val
foo:foo
one:2
foo:foo:b', $this->smarty->fetch('assign_obj.tpl'));
}
/* CONFIG FILE TESTS */