-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #753 from Golmote/tests-twig
Add tests for Twig
- Loading branch information
Showing
6 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |