Phalcon\Test\Unit\Mvc\View\Engine\Volt\CompilerTest::testVoltParser PHP Метод

testVoltParser() публичный Метод

public testVoltParser ( )
    public function testVoltParser()
    {
        $this->specify("Volt parser doesn't work as expected", function () {
            $volt = new Compiler();
            $intermediate = $volt->parse('');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(0);
            //Comments
            $intermediate = $volt->parse('{# hello #}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(0);
            $intermediate = $volt->parse('{# hello #}{# other comment #}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(0);
            //Common Expressions
            $intermediate = $volt->parse('hello');
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ 1 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ 1.2 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ false }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ true }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ null }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "hello" }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "\'hello\'" }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "hello" }}{{ "hello" }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('{{ "hello" }}-{{ "hello" }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(3);
            $intermediate = $volt->parse('-{{ "hello" }}{{ "hello" }}-');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(4);
            $intermediate = $volt->parse('-{{ "hello" }}-{{ "hello" }}-');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(5);
            $intermediate = $volt->parse('Some = {{ 100+50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('Some = {{ 100-50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('Some = {{ 100*50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('Some = {{ 100/50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('Some = {{ 100%50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            $intermediate = $volt->parse('Some = {{ 100~50 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(2);
            //Array access
            $intermediate = $volt->parse('{{ a[0 ]}}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a[0 ][1]}}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a[0]["hello"] }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a[0][1.2][false][true] }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a[0][1.2][false][true][b] }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Attribute access
            $intermediate = $volt->parse('{{ a.b }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a.b.c }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ (a.b).c }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ a.(b.c) }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Ranges
            $intermediate = $volt->parse('{{ 1..100 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "Z".."A" }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ 'a'..'z' }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ 'a' .. 'z' }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Unary operators
            $intermediate = $volt->parse('{{ -10 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ !10 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ !a }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ not a }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ 10-- }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ !!10 }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Calling functions
            $intermediate = $volt->parse("{{ contents() }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ link_to('hello', 'some-link') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ form('action': 'save/products', 'method': 'post') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ form('action': 'save/products', 'method': other_func(1, 2, 3)) }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ partial('hello/x') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ dump(a) }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ date('Y-m-d', time()) }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ flash.outputMessages() }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ session.get('hello') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ user.session.get('hello') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ user.session.get(request.getPost('token')) }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ a[0]('hello') }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ [a[0]('hello').name]|keys }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Arrays
            $intermediate = $volt->parse("{{ [1, 2, 3, 4] }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ ["hello", 2, 1.3, false, true, null] }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ ["hello", 2, 3, false, true, null, [1, 2, "hola"]] }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse("{{ ['first': 1, 'second': 2, 'third': 3] }}");
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Filters
            $intermediate = $volt->parse('{{ "hello"|e }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ ("hello" ~ "lol")|e|length }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ (("hello" ~ "lol")|e|length)|trim }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "a".."z"|join(",") }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ "My real name is %s"|format(name) }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{{ robot.price|default(10.0) }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //if statement
            $intermediate = $volt->parse('{% if a==b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a!=b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a<b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a>b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a<=b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a>=b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a===b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a!==b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a and b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a or b %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a is defined %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a is not defined %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a is 100 %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a is not 100 %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a==b and c==d %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a==b or c==d %} hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a==b %} hello {% else %} not hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a==b %} {% if c==d %} hello {% endif %} {% else %} not hello {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% if a==b %} hello {% else %} {% if c==d %} not hello {% endif %} {% endif %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //for statement
            $intermediate = $volt->parse('{% for a in b %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for a in b[0] %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for a in b.c %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for a in 1..10 %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for a in 1..10 if a < 5 and a > 7 %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for a in 1..10 %} {% for b in 1..10 %} hello {% endfor %} {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for k, v in [1, 2, 3] %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for k, v in [1, 2, 3] if v is odd %} hello {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for v in [1, 2, 3] %} {% break %} {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% for v in [1, 2] %} {% continue %} {% endfor %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //set statement
            $intermediate = $volt->parse('{% set a = 1 %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% set a = b %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% set a = 1.2 %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% set a = 1.2+1*(20/b) and c %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% set a[0] = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% set a[0][1] = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% set a.y = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% set a.y.x = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% set a[0].y = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% set a.y[0] = 1 %}');
            expect(is_array($intermediate))->true();
            $intermediate = $volt->parse('{% do 1 %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% do a + b %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% do a - 1.2 %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% do 1.2 + 1 * (20 / b) and c %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% do super()|e %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Autoescape
            $intermediate = $volt->parse('{% autoescape true %} {% endautoescape %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% autoescape false %} {% endautoescape %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Blocks
            $intermediate = $volt->parse('{% block hello %} {% endblock %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% block hello %}{% endblock %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Extends
            $intermediate = $volt->parse('{% extends "some/file.volt" %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Include
            $intermediate = $volt->parse('{% include "some/file.volt" %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Cache
            $intermediate = $volt->parse('{% cache sidebar %} hello {% endcache %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            $intermediate = $volt->parse('{% cache sidebar 500 %} hello {% endcache %}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
            //Mixed
            $intermediate = $volt->parse('{# some comment #}{{ "hello" }}{# other comment }}');
            expect(is_array($intermediate))->true();
            expect($intermediate)->count(1);
        });
    }