decy-parser 2.2.0

C AST parsing using clang-sys for Decy transpiler
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
//! Unit tests for the C parser (DECY-001 RED phase).
//!
//! These tests are intentionally failing to follow EXTREME TDD methodology.

use super::*;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_parser_creation() {
        // Test that we can create a parser
        let result = CParser::new();
        assert!(result.is_ok(), "Parser creation should succeed");
    }

    #[test]
    fn test_parse_simple_main_function() {
        // RED PHASE: This test will FAIL until we implement clang-sys parsing
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int main() { return 0; }";

        let ast = parser.parse(source).expect("Parsing simple main function should succeed");

        // Verify we got one function
        assert_eq!(ast.functions().len(), 1, "Should parse exactly one function");

        // Verify function details
        let func = &ast.functions()[0];
        assert_eq!(func.name, "main", "Function name should be 'main'");
        assert_eq!(func.return_type, Type::Int, "Return type should be int");
        assert_eq!(func.parameters.len(), 0, "main() should have no parameters");
    }

    #[test]
    fn test_parse_function_with_parameters() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int add(int a, int b) { return a + b; }";

        let ast = parser.parse(source).expect("Parsing function with parameters should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "add");
        assert_eq!(func.return_type, Type::Int);
        assert_eq!(func.parameters.len(), 2);

        assert_eq!(func.parameters[0].name, "a");
        assert_eq!(func.parameters[0].param_type, Type::Int);

        assert_eq!(func.parameters[1].name, "b");
        assert_eq!(func.parameters[1].param_type, Type::Int);
    }

    #[test]
    fn test_parse_function_with_return_value() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let source = "float calculate(int x) { return x * 2.5; }";

        let ast = parser.parse(source).expect("Parsing function with return value should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "calculate");
        assert_eq!(func.return_type, Type::Float);
        assert_eq!(func.parameters.len(), 1);
        assert_eq!(func.parameters[0].param_type, Type::Int);
    }

    #[test]
    fn test_parse_syntax_error_handling() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let invalid_source = "int incomplete(";

        let result = parser.parse(invalid_source);
        assert!(result.is_err(), "Parsing invalid syntax should return an error");
    }

    #[test]
    fn test_parse_empty_input() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let empty_source = "";

        let result = parser.parse(empty_source);
        // Empty input should either return empty AST or error (design decision)
        // For now, we expect it to succeed with empty AST
        assert!(result.is_ok(), "Parsing empty input should succeed");

        if let Ok(ast) = result {
            assert_eq!(ast.functions().len(), 0, "Empty input should have no functions");
        }
    }

    #[test]
    fn test_parse_multiple_functions() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"
            int add(int a, int b) { return a + b; }
            int subtract(int a, int b) { return a - b; }
        "#;

        let ast = parser.parse(source).expect("Parsing multiple functions should succeed");

        assert_eq!(ast.functions().len(), 2, "Should parse two functions");
        assert_eq!(ast.functions()[0].name, "add");
        assert_eq!(ast.functions()[1].name, "subtract");
    }

    #[test]
    fn test_parse_void_function() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void print_hello() { }";

        let ast = parser.parse(source).expect("Parsing void function should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "print_hello");
        assert_eq!(func.return_type, Type::Void);
        assert_eq!(func.parameters.len(), 0);
    }

    #[test]
    fn test_parse_pointer_parameter() {
        // RED PHASE: This test will FAIL
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void process(int* data) { }";

        let ast = parser.parse(source).expect("Parsing pointer parameter should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "process");
        assert_eq!(func.return_type, Type::Void);
        assert_eq!(func.parameters.len(), 1);

        // Check that parameter is a pointer
        match &func.parameters[0].param_type {
            Type::Pointer(inner) => {
                assert_eq!(**inner, Type::Int, "Should be pointer to int");
            }
            _ => panic!("Parameter should be a pointer type"),
        }
    }

    #[test]
    fn test_parse_double_type() {
        // Test for double type conversion (mutation testing found this gap)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "double calculate_pi() { return 3.14159; }";

        let ast = parser.parse(source).expect("Parsing double function should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "calculate_pi");
        assert_eq!(func.return_type, Type::Double, "Return type should be double");
    }

    #[test]
    fn test_parse_double_parameter() {
        // Test for double parameter type
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int round_value(double value) { return 0; }";

        let ast =
            parser.parse(source).expect("Parsing function with double parameter should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.parameters.len(), 1);
        assert_eq!(func.parameters[0].param_type, Type::Double, "Parameter should be double");
    }

    #[test]
    fn test_parse_char_type() {
        // Test for char type conversion (mutation testing found this gap)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "char get_initial() { return 'A'; }";

        let ast = parser.parse(source).expect("Parsing char function should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_initial");
        assert_eq!(func.return_type, Type::Char, "Return type should be char");
    }

    #[test]
    fn test_parse_char_parameter() {
        // Test for char parameter type
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int to_uppercase(char c) { return 0; }";

        let ast =
            parser.parse(source).expect("Parsing function with char parameter should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.parameters.len(), 1);
        assert_eq!(func.parameters[0].param_type, Type::Char, "Parameter should be char");
    }

    #[test]
    fn test_parse_mixed_types() {
        // Test function with multiple different types
        let parser = CParser::new().expect("Parser creation failed");
        let source = "double complex_calc(int a, float b, double c, char d) { return 0.0; }";

        let ast = parser.parse(source).expect("Parsing function with mixed types should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.return_type, Type::Double);
        assert_eq!(func.parameters.len(), 4);
        assert_eq!(func.parameters[0].param_type, Type::Int);
        assert_eq!(func.parameters[1].param_type, Type::Float);
        assert_eq!(func.parameters[2].param_type, Type::Double);
        assert_eq!(func.parameters[3].param_type, Type::Char);
    }

    #[test]
    fn test_parse_return_literal_value() {
        // DECY-028: Test that return statements preserve actual integer values
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int get_value() { return 42; }";

        let ast = parser.parse(source).expect("Parsing return with literal should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_value");
        assert_eq!(func.body.len(), 1, "Should have one statement");

        // Verify return statement has correct value
        match &func.body[0] {
            Statement::Return(Some(Expression::IntLiteral(value))) => {
                assert_eq!(*value, 42, "Return value should be 42, not 0");
            }
            _ => panic!("Expected Return statement with IntLiteral(42)"),
        }
    }

    #[test]
    fn test_parse_binary_expression() {
        // DECY-028: Test that binary expressions are parsed
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int add(int a, int b) { return a + b; }";

        let ast = parser.parse(source).expect("Parsing binary expression should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "add");
        assert_eq!(func.body.len(), 1, "Should have one statement");

        // Verify return statement has binary expression
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, left, right })) => {
                assert_eq!(*op, BinaryOperator::Add, "Operator should be Add");

                // Left side should be variable 'a'
                match **left {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "a", "Left operand should be variable 'a'");
                    }
                    _ => panic!("Left operand should be a variable"),
                }

                // Right side should be variable 'b'
                match **right {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "b", "Right operand should be variable 'b'");
                    }
                    _ => panic!("Right operand should be a variable"),
                }
            }
            _ => panic!("Expected Return statement with BinaryOp expression"),
        }
    }

    #[test]
    fn test_parse_assignment_statement() {
        // DECY-028 Phase 3: Test that assignment statements are parsed
        // RED PHASE: This test will FAIL because Statement doesn't have Assignment variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void set_value() { int x; x = 42; }";

        let ast = parser.parse(source).expect("Parsing assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "set_value");
        assert_eq!(func.body.len(), 2, "Should have two statements: declaration and assignment");

        // First statement: variable declaration
        match &func.body[0] {
            Statement::VariableDeclaration { name, var_type, initializer } => {
                assert_eq!(name, "x");
                assert_eq!(*var_type, Type::Int);
                assert!(initializer.is_none());
            }
            _ => panic!("Expected VariableDeclaration statement"),
        }

        // Second statement: assignment
        match &func.body[1] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "x", "Assignment target should be 'x'");
                match value {
                    Expression::IntLiteral(val) => {
                        assert_eq!(*val, 42, "Assignment value should be 42");
                    }
                    _ => panic!("Assignment value should be IntLiteral(42)"),
                }
            }
            _ => panic!("Expected Assignment statement"),
        }
    }

    #[test]
    fn test_parse_if_statement() {
        // DECY-029 RED PHASE: Test that if statements are parsed
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int max(int a, int b) { if (a > b) { return a; } return b; }";

        let ast = parser.parse(source).expect("Parsing if statement should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "max");
        assert_eq!(func.body.len(), 2, "Should have if statement and return");

        // First statement: if statement
        match &func.body[0] {
            Statement::If { condition, then_block, else_block } => {
                // Check condition: a > b
                match condition {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(*op, BinaryOperator::GreaterThan);
                        match **left {
                            Expression::Variable(ref name) => assert_eq!(name, "a"),
                            _ => panic!("Expected variable 'a'"),
                        }
                        match **right {
                            Expression::Variable(ref name) => assert_eq!(name, "b"),
                            _ => panic!("Expected variable 'b'"),
                        }
                    }
                    _ => panic!("Expected binary expression for condition"),
                }

                // Check then block
                assert_eq!(then_block.len(), 1, "Then block should have one statement");
                match &then_block[0] {
                    Statement::Return(Some(Expression::Variable(ref name))) => {
                        assert_eq!(name, "a");
                    }
                    _ => panic!("Expected return statement in then block"),
                }

                // Check else block
                assert!(else_block.is_none(), "Should not have else block");
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_if_else_statement() {
        // DECY-029 RED PHASE: Test that if-else statements are parsed
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int max(int a, int b) { if (a > b) { return a; } else { return b; } }";

        let ast = parser.parse(source).expect("Parsing if-else statement should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one if-else statement");

        match &func.body[0] {
            Statement::If { condition, then_block, else_block } => {
                // Condition already tested above
                assert!(matches!(condition, Expression::BinaryOp { .. }), "Should have comparison");

                // Then block
                assert_eq!(then_block.len(), 1);

                // Else block
                assert!(else_block.is_some(), "Should have else block");
                let else_stmts = else_block.as_ref().unwrap();
                assert_eq!(else_stmts.len(), 1, "Else block should have one statement");
                match &else_stmts[0] {
                    Statement::Return(Some(Expression::Variable(ref name))) => {
                        assert_eq!(name, "b");
                    }
                    _ => panic!("Expected return statement in else block"),
                }
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_for_loop() {
        // DECY-029 RED PHASE: Test that for loops are parsed
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int sum(int n) { int s = 0; for (int i = 0; i < n; i = i + 1) { s = s + i; } return s; }";

        let ast = parser.parse(source).expect("Parsing for loop should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "sum");
        assert_eq!(func.body.len(), 3, "Should have var decl, for loop, return");

        // Second statement: for loop
        match &func.body[1] {
            Statement::For { init, condition, increment, body } => {
                // Check init: int i = 0
                assert!(!init.is_empty(), "Should have init statement");
                match &init[0] {
                    Statement::VariableDeclaration { name, var_type, initializer } => {
                        assert_eq!(name, "i");
                        assert_eq!(*var_type, Type::Int);
                        assert!(initializer.is_some());
                    }
                    _ => panic!("Expected variable declaration in init"),
                }

                // Check condition: i < n
                assert!(condition.is_some(), "Should have condition");
                match condition.as_ref().unwrap() {
                    Expression::BinaryOp { op, .. } => {
                        assert_eq!(*op, BinaryOperator::LessThan);
                    }
                    _ => panic!("Expected binary expression for condition"),
                }

                // Check increment: i = i + 1
                assert!(!increment.is_empty(), "Should have increment");

                // Check body: s = s + i
                assert_eq!(body.len(), 1, "Loop body should have one statement");
                match &body[0] {
                    Statement::Assignment { target, .. } => {
                        assert_eq!(target, "s");
                    }
                    _ => panic!("Expected assignment in loop body"),
                }
            }
            _ => panic!("Expected For statement"),
        }
    }

    #[test]
    fn test_parse_nested_if() {
        // DECY-029 RED PHASE: Test nested if statements
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"
            int classify(int x) {
                if (x > 0) {
                    if (x > 10) {
                        return 2;
                    }
                    return 1;
                }
                return 0;
            }
        "#;

        let ast = parser.parse(source).expect("Parsing nested if should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "classify");
        // Should have: if (outer), return
        assert!(func.body.len() >= 2, "Should have at least outer if and final return");

        // Outer if statement
        match &func.body[0] {
            Statement::If { then_block, else_block, .. } => {
                // Then block should have nested if
                assert!(then_block.len() >= 2, "Should have nested if and return in then block");
                match &then_block[0] {
                    Statement::If { .. } => {
                        // Nested if found
                    }
                    _ => panic!("Expected nested If statement"),
                }
                assert!(else_block.is_none(), "Outer if should not have else");
            }
            _ => panic!("Expected outer If statement"),
        }
    }

    #[test]
    fn test_parse_while_loop_with_body() {
        // DECY-029: Verify while loops parse correctly with actual body
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int countdown(int n) { while (n > 0) { n = n - 1; } return n; }";

        let ast = parser.parse(source).expect("Parsing while loop should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "countdown");
        assert_eq!(func.body.len(), 2, "Should have while loop and return");

        // While statement
        match &func.body[0] {
            Statement::While { condition, body } => {
                // Check condition: n > 0
                match condition {
                    Expression::BinaryOp { op, .. } => {
                        assert_eq!(*op, BinaryOperator::GreaterThan);
                    }
                    _ => panic!("Expected comparison in while condition"),
                }

                // Check body
                assert_eq!(body.len(), 1, "While body should have one statement");
                match &body[0] {
                    Statement::Assignment { target, .. } => {
                        assert_eq!(target, "n");
                    }
                    _ => panic!("Expected assignment in while body"),
                }
            }
            _ => panic!("Expected While statement"),
        }
    }

    #[test]
    fn test_parse_pointer_dereference_in_return() {
        // DECY-031 RED PHASE: Test that pointer dereference is parsed
        // This test will FAIL because Expression doesn't have Dereference variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int get_value(int* ptr) { return *ptr; }";

        let ast = parser.parse(source).expect("Parsing pointer dereference should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_value");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has dereference expression
        match &func.body[0] {
            Statement::Return(Some(Expression::Dereference(expr))) => {
                // Inner expression should be variable 'ptr'
                match **expr {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "ptr", "Dereferenced variable should be 'ptr'");
                    }
                    _ => panic!("Dereference should contain a variable"),
                }
            }
            _ => panic!("Expected Return statement with Dereference expression"),
        }
    }

    #[test]
    fn test_parse_pointer_dereference_in_condition() {
        // DECY-031 RED PHASE: Test pointer dereference in if condition
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int check(int* ptr) { if (*ptr != 0) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing dereference in condition should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "check");

        // First statement should be if with dereference in condition
        match &func.body[0] {
            Statement::If { condition, .. } => {
                match condition {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(*op, BinaryOperator::NotEqual);

                        // Left side should be dereference
                        match **left {
                            Expression::Dereference(ref inner) => match **inner {
                                Expression::Variable(ref name) => {
                                    assert_eq!(name, "ptr");
                                }
                                _ => panic!("Dereference should contain variable"),
                            },
                            _ => panic!("Left operand should be dereference expression"),
                        }

                        // Right side should be literal 0
                        match **right {
                            Expression::IntLiteral(val) => {
                                assert_eq!(val, 0);
                            }
                            _ => panic!("Right operand should be literal 0"),
                        }
                    }
                    _ => panic!("Expected binary expression in condition"),
                }
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_pointer_dereference_in_assignment() {
        // DECY-031 RED PHASE: Test pointer dereference in assignment value
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void copy(int* src, int* dst) { int x; x = *src; *dst = x; }";

        let ast = parser.parse(source).expect("Parsing dereference in assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "copy");
        assert_eq!(func.body.len(), 3, "Should have var decl and two assignments");

        // Second statement: x = *src
        match &func.body[1] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "x");
                match value {
                    Expression::Dereference(inner) => match **inner {
                        Expression::Variable(ref name) => {
                            assert_eq!(name, "src");
                        }
                        _ => panic!("Dereference should contain variable 'src'"),
                    },
                    _ => panic!("Assignment value should be dereference"),
                }
            }
            _ => panic!("Expected assignment statement"),
        }

        // Third statement: *dst = x (dereference as target)
        match &func.body[2] {
            Statement::DerefAssignment { target, value } => {
                match target {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "dst");
                    }
                    _ => panic!("Deref assignment target should be variable"),
                }
                match value {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "x");
                    }
                    _ => panic!("Assignment value should be variable"),
                }
            }
            _ => panic!("Expected DerefAssignment statement for *dst = x"),
        }
    }

    #[test]
    fn test_parse_logical_and() {
        // DECY-032 RED PHASE: Test that logical AND (&&) is parsed
        // This test will FAIL because BinaryOperator doesn't have LogicalAnd variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int check_both(int a, int b) { if (a > 0 && b > 0) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing logical AND should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "check_both");

        // First statement should be if with logical AND
        match &func.body[0] {
            Statement::If { condition, .. } => {
                match condition {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(
                            *op,
                            BinaryOperator::LogicalAnd,
                            "Operator should be LogicalAnd (&&)"
                        );

                        // Left: a > 0
                        match **left {
                            Expression::BinaryOp { op: ref left_op, .. } => {
                                assert_eq!(*left_op, BinaryOperator::GreaterThan);
                            }
                            _ => panic!("Left should be comparison expression"),
                        }

                        // Right: b > 0
                        match **right {
                            Expression::BinaryOp { op: ref right_op, .. } => {
                                assert_eq!(*right_op, BinaryOperator::GreaterThan);
                            }
                            _ => panic!("Right should be comparison expression"),
                        }
                    }
                    _ => panic!("Expected binary expression with LogicalAnd"),
                }
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_logical_or() {
        // DECY-032 RED PHASE: Test that logical OR (||) is parsed
        // This test will FAIL because BinaryOperator doesn't have LogicalOr variant
        let parser = CParser::new().expect("Parser creation failed");
        let source =
            "int check_either(int a, int b) { if (a > 0 || b > 0) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing logical OR should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "check_either");

        // First statement should be if with logical OR
        match &func.body[0] {
            Statement::If { condition, .. } => {
                match condition {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(
                            *op,
                            BinaryOperator::LogicalOr,
                            "Operator should be LogicalOr (||)"
                        );

                        // Left: a > 0
                        match **left {
                            Expression::BinaryOp { op: ref left_op, .. } => {
                                assert_eq!(*left_op, BinaryOperator::GreaterThan);
                            }
                            _ => panic!("Left should be comparison expression"),
                        }

                        // Right: b > 0
                        match **right {
                            Expression::BinaryOp { op: ref right_op, .. } => {
                                assert_eq!(*right_op, BinaryOperator::GreaterThan);
                            }
                            _ => panic!("Right should be comparison expression"),
                        }
                    }
                    _ => panic!("Expected binary expression with LogicalOr"),
                }
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_combined_logical_ops() {
        // DECY-032 RED PHASE: Test combined AND/OR operators
        let parser = CParser::new().expect("Parser creation failed");
        let source =
            "int check_range(int x) { if (x > 0 && x < 100 || x == 5) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing combined logical ops should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "check_range");

        // Verify that logical operators are parsed (structure will depend on precedence)
        match &func.body[0] {
            Statement::If { condition, .. } => {
                // Should have LogicalOr at the top level (lower precedence)
                match condition {
                    Expression::BinaryOp { op, .. } => {
                        assert!(
                            *op == BinaryOperator::LogicalOr || *op == BinaryOperator::LogicalAnd,
                            "Should have logical operator at top level"
                        );
                    }
                    _ => panic!("Expected binary expression with logical operator"),
                }
            }
            _ => panic!("Expected If statement"),
        }
    }

    #[test]
    fn test_parse_array_index_in_expression() {
        // DECY-033 RED PHASE: Test that array indexing is parsed
        // This test will FAIL because Expression doesn't have ArrayIndex variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int get_element(int arr[], int i) { return arr[i]; }";

        let ast = parser.parse(source).expect("Parsing array indexing should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_element");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has array index expression
        match &func.body[0] {
            Statement::Return(Some(Expression::ArrayIndex { array, index })) => {
                // Array should be variable 'arr'
                match **array {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "arr", "Array should be 'arr'");
                    }
                    _ => panic!("Array should be a variable"),
                }

                // Index should be variable 'i'
                match **index {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "i", "Index should be 'i'");
                    }
                    _ => panic!("Index should be a variable"),
                }
            }
            _ => panic!("Expected Return statement with ArrayIndex expression"),
        }
    }

    #[test]
    fn test_parse_array_index_assignment() {
        // DECY-033 RED PHASE: Test array index in assignment
        // buffer[i] = value should parse as ArrayIndexAssignment
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void set_element(int buffer[], int i, int value) { buffer[i] = value; }";

        let ast = parser.parse(source).expect("Parsing array index assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "set_element");
        assert_eq!(func.body.len(), 1, "Should have one assignment statement");

        // Verify assignment to array index
        match &func.body[0] {
            Statement::ArrayIndexAssignment { array, index, value } => {
                // Array should be variable 'buffer'
                match **array {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "buffer");
                    }
                    _ => panic!("Array should be a variable"),
                }

                // Index should be variable 'i'
                match **index {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "i");
                    }
                    _ => panic!("Index should be a variable"),
                }

                // Value should be variable 'value'
                match value {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "value");
                    }
                    _ => panic!("Value should be a variable"),
                }
            }
            _ => panic!("Expected ArrayIndexAssignment statement"),
        }
    }

    #[test]
    fn test_parse_array_index_in_binary_expr() {
        // DECY-033 RED PHASE: Test array index in binary expression
        // total = total + arr[i] should parse with ArrayIndex in right operand
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int sum(int arr[], int n) { int total = 0; for (int i = 0; i < n; i = i + 1) { total = total + arr[i]; } return total; }";

        let ast =
            parser.parse(source).expect("Parsing array index in binary expression should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "sum");

        // Should have: var decl, for loop, return
        assert_eq!(func.body.len(), 3);

        // Check for loop body has assignment with array index
        match &func.body[1] {
            Statement::For { body, .. } => {
                assert_eq!(body.len(), 1, "For loop body should have one statement");

                // Body should be: total = total + arr[i]
                match &body[0] {
                    Statement::Assignment { target, value } => {
                        assert_eq!(target, "total");

                        // Value should be binary expression with arr[i] on right
                        match value {
                            Expression::BinaryOp { op, right, .. } => {
                                assert_eq!(*op, BinaryOperator::Add);

                                // Right operand should be ArrayIndex
                                match **right {
                                    Expression::ArrayIndex { ref array, ref index } => {
                                        match **array {
                                            Expression::Variable(ref name) => {
                                                assert_eq!(name, "arr")
                                            }
                                            _ => panic!("Array should be variable"),
                                        }
                                        match **index {
                                            Expression::Variable(ref name) => assert_eq!(name, "i"),
                                            _ => panic!("Index should be variable"),
                                        }
                                    }
                                    _ => panic!("Right operand should be ArrayIndex"),
                                }
                            }
                            _ => panic!("Value should be BinaryOp"),
                        }
                    }
                    _ => panic!("Expected Assignment in loop body"),
                }
            }
            _ => panic!("Expected For statement"),
        }
    }

    #[test]
    fn test_parse_pointer_field_access() {
        // DECY-034 RED PHASE: Test that pointer field access (ptr->field) is parsed
        // This test will FAIL because Expression doesn't have PointerFieldAccess variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; int get_x(struct Point* p) { return p->x; }";

        let ast = parser.parse(source).expect("Parsing pointer field access should succeed");

        // Second function (index 1) because struct declaration is parsed too
        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_x");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has pointer field access expression
        match &func.body[0] {
            Statement::Return(Some(Expression::PointerFieldAccess { pointer, field })) => {
                // Pointer should be variable 'p'
                match **pointer {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "p", "Pointer should be 'p'");
                    }
                    _ => panic!("Pointer should be a variable"),
                }

                // Field should be 'x'
                assert_eq!(field, "x", "Field should be 'x'");
            }
            _ => panic!("Expected Return statement with PointerFieldAccess expression"),
        }
    }

    #[test]
    fn test_parse_field_access() {
        // DECY-034 RED PHASE: Test that struct field access (obj.field) is parsed
        // This test will FAIL because Expression doesn't have FieldAccess variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; int get_x(struct Point p) { return p.x; }";

        let ast = parser.parse(source).expect("Parsing field access should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_x");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has field access expression
        match &func.body[0] {
            Statement::Return(Some(Expression::FieldAccess { object, field })) => {
                // Object should be variable 'p'
                match **object {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "p", "Object should be 'p'");
                    }
                    _ => panic!("Object should be a variable"),
                }

                // Field should be 'x'
                assert_eq!(field, "x", "Field should be 'x'");
            }
            _ => panic!("Expected Return statement with FieldAccess expression"),
        }
    }

    #[test]
    fn test_parse_pointer_field_access_assignment() {
        // DECY-034 RED PHASE: Test ptr->field = value assignment
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; void set_y(struct Point* p, int value) { p->y = value; }";

        let ast =
            parser.parse(source).expect("Parsing pointer field access assignment should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "set_y");
        assert_eq!(func.body.len(), 1, "Should have one assignment statement");

        // Verify assignment with field access on left side
        // This should parse as a FieldAssignment statement
        match &func.body[0] {
            Statement::FieldAssignment { object, field, value } => {
                // Object should be pointer field access or variable 'p'
                match object {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "p", "Object should be 'p'");
                    }
                    _ => panic!("Object should be a variable"),
                }

                // Field should be 'y'
                assert_eq!(field, "y", "Field should be 'y'");

                // Value should be variable 'value'
                match value {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "value");
                    }
                    _ => panic!("Value should be a variable"),
                }
            }
            _ => panic!("Expected FieldAssignment statement"),
        }
    }

    #[test]
    fn test_parse_unary_minus() {
        // DECY-035 RED PHASE: Test that unary minus (-x) is parsed
        // This test will FAIL because UnaryOp expression variant doesn't support minus
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int negate(int x) { return -x; }";

        let ast = parser.parse(source).expect("Parsing unary minus should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "negate");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has unary minus expression
        match &func.body[0] {
            Statement::Return(Some(Expression::UnaryOp { op, operand })) => {
                assert_eq!(*op, UnaryOperator::Minus, "Operator should be minus");

                // Operand should be variable 'x'
                match **operand {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "x", "Operand should be 'x'");
                    }
                    _ => panic!("Operand should be a variable"),
                }
            }
            _ => panic!("Expected Return statement with UnaryOp expression"),
        }
    }

    #[test]
    fn test_parse_logical_not() {
        // DECY-035 RED PHASE: Test that logical NOT (!x) is parsed
        // This test will FAIL because UnaryOp expression variant doesn't support not
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int logical_not(int x) { return !x; }";

        let ast = parser.parse(source).expect("Parsing logical NOT should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "logical_not");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has logical NOT expression
        match &func.body[0] {
            Statement::Return(Some(Expression::UnaryOp { op, operand })) => {
                assert_eq!(*op, UnaryOperator::LogicalNot, "Operator should be logical NOT");

                // Operand should be variable 'x'
                match **operand {
                    Expression::Variable(ref name) => {
                        assert_eq!(name, "x", "Operand should be 'x'");
                    }
                    _ => panic!("Operand should be a variable"),
                }
            }
            _ => panic!("Expected Return statement with UnaryOp expression"),
        }
    }

    #[test]
    fn test_parse_double_negative() {
        // DECY-035 RED PHASE: Test nested unary operators (-(-x))
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int double_negative(int x) { return -(-x); }";

        let ast = parser.parse(source).expect("Parsing double negative should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "double_negative");

        // Verify nested unary operators
        match &func.body[0] {
            Statement::Return(Some(Expression::UnaryOp {
                op: outer_op,
                operand: outer_operand,
            })) => {
                assert_eq!(*outer_op, UnaryOperator::Minus, "Outer operator should be minus");

                // Inner should also be UnaryOp with minus
                match **outer_operand {
                    Expression::UnaryOp { ref op, ref operand } => {
                        assert_eq!(*op, UnaryOperator::Minus, "Inner operator should be minus");
                        match **operand {
                            Expression::Variable(ref name) => {
                                assert_eq!(name, "x", "Innermost operand should be 'x'");
                            }
                            _ => panic!("Innermost operand should be a variable"),
                        }
                    }
                    _ => panic!("Inner expression should be UnaryOp"),
                }
            }
            _ => panic!("Expected Return statement with UnaryOp expression"),
        }
    }

    #[test]
    fn test_parse_function_call_with_variable_args() {
        // DECY-036 RED PHASE: Test function call with variable arguments
        // This test will FAIL because visit_call_argument only handles IntLiteral
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int add(int a, int b) { return a + b; } int compute(int x) { int result = add(x, 10); return result; }";

        let ast =
            parser.parse(source).expect("Parsing function call with variable args should succeed");

        // Should have two functions
        assert_eq!(ast.functions().len(), 2);
        let compute_func = &ast.functions()[1];
        assert_eq!(compute_func.name, "compute");

        // First statement: int result = add(x, 10);
        match &compute_func.body[0] {
            Statement::VariableDeclaration { name, initializer, .. } => {
                assert_eq!(name, "result");
                match initializer {
                    Some(Expression::FunctionCall { function, arguments }) => {
                        assert_eq!(function, "add");
                        assert_eq!(arguments.len(), 2, "add() should have 2 arguments");

                        // First argument should be variable 'x'
                        match &arguments[0] {
                            Expression::Variable(ref name) => {
                                assert_eq!(name, "x", "First argument should be variable 'x'");
                            }
                            _ => panic!("First argument should be a variable"),
                        }

                        // Second argument should be literal 10
                        match &arguments[1] {
                            Expression::IntLiteral(val) => {
                                assert_eq!(*val, 10, "Second argument should be 10");
                            }
                            _ => panic!("Second argument should be IntLiteral(10)"),
                        }
                    }
                    _ => panic!("Initializer should be a function call"),
                }
            }
            _ => panic!("Expected VariableDeclaration statement"),
        }
    }

    #[test]
    fn test_parse_nested_function_calls() {
        // DECY-036 RED PHASE: Test nested function calls
        // This test will FAIL because nested calls are flattened
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int add(int a, int b) { return a + b; } int nested(int x) { return add(add(x, 5), add(10, 20)); }";

        let ast = parser.parse(source).expect("Parsing nested function calls should succeed");

        assert_eq!(ast.functions().len(), 2);
        let nested_func = &ast.functions()[1];
        assert_eq!(nested_func.name, "nested");

        // Return statement: return add(add(x, 5), add(10, 20));
        match &nested_func.body[0] {
            Statement::Return(Some(Expression::FunctionCall { function, arguments })) => {
                assert_eq!(function, "add");
                assert_eq!(arguments.len(), 2, "Outer add() should have 2 arguments");

                // First argument should be nested function call: add(x, 5)
                match &arguments[0] {
                    Expression::FunctionCall { function: inner_fn, arguments: inner_args } => {
                        assert_eq!(inner_fn, "add");
                        assert_eq!(inner_args.len(), 2);
                        match &inner_args[0] {
                            Expression::Variable(ref name) => assert_eq!(name, "x"),
                            _ => panic!("First arg of inner call should be variable 'x'"),
                        }
                        match &inner_args[1] {
                            Expression::IntLiteral(val) => assert_eq!(*val, 5),
                            _ => panic!("Second arg of inner call should be 5"),
                        }
                    }
                    _ => panic!("First argument should be a function call"),
                }

                // Second argument should be nested function call: add(10, 20)
                match &arguments[1] {
                    Expression::FunctionCall { function: inner_fn, arguments: inner_args } => {
                        assert_eq!(inner_fn, "add");
                        assert_eq!(inner_args.len(), 2);
                        match &inner_args[0] {
                            Expression::IntLiteral(val) => assert_eq!(*val, 10),
                            _ => panic!("First arg of inner call should be 10"),
                        }
                        match &inner_args[1] {
                            Expression::IntLiteral(val) => assert_eq!(*val, 20),
                            _ => panic!("Second arg of inner call should be 20"),
                        }
                    }
                    _ => panic!("Second argument should be a function call"),
                }
            }
            _ => panic!("Expected Return statement with function call"),
        }
    }

    #[test]
    fn test_parse_function_call_with_expression_args() {
        // DECY-036 RED PHASE: Test function call with expression arguments
        // This test will FAIL because expressions are not properly extracted
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int add(int a, int b) { return a + b; } int compute(int x, int y) { return add(x + 1, y * 2); }";

        let ast = parser
            .parse(source)
            .expect("Parsing function call with expression args should succeed");

        assert_eq!(ast.functions().len(), 2);
        let compute_func = &ast.functions()[1];
        assert_eq!(compute_func.name, "compute");

        // Return statement: return add(x + 1, y * 2);
        match &compute_func.body[0] {
            Statement::Return(Some(Expression::FunctionCall { function, arguments })) => {
                assert_eq!(function, "add");
                assert_eq!(arguments.len(), 2, "add() should have 2 arguments");

                // First argument should be binary expression: x + 1
                match &arguments[0] {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(*op, BinaryOperator::Add);
                        match **left {
                            Expression::Variable(ref name) => assert_eq!(name, "x"),
                            _ => panic!("Left operand should be variable 'x'"),
                        }
                        match **right {
                            Expression::IntLiteral(val) => assert_eq!(val, 1),
                            _ => panic!("Right operand should be literal 1"),
                        }
                    }
                    _ => panic!("First argument should be a binary expression"),
                }

                // Second argument should be binary expression: y * 2
                match &arguments[1] {
                    Expression::BinaryOp { op, left, right } => {
                        assert_eq!(*op, BinaryOperator::Multiply);
                        match **left {
                            Expression::Variable(ref name) => assert_eq!(name, "y"),
                            _ => panic!("Left operand should be variable 'y'"),
                        }
                        match **right {
                            Expression::IntLiteral(val) => assert_eq!(val, 2),
                            _ => panic!("Right operand should be literal 2"),
                        }
                    }
                    _ => panic!("Second argument should be a binary expression"),
                }
            }
            _ => panic!("Expected Return statement with function call"),
        }
    }

    #[test]
    fn test_parse_struct_value_parameter() {
        // DECY-037 RED PHASE: Test that struct value parameters are parsed
        // This test will FAIL because Type enum doesn't have Struct variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; void print_point(struct Point p) { }";

        let ast = parser.parse(source).expect("Parsing struct value parameter should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "print_point");
        assert_eq!(func.parameters.len(), 1, "Should have one parameter");

        // Parameter should be struct type
        match &func.parameters[0].param_type {
            Type::Struct(name) => {
                assert_eq!(name, "Point", "Struct name should be 'Point'");
            }
            _ => {
                panic!("Parameter should be a struct type, got {:?}", func.parameters[0].param_type)
            }
        }
    }

    #[test]
    fn test_parse_struct_pointer_parameter() {
        // DECY-037 RED PHASE: Test that struct pointer parameters are parsed
        // This test will FAIL because Type::Pointer doesn't handle inner struct types
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; void update_point(struct Point* p) { }";

        let ast = parser.parse(source).expect("Parsing struct pointer parameter should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "update_point");
        assert_eq!(func.parameters.len(), 1, "Should have one parameter");

        // Parameter should be pointer to struct
        match &func.parameters[0].param_type {
            Type::Pointer(inner) => match **inner {
                Type::Struct(ref name) => {
                    assert_eq!(name, "Point", "Struct name should be 'Point'");
                }
                _ => panic!("Pointer should point to struct type"),
            },
            _ => panic!("Parameter should be a pointer type"),
        }
    }

    #[test]
    fn test_parse_struct_return_type() {
        // DECY-037 RED PHASE: Test that struct return types are parsed
        // This test will FAIL because Type enum doesn't handle structs
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; struct Point create_point(int x, int y) { struct Point p; return p; }";

        let ast = parser.parse(source).expect("Parsing struct return type should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "create_point");

        // Return type should be struct
        match &func.return_type {
            Type::Struct(name) => {
                assert_eq!(name, "Point", "Struct name should be 'Point'");
            }
            _ => panic!("Return type should be a struct, got {:?}", func.return_type),
        }
    }

    #[test]
    fn test_parse_simple_typedef() {
        // DECY-023 RED PHASE: Test that simple typedefs are parsed
        // This test will FAIL because AST doesn't have typedefs yet
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int Integer; int test(Integer x) { return x; }";

        let ast = parser.parse(source).expect("Parsing simple typedef should succeed");

        // Should have one typedef and one function
        assert!(!ast.typedefs().is_empty(), "Should have at least one typedef");
        let typedef = &ast.typedefs()[0];
        assert_eq!(typedef.name, "Integer", "Typedef name should be 'Integer'");
        assert_eq!(typedef.underlying_type, Type::Int, "Underlying type should be int");

        // Function should use the typedef'd type
        assert_eq!(ast.functions().len(), 1, "Should have one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        assert_eq!(func.parameters.len(), 1);
        // Note: The parameter type will be resolved to Int by clang, not kept as "Integer"
    }

    #[test]
    fn test_parse_struct_typedef() {
        // DECY-023 RED PHASE: Test typedef of struct
        // This test will FAIL because AST doesn't have typedefs
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; typedef struct Point Point;";

        let ast = parser.parse(source).expect("Parsing struct typedef should succeed");

        assert!(!ast.typedefs().is_empty(), "Should have at least one typedef");
        let typedef = &ast.typedefs()[0];
        assert_eq!(typedef.name, "Point", "Typedef name should be 'Point'");
        match &typedef.underlying_type {
            Type::Struct(name) => {
                assert_eq!(name, "Point", "Underlying type should be struct Point");
            }
            _ => panic!("Typedef should reference struct type"),
        }
    }

    #[test]
    fn test_parse_pointer_typedef() {
        // DECY-023 RED PHASE: Test typedef of pointer type
        // This test will FAIL because AST doesn't have typedefs
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int* IntPtr; void process(IntPtr p) { }";

        let ast = parser.parse(source).expect("Parsing pointer typedef should succeed");

        assert!(!ast.typedefs().is_empty(), "Should have at least one typedef");
        let typedef = &ast.typedefs()[0];
        assert_eq!(typedef.name, "IntPtr", "Typedef name should be 'IntPtr'");
        match &typedef.underlying_type {
            Type::Pointer(inner) => {
                assert_eq!(**inner, Type::Int, "Should be pointer to int");
            }
            _ => panic!("Typedef should be pointer type"),
        }
    }

    #[test]
    fn test_parse_function_pointer_typedef() {
        // DECY-024 RED PHASE: Test that function pointer typedefs are parsed
        // This test will FAIL because Type enum doesn't have FunctionPointer variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int (*Callback)(int x);";

        let ast = parser.parse(source).expect("Parsing function pointer typedef should succeed");

        // Should have one typedef
        assert!(!ast.typedefs().is_empty(), "Should have at least one typedef");
        let typedef = &ast.typedefs()[0];
        assert_eq!(typedef.name, "Callback", "Typedef name should be 'Callback'");

        // Underlying type should be function pointer
        match &typedef.underlying_type {
            Type::FunctionPointer { param_types, return_type } => {
                assert_eq!(param_types.len(), 1, "Should have one parameter");
                assert_eq!(param_types[0], Type::Int, "Parameter should be int");
                assert_eq!(**return_type, Type::Int, "Return type should be int");
            }
            _ => {
                panic!("Typedef should be function pointer type, got {:?}", typedef.underlying_type)
            }
        }
    }

    #[test]
    fn test_parse_function_pointer_parameter() {
        // DECY-024 RED PHASE: Test function with function pointer parameter
        // This test will FAIL because Type enum doesn't have FunctionPointer variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int (*Callback)(int x); void register_callback(Callback cb) { }";

        let ast = parser.parse(source).expect("Parsing function pointer parameter should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "register_callback");
        assert_eq!(func.parameters.len(), 1, "Should have one parameter");
        assert_eq!(func.parameters[0].name, "cb", "Parameter name should be 'cb'");

        // Parameter type should be function pointer (resolved from typedef)
        // Note: clang will resolve the typedef to the underlying function pointer type
        match &func.parameters[0].param_type {
            Type::FunctionPointer { param_types, return_type } => {
                assert_eq!(param_types.len(), 1, "Should have one parameter");
                assert_eq!(param_types[0], Type::Int, "Parameter should be int");
                assert_eq!(**return_type, Type::Int, "Return type should be int");
            }
            _ => panic!(
                "Parameter should be function pointer type, got {:?}",
                func.parameters[0].param_type
            ),
        }
    }

    #[test]
    fn test_parse_function_pointer_return_type() {
        // DECY-024 RED PHASE: Test function returning function pointer
        // This test will FAIL because Type enum doesn't have FunctionPointer variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int (*Callback)(int x); Callback get_callback() { return 0; }";

        let ast =
            parser.parse(source).expect("Parsing function pointer return type should succeed");

        assert!(!ast.functions().is_empty(), "Should have at least one function");
        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_callback");

        // Return type should be function pointer (resolved from typedef)
        match &func.return_type {
            Type::FunctionPointer { param_types, return_type } => {
                assert_eq!(param_types.len(), 1, "Should have one parameter");
                assert_eq!(param_types[0], Type::Int, "Parameter should be int");
                assert_eq!(**return_type, Type::Int, "Return type should be int");
            }
            _ => panic!("Return type should be function pointer, got {:?}", func.return_type),
        }
    }

    #[test]
    fn test_parse_string_literal_in_return() {
        // DECY-025 RED PHASE: Test that string literals are parsed
        // This test will FAIL because Expression doesn't have StringLiteral variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"const char* get_message() { return "Hello"; }"#;

        let ast = parser.parse(source).expect("Parsing string literal should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_message");
        assert_eq!(func.body.len(), 1, "Should have one return statement");

        // Verify return statement has string literal
        match &func.body[0] {
            Statement::Return(Some(Expression::StringLiteral(value))) => {
                assert_eq!(value, "Hello", "String should be 'Hello'");
            }
            _ => panic!("Expected Return statement with StringLiteral"),
        }
    }

    #[test]
    fn test_parse_string_literal_in_variable() {
        // DECY-025 RED PHASE: Test string literal in variable declaration
        // This test will FAIL because Expression doesn't have StringLiteral variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"void test() { char* msg = "World"; }"#;

        let ast = parser.parse(source).expect("Parsing string in variable should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        assert_eq!(func.body.len(), 1, "Should have one declaration");

        // Verify variable declaration has string literal initializer
        match &func.body[0] {
            Statement::VariableDeclaration { name, initializer, .. } => {
                assert_eq!(name, "msg");
                match initializer {
                    Some(Expression::StringLiteral(value)) => {
                        assert_eq!(value, "World", "String should be 'World'");
                    }
                    _ => panic!("Expected StringLiteral initializer"),
                }
            }
            _ => panic!("Expected VariableDeclaration"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_parse_string_literal_in_function_call() {
        // DECY-025 GREEN PHASE: Test string literal as function argument
        // Test with function call in a variable declaration (which IS supported)
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"int strlen(const char*); void test() { int result = strlen("Test"); }"#;

        let ast = parser.parse(source).expect("Parsing string in function call should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        assert_eq!(func.body.len(), 1, "Should have one statement");

        // Verify function call has string literal argument
        match &func.body[0] {
            Statement::VariableDeclaration { name, initializer, .. } => {
                assert_eq!(name, "result");
                match initializer {
                    Some(Expression::FunctionCall { function, arguments }) => {
                        assert_eq!(function, "strlen");
                        assert_eq!(arguments.len(), 1, "Should have one argument");
                        match &arguments[0] {
                            Expression::StringLiteral(value) => {
                                assert_eq!(value, "Test", "String should be 'Test'");
                            }
                            _ => panic!("Expected StringLiteral argument"),
                        }
                    }
                    _ => panic!("Expected FunctionCall initializer"),
                }
            }
            _ => panic!("Expected VariableDeclaration statement"),
        }
    }

    // ============================================================================
    // MUTATION TESTING HARDENING: Visitor Match Arm Coverage Tests
    // These tests target uncovered wildcard branches and edge cases
    // Found by mutation testing analysis (69.5% → 85%+ target)
    // ============================================================================

    #[test]
    fn test_visitor_unknown_statement_cursor() {
        // Test that unknown statement cursor types are handled gracefully
        // Targets visit_statement wildcard arm (parser.rs:332)
        let parser = CParser::new().expect("Parser creation failed");
        // Use C code with break statement (not yet supported, should be skipped)
        let source = "void test() { for(int i = 0; i < 10; i++) { break; } }";

        let ast =
            parser.parse(source).expect("Parsing with unsupported statement should still succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        // Should parse the for loop, but break statement may be skipped
        assert!(!func.body.is_empty(), "Should have at least the for loop");
    }

    #[test]
    fn test_visitor_unknown_expression_cursor() {
        // Test that unknown expression cursor types are handled gracefully
        // Targets visit_expression wildcard arm (parser.rs:624)
        let parser = CParser::new().expect("Parser creation failed");
        // Use complex cast expression that might not be fully supported
        let source = "int test(void* ptr) { return (int)(long)ptr; }";

        let ast = parser.parse(source).expect("Parsing with complex cast should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        // Function should parse even if some expressions are not fully captured
        assert_eq!(func.body.len(), 1, "Should have return statement");
    }

    #[test]
    fn test_visitor_unknown_binary_operand() {
        // Test that unknown binary operand cursor types trigger recursion
        // Targets visit_binary_operand wildcard arm (parser.rs:816)
        let parser = CParser::new().expect("Parser creation failed");
        // Use sizeof operator in binary expression (might need recursion)
        let source = "int test() { return 5 + 10; }";

        let ast = parser
            .parse(source)
            .expect("Parsing binary expression with complex operand should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
                assert_eq!(*op, BinaryOperator::Add);
            }
            _ => panic!("Expected return with binary operation"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_visitor_unknown_call_argument() {
        // Test that unknown call argument cursor types are handled
        // Targets visit_call_argument wildcard arm (parser.rs:1047)
        let parser = CParser::new().expect("Parser creation failed");
        // Use complex expression as function argument
        let source = "int max(int, int); int test(int x) { int y = max(x, 100); return y; }";

        let ast =
            parser.parse(source).expect("Parsing function call with complex args should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "test");
        match &func.body[0] {
            Statement::VariableDeclaration { initializer, .. } => match initializer {
                Some(Expression::FunctionCall { arguments, .. }) => {
                    assert_eq!(arguments.len(), 2, "Should parse both arguments");
                }
                _ => panic!("Expected function call initializer"),
            },
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    fn test_extract_var_decl_returns_none() {
        // Test edge case where extract_var_decl might return None
        // Targets lines 67-95 in parser.rs (extract_var_decl)
        let parser = CParser::new().expect("Parser creation failed");
        // Declare variable with unknown type (should handle gracefully)
        let source = "void test() { int x; }";

        let ast = parser.parse(source).expect("Parsing simple var decl should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one variable declaration");
        match &func.body[0] {
            Statement::VariableDeclaration { name, var_type, initializer } => {
                assert_eq!(name, "x");
                assert_eq!(*var_type, Type::Int);
                assert!(initializer.is_none(), "Should have no initializer");
            }
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    fn test_extract_return_stmt_with_no_value() {
        // Test return statement with no expression
        // Targets lines 97-108 in parser.rs (extract_return_stmt)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test() { return; }";

        let ast = parser.parse(source).expect("Parsing return with no value should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one return statement");
        match &func.body[0] {
            Statement::Return(None) => {
                // Expected: return with no value
            }
            _ => panic!("Expected Return(None) statement"),
        }
    }

    #[test]
    fn test_extract_assignment_invalid_token() {
        // Test assignment extraction when tokenization might fail
        // Targets lines 110-233 in parser.rs (extract_assignment_stmt)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test() { int x = 5; x = 10; }";

        let ast = parser.parse(source).expect("Parsing assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 2, "Should have var decl and assignment");
        match &func.body[1] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "x");
                match value {
                    Expression::IntLiteral(val) => assert_eq!(*val, 10),
                    _ => panic!("Value should be 10"),
                }
            }
            _ => panic!("Expected assignment statement"),
        }
    }

    #[test]
    fn test_extract_binary_op_with_no_operator() {
        // Test binary operation when operator extraction might fail
        // Targets lines 734-757 in parser.rs (extract_binary_op)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { return a * b; }";

        let ast = parser.parse(source).expect("Parsing binary operation should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, left, right })) => {
                assert_eq!(*op, BinaryOperator::Multiply);
                match **left {
                    Expression::Variable(ref name) => assert_eq!(name, "a"),
                    _ => panic!("Left should be variable 'a'"),
                }
                match **right {
                    Expression::Variable(ref name) => assert_eq!(name, "b"),
                    _ => panic!("Right should be variable 'b'"),
                }
            }
            _ => panic!("Expected binary operation"),
        }
    }

    #[test]
    fn test_extract_binary_operator_division() {
        // Test division operator parsing
        // Targets BinaryOperator::Divide variant coverage
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { return a / b; }";

        let ast = parser.parse(source).expect("Parsing division should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
                assert_eq!(*op, BinaryOperator::Divide, "Should be division operator");
            }
            _ => panic!("Expected division operation"),
        }
    }

    #[test]
    fn test_extract_binary_operator_modulo() {
        // Test modulo operator parsing
        // Targets BinaryOperator::Modulo variant coverage
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { return a % b; }";

        let ast = parser.parse(source).expect("Parsing modulo should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
                assert_eq!(*op, BinaryOperator::Modulo, "Should be modulo operator");
            }
            _ => panic!("Expected modulo operation"),
        }
    }

    #[test]
    fn test_extract_binary_operator_subtract() {
        // Test subtraction operator parsing
        // Targets BinaryOperator::Subtract variant coverage
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { return a - b; }";

        let ast = parser.parse(source).expect("Parsing subtraction should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
                assert_eq!(*op, BinaryOperator::Subtract, "Should be subtraction operator");
            }
            _ => panic!("Expected subtraction operation"),
        }
    }

    #[test]
    fn test_extract_binary_operator_less_equal() {
        // Test less-than-or-equal operator parsing
        // Targets BinaryOperator::LessEqual variant coverage
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a <= b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing <= should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(*op, BinaryOperator::LessEqual, "Should be <= operator");
                }
                _ => panic!("Condition should be binary operation"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_extract_binary_operator_greater_equal() {
        // Test greater-than-or-equal operator parsing
        // Targets BinaryOperator::GreaterEqual variant coverage
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a >= b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing >= should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(*op, BinaryOperator::GreaterEqual, "Should be >= operator");
                }
                _ => panic!("Condition should be binary operation"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_extract_int_literal_null_tu() {
        // Test integer literal extraction with edge cases
        // Targets lines 629-677 in parser.rs (extract_int_literal)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test() { return 999; }";

        let ast = parser.parse(source).expect("Parsing integer literal should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::IntLiteral(val))) => {
                assert_eq!(*val, 999, "Should parse literal value 999");
            }
            _ => panic!("Expected integer literal"),
        }
    }

    #[test]
    fn test_extract_string_literal_empty() {
        // Test empty string literal parsing
        // Targets lines 679-718 in parser.rs (extract_string_literal)
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"const char* test() { return ""; }"#;

        let ast = parser.parse(source).expect("Parsing empty string should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(Expression::StringLiteral(val))) => {
                assert_eq!(val, "", "Should parse empty string");
            }
            _ => panic!("Expected string literal"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_extract_function_call_no_args() {
        // Test function call with no arguments
        // Targets lines 924-957 in parser.rs (extract_function_call)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int rand(void); void test() { int x = rand(); }";

        let ast = parser.parse(source).expect("Parsing function call with no args should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::VariableDeclaration { initializer, .. } => match initializer {
                Some(Expression::FunctionCall { function, arguments }) => {
                    assert_eq!(function, "rand");
                    assert_eq!(arguments.len(), 0, "Should have no arguments");
                }
                _ => panic!("Expected function call"),
            },
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    fn test_convert_type_elaborated() {
        // Test elaborated type conversion (struct keyword)
        // Targets lines 1313-1318 in parser.rs (convert_type with CXType_Elaborated)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; }; int test(struct Point p) { return p.x; }";

        let ast = parser.parse(source).expect("Parsing elaborated type should succeed");

        let func = &ast.functions()[0];
        match &func.parameters[0].param_type {
            Type::Struct(name) => {
                assert_eq!(name, "Point", "Should resolve elaborated type to struct");
            }
            _ => panic!("Expected struct type"),
        }
    }

    #[test]
    fn test_convert_type_typedef_canonical() {
        // Test typedef type conversion to canonical
        // Targets lines 1319-1324 in parser.rs (convert_type with CXType_Typedef)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "typedef int MyInt; MyInt test(MyInt x) { return x; }";

        let ast = parser.parse(source).expect("Parsing typedef should succeed");

        let func = &ast.functions()[0];
        // Clang resolves typedefs to canonical types
        assert_eq!(func.return_type, Type::Int, "Should resolve typedef to int");
        assert_eq!(func.parameters[0].param_type, Type::Int, "Should resolve typedef to int");
    }

    #[test]
    fn test_parse_comparison_not_equal() {
        // Test != operator parsing
        // Targets BinaryOperator::NotEqual variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a != b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing != should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(*op, BinaryOperator::NotEqual, "Should be != operator");
                }
                _ => panic!("Expected binary operation"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_parse_comparison_equal() {
        // Test == operator parsing
        // Targets BinaryOperator::Equal variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a == b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing == should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(*op, BinaryOperator::Equal, "Should be == operator");
                }
                _ => panic!("Expected binary operation"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_parse_comparison_less_than() {
        // Test < operator parsing explicitly
        // Targets BinaryOperator::LessThan variant
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a < b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing < should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(*op, BinaryOperator::LessThan, "Should be < operator");
                }
                _ => panic!("Expected binary operation"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    // ============================================================================
    // MUTATION TESTING HARDENING: Assignment Edge Case Tests
    // These tests target assignment statement edge cases and error paths
    // ============================================================================

    #[test]
    fn test_assignment_with_complex_rhs() {
        // Test assignment with complex right-hand side expression
        // Ensures extract_assignment_stmt handles nested expressions
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test() { int x = 0; x = 5 * 10; }";

        let ast = parser.parse(source).expect("Parsing assignment with complex RHS should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 2, "Should have var decl and assignment");
        match &func.body[1] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "x");
                // Value should be a binary operation
                match value {
                    Expression::BinaryOp { op, .. } => {
                        assert_eq!(*op, BinaryOperator::Multiply, "Should parse multiplication");
                    }
                    _ => panic!("Expected binary operation on RHS"),
                }
            }
            _ => panic!("Expected assignment statement"),
        }
    }

    #[test]
    fn test_assignment_distinguishes_equality() {
        // Test that == is NOT treated as assignment
        // Targets the operator detection logic in extract_assignment_stmt
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a == b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing == comparison should succeed");

        let func = &ast.functions()[0];
        // Should be an if statement, NOT an assignment
        match &func.body[0] {
            Statement::If { .. } => {
                // Expected: if statement with == comparison
            }
            Statement::Assignment { .. } => {
                panic!("== should not be parsed as assignment");
            }
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_assignment_distinguishes_not_equal() {
        // Test that != is NOT treated as assignment
        // Targets the operator detection logic in extract_assignment_stmt
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a != b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing != comparison should succeed");

        let func = &ast.functions()[0];
        // Should be an if statement, NOT an assignment
        match &func.body[0] {
            Statement::If { .. } => {
                // Expected: if statement with != comparison
            }
            Statement::Assignment { .. } => {
                panic!("!= should not be parsed as assignment");
            }
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_deref_assignment_edge_case() {
        // Test dereference assignment with complex target
        // Targets DerefAssignment statement creation
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test(int** pptr, int value) { *(*pptr) = value; }";

        let ast =
            parser.parse(source).expect("Parsing nested dereference assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one assignment");
        // Should parse as some form of assignment (exact structure may vary)
        match &func.body[0] {
            Statement::DerefAssignment { .. } | Statement::Assignment { .. } => {
                // Expected: some assignment variant
            }
            _ => panic!("Expected assignment statement"),
        }
    }

    #[test]
    fn test_array_index_assignment_with_expression() {
        // Test array index assignment with expression as index
        // Targets ArrayIndexAssignment with complex index
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test(int arr[], int i) { arr[i + 1] = 42; }";

        let ast = parser
            .parse(source)
            .expect("Parsing array assignment with expression index should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one assignment");
        match &func.body[0] {
            Statement::ArrayIndexAssignment { array, index, value } => {
                // Array should be 'arr'
                match **array {
                    Expression::Variable(ref name) => assert_eq!(name, "arr"),
                    _ => panic!("Array should be variable"),
                }
                // Index should be binary expression i + 1
                match **index {
                    Expression::BinaryOp { op, .. } => {
                        assert_eq!(op, BinaryOperator::Add, "Index should be i + 1");
                    }
                    _ => panic!("Index should be binary operation"),
                }
                // Value should be 42
                match value {
                    Expression::IntLiteral(val) => assert_eq!(*val, 42),
                    _ => panic!("Value should be 42"),
                }
            }
            _ => panic!("Expected ArrayIndexAssignment"),
        }
    }

    #[test]
    fn test_field_assignment_with_struct_value() {
        // Test field assignment with struct by value
        // Targets FieldAssignment for obj.field = value
        let parser = CParser::new().expect("Parser creation failed");
        let source = "struct Point { int x; int y; }; void test(struct Point p) { p.x = 100; }";

        let ast = parser.parse(source).expect("Parsing field assignment should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 1, "Should have one assignment");
        match &func.body[0] {
            Statement::FieldAssignment { object, field, value } => {
                // Object should be 'p'
                match object {
                    Expression::Variable(ref name) => assert_eq!(name, "p"),
                    _ => panic!("Object should be variable"),
                }
                // Field should be 'x'
                assert_eq!(field, "x");
                // Value should be 100
                match value {
                    Expression::IntLiteral(val) => assert_eq!(*val, 100),
                    _ => panic!("Value should be 100"),
                }
            }
            _ => panic!("Expected FieldAssignment"),
        }
    }

    #[test]
    fn test_assignment_chain() {
        // Test multiple assignments in sequence
        // Ensures each assignment is parsed independently
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void test() { int a = 0; int b = 0; a = 1; b = 2; a = b; }";

        let ast = parser.parse(source).expect("Parsing assignment chain should succeed");

        let func = &ast.functions()[0];
        assert_eq!(func.body.len(), 5, "Should have 2 var decls + 3 assignments");

        // Third statement: a = 1
        match &func.body[2] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "a");
                match value {
                    Expression::IntLiteral(val) => assert_eq!(*val, 1),
                    _ => panic!("Value should be 1"),
                }
            }
            _ => panic!("Expected assignment a = 1"),
        }

        // Fourth statement: b = 2
        match &func.body[3] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "b");
                match value {
                    Expression::IntLiteral(val) => assert_eq!(*val, 2),
                    _ => panic!("Value should be 2"),
                }
            }
            _ => panic!("Expected assignment b = 2"),
        }

        // Fifth statement: a = b
        match &func.body[4] {
            Statement::Assignment { target, value } => {
                assert_eq!(target, "a");
                match value {
                    Expression::Variable(ref name) => assert_eq!(name, "b"),
                    _ => panic!("Value should be variable b"),
                }
            }
            _ => panic!("Expected assignment a = b"),
        }
    }

    // ============================================================================
    // MUTATION TESTING: Final Push to 85%+ (Targeting Remaining 34 Mutants)
    // These tests target specific missed mutants from mutation testing
    // ============================================================================

    #[test]
    fn test_if_with_unary_in_condition() {
        // Targets: delete match arm CXCursor_UnaryOperator in visit_if_children (line 566)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int x) { if (-x > 0) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing if with unary in condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => {
                match condition {
                    Expression::BinaryOp { left, .. } => {
                        // Left should be unary operation
                        match **left {
                            Expression::UnaryOp { .. } => {
                                // Expected: unary operator in condition
                            }
                            _ => panic!("Expected unary operator in left side of condition"),
                        }
                    }
                    _ => panic!("Expected binary expression in condition"),
                }
            }
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_if_with_integer_literal_condition() {
        // Targets: delete match arm CXCursor_IntegerLiteral in visit_if_children (line 563)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test() { if (1) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing if with integer literal should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::IntLiteral(val) => {
                    assert_eq!(*val, 1, "Condition should be literal 1");
                }
                _ => panic!("Expected integer literal in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_if_with_variable_condition() {
        // Targets: delete match arm CXCursor_DeclRefExpr in visit_if_children (line 564)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int flag) { if (flag) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing if with variable condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::Variable(name) => {
                    assert_eq!(name, "flag", "Condition should be variable 'flag'");
                }
                _ => panic!("Expected variable in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_for_loop_with_variable_in_condition() {
        // Targets: delete match arm CXCursor_DeclRefExpr in visit_for_children (line 694)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int n) { for (int i = 0; n; i = i + 1) { } return 0; }";

        let ast = parser.parse(source).expect("Parsing for with variable condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::For { condition, .. } => {
                assert!(condition.is_some(), "Should have condition");
                if let Expression::Variable(name) = condition.as_ref().unwrap() {
                    assert_eq!(name, "n", "Condition should be variable 'n'");
                }
            }
            _ => panic!("Expected for statement"),
        }
    }

    #[test]
    fn test_while_loop_with_variable_condition() {
        // Targets: delete match arm CXCursor_DeclRefExpr in visit_while_children (line 789)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int flag) { while (flag) { flag = 0; } return 0; }";

        let ast =
            parser.parse(source).expect("Parsing while with variable condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::While { condition, .. } => match condition {
                Expression::Variable(name) => {
                    assert_eq!(name, "flag", "Condition should be variable 'flag'");
                }
                _ => panic!("Expected variable in while condition"),
            },
            _ => panic!("Expected while statement"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_while_loop_with_function_call_condition() {
        // Targets: delete match arm CXCursor_CallExpr in visit_while_children (line 790)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int check(void); int test() { while (check()) { } return 0; }";

        let ast = parser.parse(source).expect("Parsing while with call condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::While { condition, .. } => match condition {
                Expression::FunctionCall { function, .. } => {
                    assert_eq!(function, "check", "Should call 'check' function");
                }
                _ => panic!("Expected function call in while condition"),
            },
            _ => panic!("Expected while statement"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_function_call_with_array_index_argument() {
        // Targets: delete match arm CXCursor_ArraySubscriptExpr in visit_call_argument (line 1298)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int process(int); int test(int arr[]) { int x = process(arr[0]); return x; }";

        let ast = parser.parse(source).expect("Parsing call with array arg should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::VariableDeclaration { initializer, .. } => {
                match initializer {
                    Some(Expression::FunctionCall { arguments, .. }) => {
                        assert_eq!(arguments.len(), 1, "Should have one argument");
                        match &arguments[0] {
                            Expression::ArrayIndex { .. } => {
                                // Expected: array index as argument
                            }
                            _ => panic!("Expected array index argument"),
                        }
                    }
                    _ => panic!("Expected function call"),
                }
            }
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_function_call_with_unary_argument() {
        // Targets: delete match arm CXCursor_UnaryOperator in visit_call_argument (line 1291)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int abs(int); int test(int x) { int y = abs(-x); return y; }";

        let ast = parser.parse(source).expect("Parsing call with unary arg should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::VariableDeclaration { initializer, .. } => {
                match initializer {
                    Some(Expression::FunctionCall { arguments, .. }) => {
                        assert_eq!(arguments.len(), 1, "Should have one argument");
                        match &arguments[0] {
                            Expression::UnaryOp { .. } => {
                                // Expected: unary op as argument
                            }
                            _ => panic!("Expected unary op argument"),
                        }
                    }
                    _ => panic!("Expected function call"),
                }
            }
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_function_call_with_field_access_argument() {
        // Targets: delete match arm CXCursor_MemberRefExpr in visit_call_argument (line 1305)
        let parser = CParser::new().expect("Parser creation failed");
        let source =
            "int process(int); struct Point { int x; }; int test(struct Point p) { int v = process(p.x); return v; }";

        let ast = parser.parse(source).expect("Parsing call with field access arg should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::VariableDeclaration { initializer, .. } => {
                match initializer {
                    Some(Expression::FunctionCall { arguments, .. }) => {
                        assert_eq!(arguments.len(), 1, "Should have one argument");
                        match &arguments[0] {
                            Expression::FieldAccess { .. } => {
                                // Expected: field access as argument
                            }
                            _ => panic!("Expected field access argument"),
                        }
                    }
                    _ => panic!("Expected function call"),
                }
            }
            _ => panic!("Expected variable declaration"),
        }
    }

    #[test]
    fn test_while_with_integer_literal_condition() {
        // Targets: delete match arm CXCursor_IntegerLiteral in visit_while_children (line 788)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test() { while (1) { return 0; } return 1; }";

        let ast = parser.parse(source).expect("Parsing while with int literal should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::While { condition, .. } => match condition {
                Expression::IntLiteral(val) => {
                    assert_eq!(*val, 1, "Condition should be literal 1");
                }
                _ => panic!("Expected integer literal condition"),
            },
            _ => panic!("Expected while statement"),
        }
    }

    #[test]
    fn test_while_with_unary_in_condition() {
        // Targets: delete match arm CXCursor_UnaryOperator in visit_while_children (line 791)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int x) { while (-x < 10) { x = x + 1; } return x; }";

        let ast = parser.parse(source).expect("Parsing while with unary should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::While { condition, .. } => {
                match condition {
                    Expression::BinaryOp { left, .. } => {
                        match **left {
                            Expression::UnaryOp { .. } => {
                                // Expected: unary in while condition
                            }
                            _ => panic!("Expected unary op"),
                        }
                    }
                    _ => panic!("Expected binary expression"),
                }
            }
            _ => panic!("Expected while statement"),
        }
    }

    #[test]
    fn test_for_with_integer_literal_condition() {
        // Targets: delete match arm CXCursor_IntegerLiteral in visit_for_children (line 693)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test() { for (int i = 0; 1; i = i + 1) { return 0; } return 1; }";

        let ast =
            parser.parse(source).expect("Parsing for with int literal condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::For { condition, .. } => {
                assert!(condition.is_some(), "Should have condition");
                if let Expression::IntLiteral(val) = condition.as_ref().unwrap() {
                    assert_eq!(*val, 1, "Condition should be literal 1");
                }
            }
            _ => panic!("Expected for statement"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_for_with_function_call_condition() {
        // Targets: delete match arm CXCursor_CallExpr in visit_for_children (line 695)
        let parser = CParser::new().expect("Parser creation failed");
        let source =
            "int check(int); int test() { for (int i = 0; check(i); i = i + 1) { } return 0; }";

        let ast = parser.parse(source).expect("Parsing for with call condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::For { condition, .. } => {
                assert!(condition.is_some(), "Should have condition");
                if let Expression::FunctionCall { .. } = condition.as_ref().unwrap() {
                    // Expected: function call in for condition
                }
            }
            _ => panic!("Expected for statement"),
        }
    }

    #[test]
    #[ignore = "Parser limitation: Forward declarations change AST structure. Test needs rewrite."]
    fn test_if_with_function_call_condition() {
        // Targets: delete match arm CXCursor_CallExpr in visit_if_children (line 565)
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int check(void); int test() { if (check()) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing if with call condition should succeed");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::FunctionCall { function, .. } => {
                    assert_eq!(function, "check", "Should call check function");
                }
                _ => panic!("Expected function call condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    // DECY-040: Comparison Operator Parsing Tests
    // Verifies that all comparison operators (<, >, <=, >=, ==, !=) are correctly parsed

    #[test]
    fn test_less_than_operator() {
        // Test that < is correctly parsed as LessThan operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a < b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::LessThan,
                        "Should parse < as LessThan, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_greater_than_operator() {
        // Test that > is correctly parsed as GreaterThan operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a > b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::GreaterThan,
                        "Should parse > as GreaterThan, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_less_than_or_equal_operator() {
        // Test that <= is correctly parsed as LessEqual operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a <= b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::LessEqual,
                        "Should parse <= as LessEqual, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_greater_than_or_equal_operator() {
        // Test that >= is correctly parsed as GreaterEqual operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a >= b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::GreaterEqual,
                        "Should parse >= as GreaterEqual, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_equality_operator() {
        // Test that == is correctly parsed as Equal operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a == b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::Equal,
                        "CRITICAL: Should parse == as Equal, not {:?} (currently becomes Modulo!)",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_inequality_operator() {
        // Test that != is correctly parsed as NotEqual operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int test(int a, int b) { if (a != b) { return 1; } return 0; }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::If { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::NotEqual,
                        "Should parse != as NotEqual, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in condition"),
            },
            _ => panic!("Expected if statement"),
        }
    }

    #[test]
    fn test_all_comparison_operators_in_sequence() {
        // Test all comparison operators in one function
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"
            int test_all(int a, int b) {
                if (a < b) return 1;
                if (a > b) return 2;
                if (a <= b) return 3;
                if (a >= b) return 4;
                if (a == b) return 5;
                if (a != b) return 6;
                return 0;
            }
        "#;

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        // Check each if statement has correct operator
        let expected_ops = [
            BinaryOperator::LessThan,
            BinaryOperator::GreaterThan,
            BinaryOperator::LessEqual,
            BinaryOperator::GreaterEqual,
            BinaryOperator::Equal,
            BinaryOperator::NotEqual,
        ];

        for (i, expected_op) in expected_ops.iter().enumerate() {
            match &func.body[i] {
                Statement::If { condition, .. } => match condition {
                    Expression::BinaryOp { op, .. } => {
                        assert_eq!(
                            op, expected_op,
                            "If statement {} should have operator {:?}, got {:?}",
                            i, expected_op, op
                        );
                    }
                    _ => panic!("Expected binary operation in if statement {}", i),
                },
                _ => panic!("Expected if statement at position {}", i),
            }
        }
    }

    #[test]
    fn test_comparison_in_while_loop() {
        // Test that comparison operators work in while loops
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void loop(int n) { while (n <= 10) { n = n + 1; } }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::While { condition, .. } => match condition {
                Expression::BinaryOp { op, .. } => {
                    assert_eq!(
                        *op,
                        BinaryOperator::LessEqual,
                        "While condition should use <=, not {:?}",
                        op
                    );
                }
                _ => panic!("Expected binary operation in while condition"),
            },
            _ => panic!("Expected while statement"),
        }
    }

    #[test]
    fn test_comparison_in_for_loop() {
        // Test that comparison operators work in for loops
        let parser = CParser::new().expect("Parser creation failed");
        let source = "void count() { for (int i = 0; i < 10; i = i + 1) { } }";

        let ast = parser.parse(source).expect("Parsing should succeed");
        let func = &ast.functions()[0];

        match &func.body[0] {
            Statement::For { condition, .. } => {
                if let Some(cond_expr) = condition {
                    match cond_expr {
                        Expression::BinaryOp { op, .. } => {
                            assert_eq!(
                                *op,
                                BinaryOperator::LessThan,
                                "For condition should use <, not {:?}",
                                op
                            );
                        }
                        _ => panic!("Expected binary operation in for condition"),
                    }
                } else {
                    panic!("For loop should have condition");
                }
            }
            _ => panic!("Expected for statement"),
        }
    }

    #[test]
    fn test_parse_sizeof_expression() {
        // RED PHASE: Test for sizeof operator
        let parser = CParser::new().expect("Parser creation failed");
        let source = "int get_size() { return sizeof(int); }";

        let ast = parser.parse(source).expect("Parsing sizeof should succeed");

        assert_eq!(ast.functions().len(), 1, "Should parse one function");

        let func = &ast.functions()[0];
        assert_eq!(func.name, "get_size");
        assert_eq!(func.body.len(), 1, "Function should have one statement");

        // Check return statement contains sizeof expression
        match &func.body[0] {
            Statement::Return(Some(expr)) => match expr {
                Expression::Sizeof { type_name } => {
                    assert_eq!(type_name, "int", "sizeof should be for int type");
                }
                _ => panic!("Expected Sizeof expression, got {:?}", expr),
            },
            _ => panic!("Expected return statement with sizeof expression"),
        }
    }

    #[test]
    fn test_parse_sizeof_struct() {
        // RED PHASE: Test for sizeof with struct type
        let parser = CParser::new().expect("Parser creation failed");
        let source = r#"
            struct Data {
                int value;
            };
            int get_struct_size() { return sizeof(struct Data); }
        "#;

        let ast = parser.parse(source).expect("Parsing sizeof struct should succeed");

        assert_eq!(ast.functions().len(), 1, "Should parse one function");

        let func = &ast.functions()[0];
        match &func.body[0] {
            Statement::Return(Some(expr)) => match expr {
                Expression::Sizeof { type_name } => {
                    assert!(
                        type_name.contains("Data"),
                        "sizeof should be for Data struct, got: {}",
                        type_name
                    );
                }
                _ => panic!("Expected Sizeof expression"),
            },
            _ => panic!("Expected return statement with sizeof"),
        }
    }
}

#[test]
fn test_const_char_pointer_detection() {
    let code = r#"
void test_const(const char* str) {}
void test_mutable(char* str) {}
"#;

    let parser = CParser::new().unwrap();
    let ast = parser.parse(code).unwrap();

    let functions = ast.functions();
    assert_eq!(functions.len(), 2);

    // First function should have const char*
    let test_const = &functions[0];
    assert_eq!(&test_const.name, "test_const");
    assert_eq!(test_const.parameters.len(), 1);
    assert!(
        test_const.parameters[0].is_pointee_const,
        "const char* should have is_pointee_const = true"
    );

    // Second function should NOT have const char*
    let test_mutable = &functions[1];
    assert_eq!(&test_mutable.name, "test_mutable");
    assert_eq!(test_mutable.parameters.len(), 1);
    assert!(
        !test_mutable.parameters[0].is_pointee_const,
        "char* should have is_pointee_const = false"
    );
}

// ============================================================================
// Binary operator coverage: operators not yet tested
// ============================================================================

#[test]
fn test_parse_subtract_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int sub(int a, int b) { return a - b; }";
    let ast = parser.parse(source).expect("Should parse subtraction");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::Subtract);
        }
        other => panic!("Expected BinaryOp Subtract, got {:?}", other),
    }
}

#[test]
fn test_parse_multiply_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int mul(int a, int b) { return a * b; }";
    let ast = parser.parse(source).expect("Should parse multiplication");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::Multiply);
        }
        other => panic!("Expected BinaryOp Multiply, got {:?}", other),
    }
}

#[test]
fn test_parse_divide_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int div(int a, int b) { return a / b; }";
    let ast = parser.parse(source).expect("Should parse division");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::Divide);
        }
        other => panic!("Expected BinaryOp Divide, got {:?}", other),
    }
}

#[test]
fn test_parse_modulo_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int mod_op(int a, int b) { return a % b; }";
    let ast = parser.parse(source).expect("Should parse modulo");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::Modulo);
        }
        other => panic!("Expected BinaryOp Modulo, got {:?}", other),
    }
}

#[test]
fn test_parse_less_equal_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int check(int a, int b) { if (a <= b) { return 1; } return 0; }";
    let ast = parser.parse(source).expect("Should parse <=");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::If { condition, .. } => match condition {
            Expression::BinaryOp { op, .. } => {
                assert_eq!(*op, BinaryOperator::LessEqual);
            }
            other => panic!("Expected BinaryOp LessEqual, got {:?}", other),
        },
        other => panic!("Expected If statement, got {:?}", other),
    }
}

#[test]
fn test_parse_greater_equal_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int check(int a, int b) { if (a >= b) { return 1; } return 0; }";
    let ast = parser.parse(source).expect("Should parse >=");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::If { condition, .. } => match condition {
            Expression::BinaryOp { op, .. } => {
                assert_eq!(*op, BinaryOperator::GreaterEqual);
            }
            other => panic!("Expected BinaryOp GreaterEqual, got {:?}", other),
        },
        other => panic!("Expected If statement, got {:?}", other),
    }
}

#[test]
fn test_parse_bitwise_and_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int bitand(int a, int b) { return a & b; }";
    let ast = parser.parse(source).expect("Should parse bitwise AND");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::BitwiseAnd);
        }
        other => panic!("Expected BinaryOp BitwiseAnd, got {:?}", other),
    }
}

#[test]
fn test_parse_bitwise_or_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int bitor(int a, int b) { return a | b; }";
    let ast = parser.parse(source).expect("Should parse bitwise OR");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::BitwiseOr);
        }
        other => panic!("Expected BinaryOp BitwiseOr, got {:?}", other),
    }
}

#[test]
fn test_parse_bitwise_xor_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int bitxor(int a, int b) { return a ^ b; }";
    let ast = parser.parse(source).expect("Should parse bitwise XOR");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::BitwiseXor);
        }
        other => panic!("Expected BinaryOp BitwiseXor, got {:?}", other),
    }
}

#[test]
fn test_parse_left_shift_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int lshift(int a, int b) { return a << b; }";
    let ast = parser.parse(source).expect("Should parse left shift");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::LeftShift);
        }
        other => panic!("Expected BinaryOp LeftShift, got {:?}", other),
    }
}

#[test]
fn test_parse_right_shift_operator() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "int rshift(int a, int b) { return a >> b; }";
    let ast = parser.parse(source).expect("Should parse right shift");
    let func = &ast.functions()[0];
    match &func.body[0] {
        Statement::Return(Some(Expression::BinaryOp { op, .. })) => {
            assert_eq!(*op, BinaryOperator::RightShift);
        }
        other => panic!("Expected BinaryOp RightShift, got {:?}", other),
    }
}

// ============================================================================
// Increment/decrement coverage
// ============================================================================

#[test]
fn test_parse_post_increment() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "void inc(int* p) { int x = 0; x++; }";
    let ast = parser.parse(source).expect("Should parse post-increment");
    let func = &ast.functions()[0];
    // Should have at least a variable declaration and an increment
    assert!(func.body.len() >= 2, "Should have at least 2 statements");
}

#[test]
fn test_parse_pre_decrement() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "void dec() { int x = 5; --x; }";
    let ast = parser.parse(source).expect("Should parse pre-decrement");
    let func = &ast.functions()[0];
    assert!(func.body.len() >= 2, "Should have at least 2 statements");
}

// ============================================================================
// For loop variants coverage
// ============================================================================

#[test]
fn test_parse_for_loop_with_compound_condition() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "void test() { int i; for (i = 0; i < 10 && i >= 0; i++) { } }";
    let ast = parser.parse(source).expect("Should parse for with compound condition");
    let func = &ast.functions()[0];
    // Verify function has statements (for loop should be present)
    assert!(!func.body.is_empty(), "Function body should not be empty");
}

#[test]
fn test_parse_for_loop_with_multiple_inits() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = "void test() { int i; int j; for (i = 0, j = 10; i < j; i++, j--) { } }";
    let ast = parser.parse(source).expect("Should parse for with multiple inits");
    let func = &ast.functions()[0];
    assert!(!func.body.is_empty(), "Function body should not be empty");
}

#[test]
fn test_parse_while_with_assignment_in_condition() {
    let parser = CParser::new().expect("Parser creation failed");
    let source = r#"
        int test() {
            int x = 10;
            while (x > 0) {
                x = x - 1;
            }
            return x;
        }
    "#;
    let ast = parser.parse(source).expect("Should parse while with decrement");
    let func = &ast.functions()[0];
    assert!(func.body.len() >= 2, "Should have while + return");
}