-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #4169 Fix usage of loop in a for else clause (fabpot)
This PR was merged into the 4.x branch. Discussion ---------- Fix usage of loop in a for else clause Commits ------- 5649de8 Fix usage of loop in a for else clause
- Loading branch information
Showing
3 changed files
with
70 additions
and
3 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
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
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,62 @@ | ||
--TEST-- | ||
"for" tag loop behavior in an else clause | ||
--TEMPLATE-- | ||
{% for item in [] %} | ||
{% else %} | ||
{{ loop.previous is null ? 'OK' : 'KO' }} | ||
{{ loop.next is null ? 'OK' : 'KO' }} | ||
{{ loop.first ? 'OK' : 'KO' }} | ||
{{ loop.last ? 'OK' : 'KO' }} | ||
{{ loop.index0 is same as 0 ? 'OK' : 'KO' }} | ||
{{ loop.revindex0 is same as 0 ? 'OK' : 'KO' }} | ||
{{ loop.length is same as 0 ? 'OK' : 'KO' }} | ||
{{ loop.depth is same as 1 ? 'OK' : 'KO' }} | ||
{% endfor %} | ||
|
||
{% for item in empty_it %} | ||
{% else %} | ||
{{ loop.previous is null ? 'OK' : 'KO' }} | ||
{{ loop.next is null ? 'OK' : 'KO' }} | ||
{{ loop.first ? 'OK' : 'KO' }} | ||
{{ loop.last ? 'OK' : 'KO' }} | ||
{{ loop.index0 is same as 0 ? 'OK' : 'KO' }} | ||
{{ loop.depth is same as 1 ? 'OK' : 'KO' }} | ||
{% endfor %} | ||
|
||
{% for item in yielding_it %} | ||
{% else %} | ||
{{ loop.previous is null ? 'OK' : 'KO' }} | ||
{{ loop.next is null ? 'OK' : 'KO' }} | ||
{{ loop.first ? 'OK' : 'KO' }} | ||
{{ loop.last ? 'OK' : 'KO' }} | ||
{{ loop.index0 is same as 0 ? 'OK' : 'KO' }} | ||
{{ loop.depth is same as 1 ? 'OK' : 'KO' }} | ||
{% endfor %} | ||
--DATA-- | ||
return [ | ||
'empty_it' => new \EmptyIterator(), | ||
'yielding_it' => (function (): \Generator { return; yield; })(), | ||
] | ||
--EXPECT-- | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
|
||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
|
||
OK | ||
OK | ||
OK | ||
OK | ||
OK | ||
OK |