|
| 1 | +using FlexRender.Parsing; |
1 | 2 | using FlexRender.Parsing.Ast; |
2 | 3 | using FlexRender.Xml; |
3 | 4 | using Xunit; |
@@ -78,4 +79,64 @@ public void Parse_If_ElseIf() |
78 | 79 | Assert.NotNull(ifEl.ElseIf); |
79 | 80 | Assert.Equal("warm", ifEl.ElseIf!.CompareValue); |
80 | 81 | } |
| 82 | + |
| 83 | + [Fact] |
| 84 | + public void Parse_ElseIf_WithNoChild_Throws() |
| 85 | + { |
| 86 | + const string xml = """ |
| 87 | + <flexrender> |
| 88 | + <canvas width="300"/> |
| 89 | + <if condition="status" equals="hot"> |
| 90 | + <then><text content="HOT"/></then> |
| 91 | + <else-if></else-if> |
| 92 | + </if> |
| 93 | + </flexrender> |
| 94 | + """; |
| 95 | + |
| 96 | + var ex = Assert.Throws<TemplateParseException>(() => _parser.Parse(xml)); |
| 97 | + Assert.Contains("else-if", ex.Message); |
| 98 | + } |
| 99 | + |
| 100 | + [Fact] |
| 101 | + public void Parse_ElseIf_WithNonIfChild_Throws() |
| 102 | + { |
| 103 | + const string xml = """ |
| 104 | + <flexrender> |
| 105 | + <canvas width="300"/> |
| 106 | + <if condition="status" equals="hot"> |
| 107 | + <then><text content="HOT"/></then> |
| 108 | + <else-if> |
| 109 | + <text content="oops"/> |
| 110 | + </else-if> |
| 111 | + </if> |
| 112 | + </flexrender> |
| 113 | + """; |
| 114 | + |
| 115 | + var ex = Assert.Throws<TemplateParseException>(() => _parser.Parse(xml)); |
| 116 | + Assert.Contains("else-if", ex.Message); |
| 117 | + } |
| 118 | + |
| 119 | + [Fact] |
| 120 | + public void Parse_ElseIf_WithMultipleChildren_Throws() |
| 121 | + { |
| 122 | + const string xml = """ |
| 123 | + <flexrender> |
| 124 | + <canvas width="300"/> |
| 125 | + <if condition="status" equals="hot"> |
| 126 | + <then><text content="HOT"/></then> |
| 127 | + <else-if> |
| 128 | + <if condition="status" equals="warm"> |
| 129 | + <then><text content="WARM"/></then> |
| 130 | + </if> |
| 131 | + <if condition="status" equals="cool"> |
| 132 | + <then><text content="COOL"/></then> |
| 133 | + </if> |
| 134 | + </else-if> |
| 135 | + </if> |
| 136 | + </flexrender> |
| 137 | + """; |
| 138 | + |
| 139 | + var ex = Assert.Throws<TemplateParseException>(() => _parser.Parse(xml)); |
| 140 | + Assert.Contains("else-if", ex.Message); |
| 141 | + } |
81 | 142 | } |
0 commit comments