@@ -253,6 +253,38 @@ def test_visit_call_sum_prod_with_if(src_suffix: str, dest_suffix: str) -> None:
253
253
assert FunctionCodegen ().visit (node ) == dest_fn + dest_suffix
254
254
255
255
256
+ @pytest .mark .parametrize (
257
+ "code,latex" ,
258
+ [
259
+ (
260
+ "x if x < y else y" ,
261
+ r"\left\{ \begin{array}{ll} x,"
262
+ r" & \mathrm{if} \ {x < y} \\ y,"
263
+ r" & \mathrm{otherwise} \end{array} \right." ,
264
+ ),
265
+ (
266
+ "x if x < y else (y if y < z else z)" ,
267
+ r"\left\{ \begin{array}{ll} x,"
268
+ r" & \mathrm{if} \ {x < y} \\ y,"
269
+ r" & \mathrm{if} \ {y < z} \\ z,"
270
+ r" & \mathrm{otherwise} \end{array} \right." ,
271
+ ),
272
+ (
273
+ "x if x < y else (y if y < z else (z if z < w else w))" ,
274
+ r"\left\{ \begin{array}{ll} x,"
275
+ r" & \mathrm{if} \ {x < y} \\ y,"
276
+ r" & \mathrm{if} \ {y < z} \\ z,"
277
+ r" & \mathrm{if} \ {z < w} \\ w,"
278
+ r" & \mathrm{otherwise} \end{array} \right." ,
279
+ ),
280
+ ],
281
+ )
282
+ def test_if_then_else (code : str , latex : str ) -> None :
283
+ node = ast .parse (code ).body [0 ].value
284
+ assert isinstance (node , ast .IfExp )
285
+ assert FunctionCodegen ().visit (node ) == latex
286
+
287
+
256
288
@pytest .mark .parametrize (
257
289
"code,latex" ,
258
290
[
0 commit comments