@@ -26,6 +26,32 @@ describe('CaseExpression', () => {
2626 backAndForth ( sql , SqlCase ) ;
2727 } ) ;
2828
29+ it ( '.ifThenElse' , ( ) => {
30+ // Test with condition, then, and else
31+ const condition = SqlExpression . parse ( 'x > 5' ) ;
32+ const thenExpr = SqlExpression . parse ( '"result is true"' ) ;
33+ const elseExpr = SqlExpression . parse ( '"result is false"' ) ;
34+
35+ expect ( SqlCase . ifThenElse ( condition , thenExpr , elseExpr ) . toString ( ) ) . toEqual (
36+ 'CASE WHEN x > 5 THEN "result is true" ELSE "result is false" END' ,
37+ ) ;
38+
39+ // Test with literal values
40+ expect ( SqlCase . ifThenElse ( condition , 'yes' , 'no' ) . toString ( ) ) . toEqual (
41+ `CASE WHEN x > 5 THEN 'yes' ELSE 'no' END` ,
42+ ) ;
43+
44+ // Test numeric literals
45+ expect ( SqlCase . ifThenElse ( condition , 1 , 0 ) . toString ( ) ) . toEqual (
46+ 'CASE WHEN x > 5 THEN 1 ELSE 0 END' ,
47+ ) ;
48+
49+ // Test without else expression
50+ expect ( SqlCase . ifThenElse ( condition , thenExpr ) . toString ( ) ) . toEqual (
51+ 'CASE WHEN x > 5 THEN "result is true" END' ,
52+ ) ;
53+ } ) ;
54+
2955 it ( 'caseless CASE Expression' , ( ) => {
3056 const sql = `CASE WHEN B THEN C END` ;
3157
0 commit comments