@@ -191,6 +191,84 @@ static void test_conditionals(testing & t) {
191191 json::object (),
192192 " yes"
193193 );
194+
195+ test_template (t, " is undefined falsy" ,
196+ " {{ 'yes' if not y else 'no' }}" ,
197+ json::object (),
198+ " yes"
199+ );
200+
201+ test_template (t, " is undefined attribute falsy" ,
202+ " {{ 'yes' if not y.x else 'no' }}" ,
203+ {{" y" , true }},
204+ " yes"
205+ );
206+
207+ test_template (t, " is undefined key falsy" ,
208+ " {{ 'yes' if not y['x'] else 'no' }}" ,
209+ {{" y" , {{}}}},
210+ " yes"
211+ );
212+
213+ test_template (t, " is empty array falsy" ,
214+ " {{ 'yes' if not y else 'no' }}" ,
215+ {{" y" , json::array ()}},
216+ " yes"
217+ );
218+
219+ test_template (t, " is empty object falsy" ,
220+ " {{ 'yes' if not y else 'no' }}" ,
221+ {{" y" , json::object ()}},
222+ " yes"
223+ );
224+
225+ test_template (t, " is empty string falsy" ,
226+ " {{ 'yes' if not y else 'no' }}" ,
227+ {{" y" , " " }},
228+ " yes"
229+ );
230+
231+ test_template (t, " is 0 falsy" ,
232+ " {{ 'yes' if not y else 'no' }}" ,
233+ {{" y" , 0 }},
234+ " yes"
235+ );
236+
237+ test_template (t, " is 0.0 falsy" ,
238+ " {{ 'yes' if not y else 'no' }}" ,
239+ {{" y" , 0.0 }},
240+ " yes"
241+ );
242+
243+ test_template (t, " is non-empty array truthy" ,
244+ " {{ 'yes' if y else 'no' }}" ,
245+ {{" y" , json::array ({" " })}},
246+ " yes"
247+ );
248+
249+ test_template (t, " is non-empty object truthy" ,
250+ " {{ 'yes' if y else 'no' }}" ,
251+ {{" y" , {" x" , false }}},
252+ " yes"
253+ );
254+
255+ test_template (t, " is non-empty string truthy" ,
256+ " {{ 'yes' if y else 'no' }}" ,
257+ {{" y" , " 0" }},
258+ " yes"
259+ );
260+
261+ test_template (t, " is 1 truthy" ,
262+ " {{ 'yes' if y else 'no' }}" ,
263+ {{" y" , 1 }},
264+ " yes"
265+ );
266+
267+ test_template (t, " is 1.0 truthy" ,
268+ " {{ 'yes' if y else 'no' }}" ,
269+ {{" y" , 1.0 }},
270+ " yes"
271+ );
194272}
195273
196274static void test_loops (testing & t) {
0 commit comments