mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
added some tests
This commit is contained in:
@@ -37,8 +37,11 @@ Twig supports array notation
|
||||
{% set ary = { (a): 'a', (b): 'b', 'c': 'c', (a ~ b): 'd' } %}
|
||||
{{ ary|keys|join(',') }}
|
||||
{{ ary|join(',') }}
|
||||
|
||||
{# ArrayAccess #}
|
||||
{{ array_access['a'] }}
|
||||
--DATA--
|
||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'))
|
||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
||||
--EXPECT--
|
||||
1,2
|
||||
foo,bar
|
||||
@@ -59,3 +62,5 @@ FOO,BAR,
|
||||
|
||||
1,foo,c,1foo
|
||||
a,b,c,d
|
||||
|
||||
b
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
--TEST--
|
||||
Twig supports array notation
|
||||
--TEMPLATE--
|
||||
{# empty array #}
|
||||
{{ []|join(',') }}
|
||||
|
||||
{{ [1, 2]|join(',') }}
|
||||
{{ ['foo', "bar"]|join(',') }}
|
||||
{{ {0: 1, 'foo': 'bar'}|join(',') }}
|
||||
{{ {0: 1, 'foo': 'bar'}|keys|join(',') }}
|
||||
|
||||
{{ {0: 1, foo: 'bar'}|join(',') }}
|
||||
{{ {0: 1, foo: 'bar'}|keys|join(',') }}
|
||||
|
||||
{# nested arrays #}
|
||||
{% set a = [1, 2, [1, 2], {'foo': {'foo': 'bar'}}] %}
|
||||
{{ a[2]|join(',') }}
|
||||
{{ a[3]["foo"]|join(',') }}
|
||||
|
||||
{# works even if [] is used inside the array #}
|
||||
{{ [foo[bar]]|join(',') }}
|
||||
|
||||
{# elements can be any expression #}
|
||||
{{ ['foo'|upper, bar|upper, bar == foo]|join(',') }}
|
||||
|
||||
{# arrays can have a trailing , like in PHP #}
|
||||
{{
|
||||
[
|
||||
1,
|
||||
2,
|
||||
]|join(',')
|
||||
}}
|
||||
|
||||
{# keys can be any expression #}
|
||||
{% set a = 1 %}
|
||||
{% set b = "foo" %}
|
||||
{% set ary = { (a): 'a', (b): 'b', 'c': 'c', (a ~ b): 'd' } %}
|
||||
{{ ary|keys|join(',') }}
|
||||
{{ ary|join(',') }}
|
||||
|
||||
{# ArrayAccess #}
|
||||
{{ array_access['a'] }}
|
||||
--DATA--
|
||||
return array('bar' => 'bar', 'foo' => array('bar' => 'bar'), 'array_access' => new ArrayObject(array('a' => 'b')))
|
||||
--CONFIG--
|
||||
return array('strict_variables' => false)
|
||||
--EXPECT--
|
||||
1,2
|
||||
foo,bar
|
||||
1,bar
|
||||
0,foo
|
||||
|
||||
1,bar
|
||||
0,foo
|
||||
|
||||
1,2
|
||||
bar
|
||||
|
||||
bar
|
||||
|
||||
FOO,BAR,
|
||||
|
||||
1,2
|
||||
|
||||
1,foo,c,1foo
|
||||
a,b,c,d
|
||||
|
||||
b
|
||||
Reference in New Issue
Block a user