diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/zordius/lightncandy/tests | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/zordius/lightncandy/tests')
-rw-r--r-- | vendor/zordius/lightncandy/tests/LCRun3Test.php | 18 | ||||
-rw-r--r-- | vendor/zordius/lightncandy/tests/LightnCandyTest.php | 159 | ||||
-rw-r--r-- | vendor/zordius/lightncandy/tests/contextTest.php | 300 | ||||
-rw-r--r-- | vendor/zordius/lightncandy/tests/errorTest.php | 23 | ||||
-rw-r--r-- | vendor/zordius/lightncandy/tests/helpers_for_test.php | 12 | ||||
-rw-r--r-- | vendor/zordius/lightncandy/tests/regressionTest.php | 609 |
6 files changed, 1057 insertions, 64 deletions
diff --git a/vendor/zordius/lightncandy/tests/LCRun3Test.php b/vendor/zordius/lightncandy/tests/LCRun3Test.php index 63d6348e..03595298 100644 --- a/vendor/zordius/lightncandy/tests/LCRun3Test.php +++ b/vendor/zordius/lightncandy/tests/LCRun3Test.php @@ -12,10 +12,10 @@ class LCRun3Test extends PHPUnit_Framework_TestCase public function testOn_debug() { $method = new ReflectionMethod('LCRun3', 'debug'); $this->assertEquals('{{123}}', $method->invoke(null, - '123', 'miss', array('flags' => array('debug' => LCRun3::DEBUG_TAGS)), '' + '123', 'miss', array('flags' => array('debug' => LCRun3::DEBUG_TAGS), 'lcrun' => 'LCRun3'), '' )); $this->assertEquals('<!--MISSED((-->{{#123}}<!--))--><!--SKIPPED--><!--MISSED((-->{{/123}}<!--))-->', $method->invoke(null, - '123', 'wi', array('flags' => array('debug' => LCRun3::DEBUG_TAGS_HTML)), false, false, function () {return 'A';} + '123', 'wi', array('flags' => array('debug' => LCRun3::DEBUG_TAGS_HTML), 'lcrun' => 'LCRun3'), false, false, function () {return 'A';} )); } /** @@ -237,7 +237,7 @@ class LCRun3Test extends PHPUnit_Framework_TestCase array('flags' => array('spvar' => 0)), 'abc', 'abc', true, function ($c, $i) {return "-$i=";} )); $this->assertEquals('-b=', $method->invoke(null, - array('flags' => array('spvar' => 0, 'mustsec' => 0)), array('a' => 'b'), array('a' => 'b'), true, function ($c, $i) {return "-$i=";} + array('flags' => array('spvar' => 0)), array('a' => 'b'), array('a' => 'b'), true, function ($c, $i) {return "-$i=";} )); $this->assertEquals('1', $method->invoke(null, array('flags' => array('spvar' => 0)), 'b', 'b', false, function ($c, $i) {return count($i);} @@ -249,7 +249,7 @@ class LCRun3Test extends PHPUnit_Framework_TestCase array('flags' => array('spvar' => 0)), 0, 0, false, function ($c, $i) {return print_r($i, true);} )); $this->assertEquals('{"b":"c"}', $method->invoke(null, - array('flags' => array('spvar' => 0, 'mustsec' => 0)), array('b' => 'c'), array('b' => 'c'), false, function ($c, $i) {return json_encode($i);} + array('flags' => array('spvar' => 0)), array('b' => 'c'), array('b' => 'c'), false, function ($c, $i) {return json_encode($i);} )); $this->assertEquals('inv', $method->invoke(null, array('flags' => array('spvar' => 0)), array(), 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';} @@ -282,10 +282,10 @@ class LCRun3Test extends PHPUnit_Framework_TestCase array('flags' => array('spvar' => 0)), new stdClass, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';} )); $this->assertEquals('268', $method->invoke(null, - array('flags' => array('spvar' => 1)), array(1,3,4), 0, false, function ($c, $i) {return $i * 2;} + array('flags' => array('spvar' => 1), 'sp_vars'=>array('root' => 0)), array(1,3,4), 0, false, function ($c, $i) {return $i * 2;} )); $this->assertEquals('038', $method->invoke(null, - array('flags' => array('spvar' => 1), 'sp_vars'=>array()), array(1,3,'a'=>4), 0, true, function ($c, $i) {return $i * $c['sp_vars']['index'];} + array('flags' => array('spvar' => 1), 'sp_vars'=>array('root' => 0)), array(1,3,'a'=>4), 0, true, function ($c, $i) {return $i * $c['sp_vars']['index'];} )); } /** @@ -299,11 +299,11 @@ class LCRun3Test extends PHPUnit_Framework_TestCase $this->assertEquals('', $method->invoke(null, array(), null, null, function () {return 'A';} )); - $this->assertEquals('-Array=', $method->invoke(null, - array(), array('a'=>'b'), array('a' => 'b'), function ($c, $i) {return "-$i=";} + $this->assertEquals('{"a":"b"}', $method->invoke(null, + array(), array('a'=>'b'), array('a'=>'c'), function ($c, $i) {return json_encode($i);} )); $this->assertEquals('-b=', $method->invoke(null, - array(), 'b', array('a' => 'b'), function ($c, $i) {return "-$i=";} + array(), 'b', array('a'=>'b'), function ($c, $i) {return "-$i=";} )); } /** diff --git a/vendor/zordius/lightncandy/tests/LightnCandyTest.php b/vendor/zordius/lightncandy/tests/LightnCandyTest.php index 6f82f2bd..9c82aac3 100644 --- a/vendor/zordius/lightncandy/tests/LightnCandyTest.php +++ b/vendor/zordius/lightncandy/tests/LightnCandyTest.php @@ -7,6 +7,22 @@ require_once('src/lightncandy.php'); class LightnCandyTest extends PHPUnit_Framework_TestCase { /** + * @covers LightnCandy::escapeTemplate + */ + public function testOn_escapeTemplate() { + $method = new ReflectionMethod('LightnCandy', 'escapeTemplate'); + $method->setAccessible(true); + $this->assertEquals('abc', $method->invoke(null, + 'abc' + )); + $this->assertEquals('a\\\\bc', $method->invoke(null, + 'a\bc' + )); + $this->assertEquals('a\\\'bc', $method->invoke(null, + 'a\'bc' + )); + } + /** * @covers LightnCandy::buildHelperTable */ public function testOn_buildHelperTable() { @@ -124,16 +140,16 @@ class LightnCandyTest extends PHPUnit_Framework_TestCase $method = new ReflectionMethod('LightnCandy', 'getFuncName'); $method->setAccessible(true); $this->assertEquals('LCRun3::test(', $method->invoke(null, - array('flags' => array('standalone' => 0, 'debug' => 0)), 'test', '' + array('flags' => array('standalone' => 0, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test', '' )); $this->assertEquals('LCRun3::test2(', $method->invoke(null, - array('flags' => array('standalone' => 0, 'debug' => 0)), 'test2', '' + array('flags' => array('standalone' => 0, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test2', '' )); $this->assertEquals("\$cx['funcs']['test3'](", $method->invoke(null, - array('flags' => array('standalone' => 1, 'debug' => 0)), 'test3', '' + array('flags' => array('standalone' => 1, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test3', '' )); $this->assertEquals('LCRun3::debug(\'abc\', \'test\', ', $method->invoke(null, - array('flags' => array('standalone' => 0, 'debug' => 1)), 'test', 'abc' + array('flags' => array('standalone' => 0, 'debug' => 1), 'lcrun' => 'LCRun3'), 'test', 'abc' )); } /** @@ -193,32 +209,44 @@ class LightnCandyTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('$in', 'this'), $method->invoke(null, array(null), array('flags'=>array('spvar'=>true,'debug'=>0)) )); + $this->assertEquals(array('((isset($in[\'true\']) && is_array($in)) ? $in[\'true\'] : null)', '[true]'), $method->invoke(null, + array('true'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) + )); + $this->assertEquals(array('((isset($in[\'false\']) && is_array($in)) ? $in[\'false\'] : null)', '[false]'), $method->invoke(null, + array('false'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) + )); $this->assertEquals(array('true', 'true'), $method->invoke(null, - array('true'), array('flags'=>array('spvar'=>true,'debug'=>0)), true + array(0, 'true'), array('flags'=>array('spvar'=>true,'debug'=>0)) )); $this->assertEquals(array('false', 'false'), $method->invoke(null, - array('false'), array('flags'=>array('spvar'=>true,'debug'=>0)), true + array(0, 'false'), array('flags'=>array('spvar'=>true,'debug'=>0)) )); - $this->assertEquals(array(2, '2'), $method->invoke(null, - array('2'), array('flags'=>array('spvar'=>true,'debug'=>0)), true + $this->assertEquals(array('((isset($in[\'2\']) && is_array($in)) ? $in[\'2\'] : null)', '[2]'), $method->invoke(null, + array('2'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) + )); + $this->assertEquals(array('2', '2'), $method->invoke(null, + array(0, '2'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0)) )); $this->assertEquals(array('((isset($in[\'@index\']) && is_array($in)) ? $in[\'@index\'] : null)', '[@index]'), $method->invoke(null, array('@index'), array('flags'=>array('spvar'=>false,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); $this->assertEquals(array("((isset(\$cx['sp_vars']['index']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['index'] : null)", '@[index]'), $method->invoke(null, - array('@index'), array('flags'=>array('spvar'=>true,'debug'=>0)) + array('@index'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); $this->assertEquals(array("((isset(\$cx['sp_vars']['key']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['key'] : null)", '@[key]'), $method->invoke(null, - array('@key'), array('flags'=>array('spvar'=>true,'debug'=>0)) + array('@key'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); $this->assertEquals(array("((isset(\$cx['sp_vars']['first']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['first'] : null)", '@[first]'), $method->invoke(null, - array('@first'), array('flags'=>array('spvar'=>true,'debug'=>0)) + array('@first'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); $this->assertEquals(array("((isset(\$cx['sp_vars']['last']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['last'] : null)", '@[last]'), $method->invoke(null, - array('@last'), array('flags'=>array('spvar'=>true,'debug'=>0)) + array('@last'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) + )); + $this->assertEquals(array('((isset($in[\'"a"\']) && is_array($in)) ? $in[\'"a"\'] : null)', '["a"]'), $method->invoke(null, + array('"a"'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); - $this->assertEquals(array('\'a\'', '"a"'), $method->invoke(null, - array('"a"'), array('flags'=>array('spvar'=>true,'debug'=>0)) + $this->assertEquals(array('"a"', '"a"'), $method->invoke(null, + array(0, '"a"'), array('flags'=>array('spvar'=>true,'debug'=>0)) )); $this->assertEquals(array('((isset($in[\'a\']) && is_array($in)) ? $in[\'a\'] : null)', '[a]'), $method->invoke(null, array('a'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) @@ -233,7 +261,7 @@ class LightnCandyTest extends PHPUnit_Framework_TestCase array(null, 'id'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) )); $this->assertEquals(array('LCRun3::v($cx, $in, array(\'id\'))', 'this.[id]'), $method->invoke(null, - array(null, 'id'), array('flags'=>array('prop'=>true,'spvar'=>true,'debug'=>0,'method'=>0,'mustlok'=>0,'standalone'=>0)) + array(null, 'id'), array('flags'=>array('prop'=>true,'spvar'=>true,'debug'=>0,'method'=>0,'mustlok'=>0,'standalone'=>0), 'lcrun' => 'LCRun3') )); } /** @@ -273,35 +301,41 @@ class LightnCandyTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('this'), $method->invoke(null, 'this', array('flags' => array('advar' => 0, 'this' => 0)) )); - $this->assertEquals(array(null), $method->invoke(null, + $this->assertEquals(array(), $method->invoke(null, 'this', array('flags' => array('advar' => 0, 'this' => 1)) )); - $this->assertEquals(array(1, null), $method->invoke(null, - '../', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + $this->assertEquals(array(1), $method->invoke(null, + '../', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); - $this->assertEquals(array(1, null), $method->invoke(null, - '../.', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + $this->assertEquals(array(1), $method->invoke(null, + '../.', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); - $this->assertEquals(array(1, null), $method->invoke(null, - '../this', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + $this->assertEquals(array(1), $method->invoke(null, + '../this', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); $this->assertEquals(array(1, 'a'), $method->invoke(null, - '../a', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + '../a', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); $this->assertEquals(array(2, 'a', 'b'), $method->invoke(null, - '../../a.b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + '../../a.b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); $this->assertEquals(array(2, '[a]', 'b'), $method->invoke(null, - '../../[a].b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + '../../[a].b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); $this->assertEquals(array(2, 'a', 'b'), $method->invoke(null, - '../../[a].b', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + '../../[a].b', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) )); - $this->assertEquals(array('"a.b"'), $method->invoke(null, + $this->assertEquals(array('id'), $method->invoke(null, + 'this.id', array('flags' => array('advar' => 1, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + )); + $this->assertEquals(array(0, '\'a.b\''), $method->invoke(null, '"a.b"', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) )); - $this->assertEquals(array(null, 'id'), $method->invoke(null, - 'this.id', array('flags' => array('advar' => 1, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + $this->assertEquals(array(0, '123'), $method->invoke(null, + '123', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) + )); + $this->assertEquals(array(0, 'null'), $method->invoke(null, + 'null', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) )); } /** @@ -310,59 +344,80 @@ class LightnCandyTest extends PHPUnit_Framework_TestCase public function testOn_parseTokenArgs() { $method = new ReflectionMethod('LightnCandy', 'parseTokenArgs'); $method->setAccessible(true); - $this->assertEquals(array(false, array(array(null))), $method->invoke(null, - array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + $this->assertEquals(array(false, array(array())), $method->invoke(null, + array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); - $this->assertEquals(array(true, array(array(null))), $method->invoke(null, - array(0,0,0,'{{{',0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + $this->assertEquals(array(true, array(array())), $method->invoke(null, + array(0,0,0,'{{{',0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); - $this->assertEquals(array(true, array(array(null))), $method->invoke(null, - array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 1)) + $this->assertEquals(array(true, array(array())), $method->invoke(null, + array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 1), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'))), $method->invoke(null, - array(0,0,0,0,0,0,'a'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + array(0,0,0,0,0,0,'a'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('b'))), $method->invoke(null, - array(0,0,0,0,0,0,'a b'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + array(0,0,0,0,0,0,'a b'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('"b'), array('c"'))), $method->invoke(null, - array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); - $this->assertEquals(array(false, array(array('a'), array('"b c"'))), $method->invoke(null, - array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + $this->assertEquals(array(false, array(array('a'), array(0, '\'b c\''))), $method->invoke(null, + array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('[b'), array('c]'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('[b'), array('c]'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('b c'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('b c'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), 'q' => array('b c'))), $method->invoke(null, - array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), array('q=[b c'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), 'q' => array('[b'), array('c]'))), $method->invoke(null, - array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('a'), 'q' => array('b'), array('c'))), $method->invoke(null, - array(0,0,0,0,0,0,'a [q]=b c'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'a [q]=b c'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); - $this->assertEquals(array(false, array(array('a'), 'q' => array('"b c"'))), $method->invoke(null, - array(0,0,0,0,0,0,'a q="b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + $this->assertEquals(array(false, array(array('a'), 'q' => array(0, '\'b c\''))), $method->invoke(null, + array(0,0,0,0,0,0,'a q="b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('(foo bar)'))), $method->invoke(null, - array(0,0,0,0,0,0,'(foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0)) + array(0,0,0,0,0,0,'(foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0, 'exhlp' => 1), 'ops' => array('seperator' => ''), 'usedFeature' => array('subexp' => 0), 'scan' => false) )); $this->assertEquals(array(false, array(array('foo'), array("'=='"), array('bar'))), $method->invoke(null, - array(0,0,0,0,0,0,"foo '==' bar"), array('flags' => array('advar' => 1, 'namev' => 1)) + array(0,0,0,0,0,0,"foo '==' bar"), array('flags' => array('advar' => 1, 'namev' => 1, 'noesc' => 0, 'this' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('( foo bar)'))), $method->invoke(null, + array(0,0,0,0,0,0,'( foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0, 'exhlp' => 1), 'ops' => array('seperator' => ''), 'usedFeature' => array('subexp' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('a'), array(0, '\' b c\''))), $method->invoke(null, + array(0,0,0,0,0,0,'a " b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('a'), 'q' => array(0, '\' b c\''))), $method->invoke(null, + array(0,0,0,0,0,0,'a q=" b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('foo'), array(0, "' =='"), array('bar'))), $method->invoke(null, + array(0,0,0,0,0,0,"foo \' ==\' bar"), array('flags' => array('advar' => 1, 'namev' => 1, 'noesc' => 0, 'this' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('a'), array(' b c'))), $method->invoke(null, + array(0,0,0,0,0,0,'a [ b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array(array('a'), 'q' => array(0, "' d e'"))), $method->invoke(null, + array(0,0,0,0,0,0,"a q=\' d e\'"), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) + )); + $this->assertEquals(array(false, array('q' => array('( foo bar)'))), $method->invoke(null, + array(0,0,0,0,0,0,'q=( foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false) )); } /** diff --git a/vendor/zordius/lightncandy/tests/contextTest.php b/vendor/zordius/lightncandy/tests/contextTest.php new file mode 100644 index 00000000..8fa88d88 --- /dev/null +++ b/vendor/zordius/lightncandy/tests/contextTest.php @@ -0,0 +1,300 @@ +<?php + +require_once('src/lightncandy.php'); +require_once('tests/helpers_for_test.php'); + +class contextTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider compileProvider + */ + public function testUsedFeature($test) + { + LightnCandy::compile($test['template'], $test['options']); + $context = LightnCandy::getContext(); + $this->assertEquals($test['expected'], $context['usedFeature']); + } + + public function compileProvider() + { + $default = Array( + 'rootthis' => 0, + 'enc' => 0, + 'raw' => 0, + 'sec' => 0, + 'isec' => 0, + 'if' => 0, + 'else' => 0, + 'unless' => 0, + 'each' => 0, + 'this' => 0, + 'parent' => 0, + 'with' => 0, + 'comment' => 0, + 'partial' => 0, + 'dynpartial' => 0, + 'helper' => 0, + 'bhelper' => 0, + 'hbhelper' => 0, + 'delimiter' => 0, + 'subexp' => 0, + ); + + $compileCases = Array( + Array( + 'template' => 'abc', + ), + + Array( + 'template' => 'abc{{def', + ), + + Array( + 'template' => 'abc{{def}}', + 'expected' => Array( + 'enc' => 1 + ), + ), + + Array( + 'template' => 'abc{{{def}}}', + 'expected' => Array( + 'raw' => 1 + ), + ), + + Array( + 'template' => 'abc{{&def}}', + 'expected' => Array( + 'raw' => 1 + ), + ), + + Array( + 'template' => 'abc{{this}}', + 'expected' => Array( + 'enc' => 1 + ), + ), + + Array( + 'template' => 'abc{{this}}', + 'options' => Array('flags' => LightnCandy::FLAG_THIS), + 'expected' => Array( + 'enc' => 1, + 'this' => 1, + 'rootthis' => 1, + ), + ), + + Array( + 'template' => '{{#if abc}}OK!{{/if}}', + 'expected' => Array( + 'if' => 1 + ), + ), + + Array( + 'template' => '{{#unless abc}}OK!{{/unless}}', + 'expected' => Array( + 'unless' => 1 + ), + ), + + Array( + 'template' => '{{#with abc}}OK!{{/with}}', + 'expected' => Array( + 'with' => 1 + ), + ), + + Array( + 'template' => '{{#abc}}OK!{{/abc}}', + 'expected' => Array( + 'sec' => 1 + ), + ), + + Array( + 'template' => '{{^abc}}OK!{{/abc}}', + 'expected' => Array( + 'isec' => 1 + ), + ), + + Array( + 'template' => '{{#each abc}}OK!{{/each}}', + 'expected' => Array( + 'each' => 1 + ), + ), + + Array( + 'template' => '{{! test}}OK!{{! done}}', + 'expected' => Array( + 'comment' => 2 + ), + ), + + Array( + 'template' => '{{../OK}}', + 'expected' => Array( + 'parent' => 1, + 'enc' => 1, + ), + ), + + Array( + 'template' => '{{&../../OK}}', + 'expected' => Array( + 'parent' => 1, + 'raw' => 1, + ), + ), + + Array( + 'template' => '{{&../../../OK}} {{../OK}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 2, + 'enc' => 1, + 'raw' => 1, + ), + ), + + Array( + 'template' => '{{mytest ../../../OK}} {{../OK}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 2, + 'enc' => 2, + 'hbhelper' => 1, + ), + ), + + Array( + 'template' => '{{mytest . .}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($a, $b) { + return ''; + } + ) + ), + 'expected' => Array( + 'rootthis' => 2, + 'this' => 2, + 'enc' => 1, + 'hbhelper' => 1, + ), + ), + + Array( + 'template' => '{{mytest (mytest ..)}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 1, + 'enc' => 1, + 'hbhelper' => 2, + 'subexp' => 1, + ), + ), + + Array( + 'template' => '{{mytest (mytest ..) .}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 1, + 'rootthis' => 1, + 'this' => 1, + 'enc' => 1, + 'hbhelper' => 2, + 'subexp' => 1, + ), + ), + + Array( + 'template' => '{{mytest (mytest (mytest ..)) .}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'mytest' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 1, + 'rootthis' => 1, + 'this' => 1, + 'enc' => 1, + 'hbhelper' => 3, + 'subexp' => 2, + ), + ), + + Array( + 'id' => '134', + 'template' => '{{#if 1}}{{keys (keys ../names)}}{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'keys' => function ($context) { + return $context; + } + ) + ), + 'expected' => Array( + 'parent' => 1, + 'enc' => 1, + 'if' => 1, + 'hbhelper' => 2, + 'subexp' => 1, + ), + ), + ); + + return array_map(function($i) use ($default) { + if (!isset($i['options'])) { + $i['options'] = Array('flags' => 0); + } + if (!isset($i['options']['flags'])) { + $i['options']['flags'] = 0; + } + $i['expected'] = array_merge($default, isset($i['expected']) ? $i['expected'] : array()); + return Array($i); + }, $compileCases); + } +} + + +?> diff --git a/vendor/zordius/lightncandy/tests/errorTest.php b/vendor/zordius/lightncandy/tests/errorTest.php index 30ecd97d..8c1cbbf1 100644 --- a/vendor/zordius/lightncandy/tests/errorTest.php +++ b/vendor/zordius/lightncandy/tests/errorTest.php @@ -197,7 +197,7 @@ class errorTest extends PHPUnit_Framework_TestCase Array( 'template' => '{{testA[}}', 'options' => Array('flags' => LightnCandy::FLAG_ADVARNAME), - 'expected' => 'Wrong variable naming as \'testA[\' in {{testA[}} !', + 'expected' => 'Wrong variable naming in {{testA[}}', ), Array( 'template' => '{{[testB}}', @@ -387,8 +387,27 @@ class errorTest extends PHPUnit_Framework_TestCase 'flags' => LightnCandy::FLAG_ADVARNAME, 'helpers' => Array('test_join'), ), - 'expected' => "Custom helper 'foo' not found!", + 'expected' => "Can not find custom helper function defination foo() !", ), + Array( + 'template' => '{{1 + 2}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array('test_join'), + ), + 'expected' => "Wrong variable naming as '+' in {{1 + 2}} ! You should wrap ! \" # % & ' * + , ; < = > { | } ~ into [ ]", + ), + Array( + 'template' => '{{> (foo) bar}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'basedir' => '.', + ), + 'expected' => Array( + "Can not find custom helper function defination foo() !", + "You use dynamic partial name as '(foo)', this only works with option FLAG_RUNTIMEPARTIAL enabled", + ) + ), ); return array_map(function($i) { diff --git a/vendor/zordius/lightncandy/tests/helpers_for_test.php b/vendor/zordius/lightncandy/tests/helpers_for_test.php index 93a1dbc7..80c3e860 100644 --- a/vendor/zordius/lightncandy/tests/helpers_for_test.php +++ b/vendor/zordius/lightncandy/tests/helpers_for_test.php @@ -1,5 +1,12 @@ <?php +// Class for customized LCRun +class MyLCRunClass extends LCRun3 { + public static function raw($cx, $v) { + return '[[DEBUG:raw()=>' . var_export($v, true) . ']]'; + } +} + // Classes for inputs or helpers class myClass { function test() { @@ -7,7 +14,7 @@ class myClass { } function helper2($arg) { - return "=$arg="; + return is_array($arg) ? '=Array=' : "=$arg="; } function __call($method, $args) { @@ -63,9 +70,12 @@ class twoDimensionIterator implements Iterator { // Custom helpers function helper1($arg) { + $arg = is_array($arg) ? 'Array' : $arg; return "-$arg-"; } function alink($u, $t) { + $u = is_array($u) ? 'Array' : $u; + $t = is_array($t) ? 'Array' : $t; return "<a href=\"$u\">$t</a>"; } diff --git a/vendor/zordius/lightncandy/tests/regressionTest.php b/vendor/zordius/lightncandy/tests/regressionTest.php index bf591536..d7b6b96d 100644 --- a/vendor/zordius/lightncandy/tests/regressionTest.php +++ b/vendor/zordius/lightncandy/tests/regressionTest.php @@ -282,6 +282,612 @@ class regressionTest extends PHPUnit_Framework_TestCase ), Array( + 'id' => 114, + 'template' => '{{^myeach .}}OK:{{.}},{{else}}NOT GOOD{{/myeach}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_BESTPERFORMANCE, + 'blockhelpers' => Array( + 'myeach' => function ($input) { + return $input; + } + ), + ), + 'data' => Array(1, 'foo', 3, 'bar'), + 'expected' => 'NOT GOOD', + ), + + Array( + 'id' => 114, + 'template' => '{{^myeach .}}OK:{{.}},{{else}}NOT GOOD{{/myeach}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_BESTPERFORMANCE, + 'blockhelpers' => Array( + 'myeach' => function ($input) { + return; + } + ), + ), + 'data' => Array(1, 'foo', 3, 'bar'), + 'expected' => 'OK:,', + ), + + Array( + 'id' => 124, + 'template' => '{{list foo bar abc=(lt 10 3) def=(lt 3 10)}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'lt' => function ($a, $b) { + return ($a > $b) ? Array("$a>$b", 'raw') : ''; + }, + 'list' => function () { + $out = 'List:'; + $args = func_get_args(); + $opts = array_pop($args); + + foreach ($args as $v) { + if ($v) { + $out .= ")$v , "; + } + } + + foreach ($opts['hash'] as $k => $v) { + if ($v) { + $out .= "]$k=$v , "; + } + } + return array($out, 'raw'); + } + ), + ), + 'data' => Array('foo' => 'OK!', 'bar' => 'OK2', 'abc' => false, 'def' => 123), + 'expected' => 'List:)OK! , )OK2 , ]abc=10>3 , ', + ), + + Array( + 'id' => 124, + 'template' => '{{#if (equal \'OK\' cde)}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => 'OK'), + 'expected' => 'YES!' + ), + + Array( + 'id' => 124, + 'template' => '{{#if (equal true (equal \'OK\' cde))}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => 'OK'), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{#if (equal true ( equal \'OK\' cde))}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => 'OK'), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{#if (equal true (equal \' OK\' cde))}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => ' OK'), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{#if (equal true (equal \' ==\' cde))}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => ' =='), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{#if (equal true (equal " ==" cde))}}YES!{{/if}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array('cde' => ' =='), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{[ abc]}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'equal' => function ($a, $b) { + return $a === $b; + } + ), + ), + 'data' => Array(' abc' => 'YES!'), + 'expected' => 'YES!' + ), + + Array( + 'id' => 125, + 'template' => '{{list [ abc] " xyz" \' def\' "==" \'==\' "OK"}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'list' => function ($a, $b) { + $out = 'List:'; + $args = func_get_args(); + $opts = array_pop($args); + foreach ($args as $v) { + if ($v) { + $out .= ")$v , "; + } + } + return $out; + } + ), + ), + 'data' => Array(' abc' => 'YES!'), + 'expected' => 'List:)YES! , ) xyz , ) def , )== , )== , )OK , ' + ), + + Array( + 'id' => 127, + 'template' => '{{#each array}}#{{#if true}}{{name}}-{{../name}}-{{../../name}}-{{../../../name}}{{/if}}##{{#myif true}}{{name}}={{../name}}={{../../name}}={{../../../name}}{{/myif}}###{{#mywith true}}{{name}}~{{../name}}~{{../../name}}~{{../../../name}}{{/mywith}}{{/each}}', + 'data' => Array('name' => 'john', 'array' => Array(1,2,3)), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array('myif', 'mywith'), + ), + 'expected' => '#--john-##==john=###~~john~#--john-##==john=###~~john~#--john-##==john=###~~john~', + ), + + Array( + 'id' => 128, + 'template' => 'foo: {{foo}} , parent foo: {{../foo}}', + 'data' => Array('foo' => 'OK'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + ), + 'expected' => 'foo: OK , parent foo: ', + ), + + Array( + 'id' => 132, + 'template' => '{{list (keys .)}}', + 'data' => Array('foo' => 'bar', 'test' => 'ok'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'keys' => function($arg) { + return Array(array_keys($arg[0]), 'asis'); + }, + 'list' => function($arg) { + return join(',', $arg[0]); + } + ), + ), + 'expected' => 'foo,test', + ), + + Array( + 'id' => 133, + 'template' => "{{list (keys\n .\n ) \n}}", + 'data' => Array('foo' => 'bar', 'test' => 'ok'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'keys' => function($arg) { + return Array(array_keys($arg[0]), 'asis'); + }, + 'list' => function($arg) { + return join(',', $arg[0]); + } + ), + ), + 'expected' => 'foo,test', + ), + + Array( + 'id' => 133, + 'template' => "{{list\n .\n \n \n}}", + 'data' => Array('foo', 'bar', 'test'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'list' => function($arg) { + return join(',', $arg[0]); + } + ), + ), + 'expected' => 'foo,bar,test', + ), + + Array( + 'id' => 134, + 'template' => "{{#if 1}}{{list (keys ../names)}}{{/if}}", + 'data' => Array('names' => Array('foo' => 'bar', 'test' => 'ok')), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'keys' => function($arg) { + return Array(array_keys($arg[0]), 'asis'); + }, + 'list' => function($arg) { + return join(',', $arg[0]); + } + ), + ), + 'expected' => 'foo,test', + ), + + Array( + 'id' => 138, + 'template' => "{{#each (keys .)}}={{.}}{{/each}}", + 'data' => Array('foo' => 'bar', 'test' => 'ok', 'Haha'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'keys' => function($arg) { + return Array(array_keys($arg[0]), 'asis'); + } + ), + ), + 'expected' => '=foo=test=0', + ), + + Array( + 'id' => 140, + 'template' => "{{[a.good.helper] .}}", + 'data' => Array('ha', 'hey', 'ho'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'a.good.helper' => function($arg) { + return join(',', $arg[0]); + } + ), + ), + 'expected' => 'ha,hey,ho', + ), + + Array( + 'id' => 141, + 'template' => "{{#with foo}}{{#getThis bar}}{{/getThis}}{{/with}}", + 'data' => Array('foo' => Array('bar' => 'Good!')), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'getThis' => function($input, $options) { + return $input . '-' . $options['_this']['bar']; + } + ), + ), + 'expected' => 'Good!-Good!', + ), + + Array( + 'id' => 141, + 'template' => "{{#with foo}}{{getThis bar}}{{/with}}", + 'data' => Array('foo' => Array('bar' => 'Good!')), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'getThis' => function($input, $options) { + return $input . '-' . $options['_this']['bar']; + } + ), + ), + 'expected' => 'Good!-Good!', + ), + + Array( + 'id' => 143, + 'template' => "{{testString foo bar=\" \"}}", + 'data' => Array('foo' => 'good!'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'testString' => function($args, $named) { + return $args[0] . '-' . $named['bar']; + } + ), + ), + 'expected' => 'good!- ', + ), + + Array( + 'id' => 143, + 'template' => "{{testString foo bar=\"\"}}", + 'data' => Array('foo' => 'good!'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'testString' => function($args, $named) { + return $args[0] . '-' . $named['bar']; + } + ), + ), + 'expected' => 'good!-', + ), + + Array( + 'id' => 143, + 'template' => "{{testString foo bar=' '}}", + 'data' => Array('foo' => 'good!'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'testString' => function($args, $named) { + return $args[0] . '-' . $named['bar']; + } + ), + ), + 'expected' => 'good!- ', + ), + + Array( + 'id' => 143, + 'template' => "{{testString foo bar=''}}", + 'data' => Array('foo' => 'good!'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'testString' => function($args, $named) { + return $args[0] . '-' . $named['bar']; + } + ), + ), + 'expected' => 'good!-', + ), + + Array( + 'id' => 143, + 'template' => "{{testString foo bar=\" \"}}", + 'data' => Array('foo' => 'good!'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'testString' => function($arg1, $options) { + return $arg1 . '-' . $options['hash']['bar']; + } + ), + ), + 'expected' => 'good!- ', + ), + + Array( + 'id' => 147, + 'template' => '{{> test/test3 foo="bar"}}', + 'data' => Array('test' => 'OK!', 'foo' => 'error'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_RUNTIMEPARTIAL, + 'partials' => Array('test/test3' => '{{test}}, {{foo}}'), + ), + 'expected' => 'OK!, bar' + ), + + Array( + 'id' => 147, + 'template' => '{{> test/test3 foo="bar"}}', + 'data' => new foo(), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_RUNTIMEPARTIAL | LightnCandy::FLAG_INSTANCE, + 'partials' => Array('test/test3' => '{{bar}}, {{foo}}'), + ), + 'expected' => 'OK!, bar' + ), + + Array( + 'id' => 150, + 'template' => '{{{.}}}', + 'data' => Array('hello' => 'world'), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'lcrun' => 'MyLCRunClass', + ), + 'expected' => "[[DEBUG:raw()=>array (\n 'hello' => 'world',\n)]]", + ), + + Array( + 'id' => 153, + 'template' => '{{echo "test[]"}}', + 'data' => null, + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'echo' => function ($in) { + return "-$in[0]-"; + } + ) + ), + 'expected' => "-test[]-", + ), + + Array( + 'id' => 153, + 'template' => '{{echo \'test[]\'}}', + 'data' => null, + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'helpers' => Array( + 'echo' => function ($in) { + return "-$in[0]-"; + } + ) + ), + 'expected' => "-test[]-", + ), + + Array( + 'id' => 154, + 'template' => 'O{{! this is comment ! ... }}K!', + 'data' => null, + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + ), + 'expected' => "OK!" + ), + + Array( + 'template' => '{{testNull null undefined 1}}', + 'data' => 'test', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'testNull' => function($arg1, $arg2) { + return (($arg1 === null) && ($arg2 === null)) ? 'YES!' : 'no'; + } + ) + ), + 'expected' => 'YES!' + ), + + Array( + 'template' => '{{> (pname foo) bar}}', + 'data' => Array('bar' => 'OK! SUBEXP+PARTIAL!', 'foo' => Array('test/test3')), + 'options' => Array( + 'helpers' => Array( + 'pname' => function($arg) { + return $arg[0]; + } + ), + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_RUNTIMEPARTIAL, + 'partials' => Array('test/test3' => '{{.}}'), + ), + 'expected' => 'OK! SUBEXP+PARTIAL!' + ), + + Array( + 'template' => '{{> testpartial newcontext mixed=foo}}', + 'data' => Array('foo' => 'OK!', 'newcontext' => Array('bar' => 'test')), + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_RUNTIMEPARTIAL, + 'partials' => Array('testpartial' => '{{bar}}-{{mixed}}'), + ), + 'expected' => 'test-OK!' + ), + + Array( + 'template' => '{{[helper]}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'helper' => function () { + return 'DEF'; + } + ) + ), + 'data' => Array(), + 'expected' => 'DEF' + ), + + Array( + 'template' => '{{#[helper3]}}ABC{{/[helper3]}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'hbhelpers' => Array( + 'helper3' => function () { + return 'DEF'; + } + ) + ), + 'data' => Array(), + 'expected' => 'DEF' + ), + + Array( + 'template' => '{{#[helper3]}}ABC{{/[helper3]}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS, + 'blockhelpers' => Array( + 'helper3' => function () { + return Array('a', 'b', 'c'); + } + ) + ), + 'data' => Array(), + 'expected' => 'ABC' + ), + + Array( + 'template' => '{{hash abc=["def=123"]}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_BESTPERFORMANCE, + 'hbhelpers' => Array( + 'hash' => function ($options) { + $ret = ''; + foreach ($options['hash'] as $k => $v) { + $ret .= "$k : $v,"; + } + return $ret; + } + ), + ), + 'data' => Array('"def=123"' => 'La!'), + 'expected' => 'abc : La!,', + ), + + Array( + 'template' => '{{hash abc=[\'def=123\']}}', + 'options' => Array( + 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_BESTPERFORMANCE, + 'hbhelpers' => Array( + 'hash' => function ($options) { + $ret = ''; + foreach ($options['hash'] as $k => $v) { + $ret .= "$k : $v,"; + } + return $ret; + } + ), + ), + 'data' => Array("'def=123'" => 'La!'), + 'expected' => 'abc : La!,', + ), + + Array( 'template' => 'ABC{{#block "YES!"}}DEF{{foo}}GHI{{else}}NO~{{/block}}JKL', 'options' => Array( 'flags' => LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_BESTPERFORMANCE, @@ -558,6 +1164,9 @@ VAREND 'he' => 'helper1', 'h2' => 'myClass::helper2', 'link' => function ($arg) { + if (is_array($arg)) { + $arg = 'Array'; + } return "<a href=\"{$arg}\">click here</a>"; }, 'alink', |