|
| 1 | +"""Universal `end` tag test cases.""" |
| 2 | + |
| 3 | +from liquid.golden.case import Case |
| 4 | + |
| 5 | +cases = [ |
| 6 | + Case( |
| 7 | + description="end if", |
| 8 | + template=r"{% if true %}foo{% end %}", |
| 9 | + expect="foo", |
| 10 | + future=True, |
| 11 | + ), |
| 12 | + Case( |
| 13 | + description="end if, else", |
| 14 | + template=r"{% if false %}foo{% else %}bar{% end %}", |
| 15 | + expect="bar", |
| 16 | + future=True, |
| 17 | + ), |
| 18 | + Case( |
| 19 | + description="end if, elsif", |
| 20 | + template=r"{% if false %}foo{% elsif true %}bar{% end %}", |
| 21 | + expect="bar", |
| 22 | + future=True, |
| 23 | + ), |
| 24 | + Case( |
| 25 | + description="end if, whitespace control", |
| 26 | + template="{% if true -%}\nfoo\n{%- end %}", |
| 27 | + expect="foo", |
| 28 | + future=True, |
| 29 | + ), |
| 30 | + Case( |
| 31 | + description="end for", |
| 32 | + template=r"{% for x in (1..2) %}{{ x }},{% end %}", |
| 33 | + expect="1,2,", |
| 34 | + future=True, |
| 35 | + ), |
| 36 | + Case( |
| 37 | + description="end for, else", |
| 38 | + template=r"{% for x in a %}{{ x }},{% else %}bar{% end %}", |
| 39 | + expect="bar", |
| 40 | + future=True, |
| 41 | + globals={"a": []}, |
| 42 | + ), |
| 43 | + Case( |
| 44 | + description="end if, nested universal", |
| 45 | + template="\n".join( |
| 46 | + [ |
| 47 | + r"{% if true %}", |
| 48 | + r"foo", |
| 49 | + r"{% if true %}", |
| 50 | + r"bar", |
| 51 | + r"{% end %}", |
| 52 | + r"{% end %}", |
| 53 | + ] |
| 54 | + ), |
| 55 | + expect="\nfoo\n\nbar\n\n", |
| 56 | + future=True, |
| 57 | + ), |
| 58 | + Case( |
| 59 | + description="end if, alternative, nested universal", |
| 60 | + template="\n".join( |
| 61 | + [ |
| 62 | + r"{% if false %}", |
| 63 | + r"foo", |
| 64 | + r"{% else %}", |
| 65 | + r"{% if true %}", |
| 66 | + r"bar", |
| 67 | + r"{% end %}", |
| 68 | + r"{% end %}", |
| 69 | + ] |
| 70 | + ), |
| 71 | + expect="\n\nbar\n\n", |
| 72 | + future=True, |
| 73 | + ), |
| 74 | + Case( |
| 75 | + description="end if, nested inner", |
| 76 | + template="\n".join( |
| 77 | + [ |
| 78 | + r"{% if true %}", |
| 79 | + r"foo", |
| 80 | + r"{% if true %}", |
| 81 | + r"bar", |
| 82 | + r"{% end %}", |
| 83 | + r"{% endif %}", |
| 84 | + ] |
| 85 | + ), |
| 86 | + expect="\nfoo\n\nbar\n\n", |
| 87 | + future=True, |
| 88 | + ), |
| 89 | + Case( |
| 90 | + description="end if, nested outer", |
| 91 | + template="\n".join( |
| 92 | + [ |
| 93 | + r"{% if true %}", |
| 94 | + r"foo", |
| 95 | + r"{% if true %}", |
| 96 | + r"bar", |
| 97 | + r"{% endif %}", |
| 98 | + r"{% end %}", |
| 99 | + ] |
| 100 | + ), |
| 101 | + expect="\nfoo\n\nbar\n\n", |
| 102 | + future=True, |
| 103 | + ), |
| 104 | + Case( |
| 105 | + description="liquid, end if", |
| 106 | + template="\n".join( |
| 107 | + [ |
| 108 | + r"{% liquid ", |
| 109 | + r"if true", |
| 110 | + r" echo 'foo'", |
| 111 | + r"end", |
| 112 | + r"%}", |
| 113 | + ] |
| 114 | + ), |
| 115 | + expect="foo", |
| 116 | + future=True, |
| 117 | + ), |
| 118 | +] |
0 commit comments