Skip to content

Commit

Permalink
Merge pull request #753 from Golmote/tests-twig
Browse files Browse the repository at this point in the history
Add tests for Twig
  • Loading branch information
Golmote committed Sep 9, 2015
2 parents c2431a7 + db25ed7 commit cd58ab0
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/languages/twig/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{ null }}
{{- true -}}
{{ false }}

----------------------------------------------------

[
["tag", [
["ld", [["punctuation", "{{"]]],
["boolean", "null"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{-"]]],
["boolean", "true"],
["rd", [["punctuation", "-}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["boolean", "false"],
["rd", [["punctuation", "}}"]]]
]]
]

----------------------------------------------------

Checks for booleans and null.
16 changes: 16 additions & 0 deletions tests/languages/twig/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{##}
{# foo #}
{# foo
bar #}

----------------------------------------------------

[
["comment", "{##}"],
["comment", "{# foo #}"],
["comment", "{# foo\r\nbar #}"]
]

----------------------------------------------------

Checks for comments.
53 changes: 53 additions & 0 deletions tests/languages/twig/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% for foo in bar if baz %}{% endfor %}
{%- if foo() -%}{%- endif -%}
{% macro foobar() %}{% endmacro %}
{{ foo is even or bar is odd }}

----------------------------------------------------

[
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "for"]]],
["property", "foo"],
["operator", "in"], ["property", "bar"],
["keyword", "if"], ["property", "baz"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "endfor"]]],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%-"], ["keyword", "if"]]],
["property", "foo"], ["punctuation", "("], ["punctuation", ")"],
["rd", [["punctuation", "-%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%-"], ["keyword", "endif"]]],
["rd", [["punctuation", "-%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "macro"]]],
["property", "foobar"], ["punctuation", "("], ["punctuation", ")"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "endmacro"]]],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "foo"],
["operator", "is"],
["keyword", "even"],
["operator", "or"],
["property", "bar"],
["operator", "is"],
["keyword", "odd"],
["rd", [["punctuation", "}}"]]]
]]
]

----------------------------------------------------

Checks for keywords.
45 changes: 45 additions & 0 deletions tests/languages/twig/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{ 0xBadFace }}
{{ 42 }}
{{ 3.14159 }}
{{ 3e15 }}
{{ 4.5E-4 }}
{{ 0.2e+8 }}

----------------------------------------------------

[
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "0xBadFace"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "42"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "3.14159"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "3e15"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "4.5E-4"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["number", "0.2e+8"],
["rd", [["punctuation", "}}"]]]
]]
]

----------------------------------------------------

Checks for hexadecimal and decimal numbers.
179 changes: 179 additions & 0 deletions tests/languages/twig/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{% set a = 4 %}
{{ a == 4 }}
{{ b != c }}
{{ c < d }}
{{ d <= e }}
{{ e > f }}
{{ f >= g }}
{{ g + h }}
{{ h - i }}
{{ i ~ j }}
{{ j * k }}
{{ k ** l }}
{{ l / m }}
{{ m // n }}
{{ n % o }}
{{ o|default('foo') }}
{{ p ? q : r }}
{{ s ?: t }}

{% if a and b or not c %}
{% for p in foo %}
{% if d b-and e and f b-xor g or h b-or i %}
{% if j starts with 'h' %}
{% if i ends with 'j' %}
{% if k is same as false %}
{% if l matches '/f[o]{2,}(?:bar)?' %}

----------------------------------------------------

[
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "set"]]],
["property", "a"], ["operator", "="], ["number", "4"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "a"], ["operator", "=="], ["number", "4"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "b"], ["operator", "!="], ["property", "c"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "c"], ["operator", "<"], ["property", "d"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "d"], ["operator", "<="], ["property", "e"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "e"], ["operator", ">"], ["property", "f"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "f"], ["operator", ">="], ["property", "g"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "g"], ["operator", "+"], ["property", "h"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "h"], ["operator", "-"], ["property", "i"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "i"], ["operator", "~"], ["property", "j"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "j"], ["operator", "*"], ["property", "k"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "k"], ["operator", "**"], ["property", "l"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "l"], ["operator", "/"], ["property", "m"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "m"], ["operator", "//"], ["property", "n"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "n"], ["operator", "%"], ["property", "o"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "o"],
["operator", "|"],
["property", "default"],
["punctuation", "("],
["string", [["punctuation", "'"], "foo", ["punctuation", "'"]]],
["punctuation", ")"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "p"], ["operator", "?"],
["property", "q"], ["punctuation", ":"],
["property", "r"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["property", "s"], ["operator", "?:"], ["property", "t"],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "a"], ["operator", "and"], ["property", "b"],
["operator", "or"], ["operator", "not"], ["property", "c"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "for"]]],
["property", "p"], ["operator", "in"], ["property", "foo"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "d"], ["operator", "b-and"],
["property", "e"], ["operator", "and"],
["property", "f"], ["operator", "b-xor"],
["property", "g"], ["operator", "or"],
["property", "h"], ["operator", "b-or"],
["property", "i"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "j"],
["operator", "starts with"],
["string", [["punctuation", "'"], "h", ["punctuation", "'"]]],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "i"],
["operator", "ends with"],
["string", [["punctuation", "'"], "j", ["punctuation", "'"]]],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "k"], ["operator", "is"],
["operator", "same as"], ["boolean", "false"],
["rd", [["punctuation", "%}"]]]
]],
["tag", [
["ld", [["punctuation", "{%"], ["keyword", "if"]]],
["property", "l"], ["operator", "matches"],
["string", [["punctuation", "'"], "/f[o]{2,}(?:bar)?", ["punctuation", "'"]]],
["rd", [["punctuation", "%}"]]]
]]
]

----------------------------------------------------

Checks for operators.
33 changes: 33 additions & 0 deletions tests/languages/twig/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{ '' }}
{{ "" }}
{{ "ba\"r" }}
{{ 'ba\'z' }}

----------------------------------------------------

[
["tag", [
["ld", [["punctuation", "{{"]]],
["string", [["punctuation", "'"], ["punctuation", "'"]]],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["string", [["punctuation", "\""], ["punctuation", "\""]]],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["string", [["punctuation", "\""], "ba\\\"r", ["punctuation", "\""]]],
["rd", [["punctuation", "}}"]]]
]],
["tag", [
["ld", [["punctuation", "{{"]]],
["string", [["punctuation", "'"], "ba\\'z", ["punctuation", "'"]]],
["rd", [["punctuation", "}}"]]]
]]
]

----------------------------------------------------

Checks for strings.

0 comments on commit cd58ab0

Please sign in to comment.