aboutsummaryrefslogtreecommitdiff
path: root/test/translate_c.zig
blob: 2097e17323cb07e88712942db9dea5b121e42461 (plain)
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
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
const tests = @import("tests.zig");
const std = @import("std");
const CrossTarget = std.zig.CrossTarget;

pub fn addCases(cases: *tests.TranslateCContext) void {
    cases.add("variadic function demoted to prototype",
        \\int foo(int bar, ...) {
        \\    return 1;
        \\}
    , &[_][]const u8{
        \\warning: TODO unable to translate variadic function, demoted to declaration
        \\pub extern fn foo(bar: c_int, ...) c_int;
    });

    cases.add("pointer to opaque demoted struct",
        \\typedef struct {
        \\    _Atomic int foo;
        \\} Foo;
        \\
        \\typedef struct {
        \\    Foo *bar;
        \\} Bar;
    , &[_][]const u8{
        \\const struct_unnamed_1 = //
        ,
        \\warning: unsupported type: 'Atomic'
        \\    opaque {}; //
        ,
        \\pub const Foo = struct_unnamed_1;
        \\const struct_unnamed_2 = extern struct {
        \\    bar: ?*Foo,
        \\};
    });

    cases.add("macro expressions respect C operator precedence",
        \\#define FOO *((foo) + 2)
        \\#define VALUE  (1 + 2 * 3 + 4 * 5 + 6 << 7 | 8 == 9)
        \\#define _AL_READ3BYTES(p)   ((*(unsigned char *)(p))            \
        \\                             | (*((unsigned char *)(p) + 1) << 8)  \
        \\                             | (*((unsigned char *)(p) + 2) << 16))
    , &[_][]const u8{
        \\pub const FOO = (foo + 2).*;
        ,
        \\pub const VALUE = ((((1 + (2 * 3)) + (4 * 5)) + 6) << 7) | @boolToInt(8 == 9);
        ,
        \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf(((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16)) {
        \\    return ((@import("std").meta.cast([*c]u8, p)).* | (((@import("std").meta.cast([*c]u8, p)) + 1).* << 8)) | (((@import("std").meta.cast([*c]u8, p)) + 2).* << 16);
        \\}
    });

    cases.add("extern variable in block scope",
        \\float bar;
        \\int foo() {
        \\    _Thread_local static int bar = 2;
        \\}
    , &[_][]const u8{
        \\pub export var bar: f32 = @import("std").mem.zeroes(f32);
        \\threadlocal var bar_1: c_int = 2;
        \\pub export fn foo() c_int {
        \\    _ = bar_1;
        \\    return 0;
        \\}
    });

    cases.add("missing return stmt",
        \\int foo() {}
        \\int bar() {
        \\    int a = 2;
        \\}
        \\int baz() {
        \\    return 0;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    return 0;
        \\}
        \\pub export fn bar() c_int {
        \\    var a: c_int = 2;
        \\    return 0;
        \\}
        \\pub export fn baz() c_int {
        \\    return 0;
        \\}
    });

    cases.add("alignof",
        \\void main() {
        \\    int a = _Alignof(int);
        \\}
    , &[_][]const u8{
        \\pub export fn main() void {
        \\    var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int)));
        \\}
    });

    cases.add("initializer list macro",
        \\typedef struct Color {
        \\    unsigned char r;
        \\    unsigned char g;
        \\    unsigned char b;
        \\    unsigned char a;
        \\} Color;
        \\#define CLITERAL(type)      (type)
        \\#define LIGHTGRAY  CLITERAL(Color){ 200, 200, 200, 255 }   // Light Gray
        \\typedef struct boom_t
        \\{
        \\    int i1;
        \\} boom_t;
        \\#define FOO ((boom_t){1})
    , &[_][]const u8{ // TODO properly translate this
        \\pub const struct_Color = extern struct {
        \\    r: u8,
        \\    g: u8,
        \\    b: u8,
        \\    a: u8,
        \\};
        \\pub const Color = struct_Color;
        ,
        \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) {
        \\    return type_1;
        \\}
        ,
        \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 });
        ,
        \\pub const struct_boom_t = extern struct {
        \\    i1: c_int,
        \\};
        \\pub const boom_t = struct_boom_t;
        ,
        \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{ 1 });
    });

    cases.add("complex switch",
        \\int main() {
        \\    int i = 2;
        \\    switch (i) {
        \\        case 0: {
        \\            case 2:{
        \\                i += 2;}
        \\            i += 1;
        \\        }
        \\    }
        \\}
    , &[_][]const u8{ // TODO properly translate this
        \\pub const main = @compileError("unable to translate function");
    });

    cases.add("correct semicolon after infixop",
        \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0)
    , &[_][]const u8{
        \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf(((_fp.*._flags) & _IO_ERR_SEEN) != 0) {
        \\    return ((_fp.*._flags) & _IO_ERR_SEEN) != 0;
        \\}
    });

    cases.add("c booleans are just ints",
        \\#define FOO(x) ((x >= 0) + (x >= 0))
        \\#define BAR 1 && 2 > 4
    , &[_][]const u8{
        \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= 0) + @boolToInt(x >= 0)) {
        \\    return @boolToInt(x >= 0) + @boolToInt(x >= 0);
        \\}
        ,
        \\pub const BAR = (1 != 0) and (2 > 4);
    });

    cases.add("struct with aligned fields",
        \\struct foo {
        \\    __attribute__((aligned(1))) short bar;
        \\};
    , &[_][]const u8{
        \\pub const struct_foo = extern struct {
        \\    bar: c_short align(1),
        \\};
    });

    cases.add("structs with VLAs are rejected",
        \\struct foo { int x; int y[]; };
        \\struct bar { int x; int y[0]; };
    , &[_][]const u8{
        \\pub const struct_foo = opaque {};
        ,
        \\pub const struct_bar = opaque {};
    });

    cases.add("nested loops without blocks",
        \\void foo() {
        \\    while (0) while (0) {}
        \\    for (;;) while (0);
        \\    for (;;) do {} while (0);
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    while (false) while (false) {};
        \\    while (true) while (false) {};
        \\    while (true) while (true) {
        \\        if (!false) break;
        \\    };
        \\}
    });

    cases.add("macro comma operator",
        \\#define foo (foo, bar)
        \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))
    , &[_][]const u8{
        \\pub const foo = blk: {
        \\    _ = foo;
        \\    break :blk bar;
        \\};
        ,
        \\pub inline fn bar(x: anytype) @TypeOf(baz(1, 2)) {
        \\    return blk: {
        \\        _ = &x;
        \\        _ = 3;
        \\        _ = 4 == 4;
        \\        _ = 5 * 6;
        \\        _ = baz(1, 2);
        \\        _ = 2 % 2;
        \\        break :blk baz(1, 2);
        \\    };
        \\}
    });

    cases.add("macro keyword define",
        \\#define foo 1
        \\#define inline 2
    , &[_][]const u8{
        \\pub const foo = 1;
        ,
        \\pub const @"inline" = 2;
    });

    cases.add("macro line continuation",
        \\#define FOO -\
        \\BAR
    , &[_][]const u8{
        \\pub const FOO = -BAR;
    });

    cases.add("struct with atomic field",
        \\struct arcan_shmif_cont {
        \\        struct arcan_shmif_page* addr;
        \\};
        \\struct arcan_shmif_page {
        \\        volatile _Atomic int abufused[12];
        \\};
    , &[_][]const u8{
        \\pub const struct_arcan_shmif_page = //
        ,
        \\warning: unsupported type: 'Atomic'
        \\    opaque {}; //
        ,
        \\ warning: struct demoted to opaque type - unable to translate type of field abufused
        , // TODO should be `addr: *struct_arcan_shmif_page`
        \\pub const struct_arcan_shmif_cont = extern struct {
        \\    addr: [*c]struct_arcan_shmif_page,
        \\};
    });

    cases.add("function prototype translated as optional",
        \\typedef void (*fnptr_ty)(void);
        \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);
        \\struct foo {
        \\    __attribute__((cdecl)) void (*foo)(void);
        \\    void (*bar)(void);
        \\    fnptr_ty baz;
        \\    fnptr_attr_ty qux;
        \\};
    , &[_][]const u8{
        \\pub const fnptr_ty = ?fn () callconv(.C) void;
        \\pub const fnptr_attr_ty = ?fn () callconv(.C) void;
        \\pub const struct_foo = extern struct {
        \\    foo: ?fn () callconv(.C) void,
        \\    bar: ?fn () callconv(.C) void,
        \\    baz: fnptr_ty,
        \\    qux: fnptr_attr_ty,
        \\};
    });

    cases.add("function prototype with parenthesis",
        \\void (f0) (void *L);
        \\void ((f1)) (void *L);
        \\void (((f2))) (void *L);
    , &[_][]const u8{
        \\pub extern fn f0(L: ?*c_void) void;
        \\pub extern fn f1(L: ?*c_void) void;
        \\pub extern fn f2(L: ?*c_void) void;
    });

    cases.add("array initializer w/ typedef",
        \\typedef unsigned char uuid_t[16];
        \\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    , &[_][]const u8{
        \\pub const uuid_t = [16]u8;
        \\pub const UUID_NULL: uuid_t = [16]u8{
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\    @bitCast(u8, @truncate(i8, @as(c_int, 0))),
        \\};
    });

    cases.add("empty declaration",
        \\;
    , &[_][]const u8{""});

    cases.add("#define hex literal with capital X",
        \\#define VAL 0XF00D
    , &[_][]const u8{
        \\pub const VAL = 0xF00D;
    });

    cases.add("anonymous struct & unions",
        \\typedef struct {
        \\    union {
        \\        char x;
        \\        struct { int y; };
        \\    };
        \\} outer;
        \\void foo(outer *x) { x->y = x->x; }
    , &[_][]const u8{
        \\const struct_unnamed_3 = extern struct {
        \\    y: c_int,
        \\};
        \\const union_unnamed_2 = extern union {
        \\    x: u8,
        \\    unnamed_0: struct_unnamed_3,
        \\};
        \\const struct_unnamed_1 = extern struct {
        \\    unnamed_0: union_unnamed_2,
        \\};
        \\pub const outer = struct_unnamed_1;
        \\pub export fn foo(arg_x: [*c]outer) void {
        \\    var x = arg_x;
        \\    x.*.unnamed_0.unnamed_0.y = @bitCast(c_int, @as(c_uint, x.*.unnamed_0.x));
        \\}
    });

    cases.add("union initializer",
        \\union { int x; char c[4]; }
        \\  ua = {1},
        \\  ub = {.c={'a','b','b','a'}};
    , &[_][]const u8{
        \\const union_unnamed_1 = extern union {
        \\    x: c_int,
        \\    c: [4]u8,
        \\};
        \\pub export var ua: union_unnamed_1 = union_unnamed_1{
        \\    .x = @as(c_int, 1),
        \\};
        \\pub export var ub: union_unnamed_1 = union_unnamed_1{
        \\    .c = [4]u8{
        \\        @bitCast(u8, @truncate(i8, @as(c_int, 'a'))),
        \\        @bitCast(u8, @truncate(i8, @as(c_int, 'b'))),
        \\        @bitCast(u8, @truncate(i8, @as(c_int, 'b'))),
        \\        @bitCast(u8, @truncate(i8, @as(c_int, 'a'))),
        \\    },
        \\};
    });

    cases.add("struct initializer - simple",
        \\typedef struct { int x; } foo;
        \\struct {double x,y,z;} s0 = {1.2, 1.3};
        \\struct {int sec,min,hour,day,mon,year;} s1 = {.day=31,12,2014,.sec=30,15,17};
        \\struct {int x,y;} s2 = {.y = 2, .x=1};
        \\foo s3 = { 123 };
    , &[_][]const u8{
        \\const struct_unnamed_1 = extern struct {
        \\    x: c_int,
        \\};
        \\pub const foo = struct_unnamed_1;
        \\const struct_unnamed_2 = extern struct {
        \\    x: f64,
        \\    y: f64,
        \\    z: f64,
        \\};
        \\pub export var s0: struct_unnamed_2 = struct_unnamed_2{
        \\    .x = 1.2,
        \\    .y = 1.3,
        \\    .z = 0,
        \\};
        \\const struct_unnamed_3 = extern struct {
        \\    sec: c_int,
        \\    min: c_int,
        \\    hour: c_int,
        \\    day: c_int,
        \\    mon: c_int,
        \\    year: c_int,
        \\};
        \\pub export var s1: struct_unnamed_3 = struct_unnamed_3{
        \\    .sec = @as(c_int, 30),
        \\    .min = @as(c_int, 15),
        \\    .hour = @as(c_int, 17),
        \\    .day = @as(c_int, 31),
        \\    .mon = @as(c_int, 12),
        \\    .year = @as(c_int, 2014),
        \\};
        \\const struct_unnamed_4 = extern struct {
        \\    x: c_int,
        \\    y: c_int,
        \\};
        \\pub export var s2: struct_unnamed_4 = struct_unnamed_4{
        \\    .x = @as(c_int, 1),
        \\    .y = @as(c_int, 2),
        \\};
        \\pub export var s3: foo = foo{
        \\    .x = @as(c_int, 123),
        \\};
    });

    cases.add("simple ptrCast for casts between opaque types",
        \\struct opaque;
        \\struct opaque_2;
        \\void function(struct opaque *opaque) {
        \\    struct opaque_2 *cast = (struct opaque_2 *)opaque;
        \\}
    , &[_][]const u8{
        \\pub const struct_opaque = opaque {};
        \\pub const struct_opaque_2 = opaque {};
        \\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
        \\    var opaque_1 = arg_opaque_1;
        \\    var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);
        \\}
    });

    cases.add("struct initializer - packed",
        \\struct {int x,y,z;} __attribute__((packed)) s0 = {1, 2};
    , &[_][]const u8{
        \\const struct_unnamed_1 = packed struct {
        \\    x: c_int,
        \\    y: c_int,
        \\    z: c_int,
        \\};
        \\pub export var s0: struct_unnamed_1 = struct_unnamed_1{
        \\    .x = @as(c_int, 1),
        \\    .y = @as(c_int, 2),
        \\    .z = 0,
        \\};
    });

    cases.add("align() attribute",
        \\__attribute__ ((aligned(128)))
        \\extern char my_array[16];
        \\__attribute__ ((aligned(128)))
        \\void my_fn(void) { }
    , &[_][]const u8{
        \\pub extern var my_array: [16]u8 align(128);
        \\pub export fn my_fn() align(128) void {}
    });

    cases.add("linksection() attribute",
        \\// Use the "segment,section" format to make this test pass when
        \\// targeting the mach-o binary format
        \\__attribute__ ((__section__("NEAR,.data")))
        \\extern char my_array[16];
        \\__attribute__ ((__section__("NEAR,.data")))
        \\void my_fn(void) { }
    , &[_][]const u8{
        \\pub extern var my_array: [16]u8 linksection("NEAR,.data");
        \\pub export fn my_fn() linksection("NEAR,.data") void {}
    });

    cases.add("simple function prototypes",
        \\void __attribute__((noreturn)) foo(void);
        \\int bar(void);
    , &[_][]const u8{
        \\pub extern fn foo() noreturn;
        \\pub extern fn bar() c_int;
    });

    cases.add("simple var decls",
        \\void foo(void) {
        \\    int a;
        \\    char b = 123;
        \\    const int c;
        \\    const unsigned d = 440;
        \\    int e = 10;
        \\    unsigned int f = 10u;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = undefined;
        \\    var b: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 123)));
        \\    const c: c_int = undefined;
        \\    const d: c_uint = @bitCast(c_uint, @as(c_int, 440));
        \\    var e: c_int = 10;
        \\    var f: c_uint = 10;
        \\}
    });

    cases.add("ignore result, explicit function arguments",
        \\void foo(void) {
        \\    int a;
        \\    1;
        \\    "hey";
        \\    1 + 1;
        \\    1 - 1;
        \\    a = 1;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = undefined;
        \\    _ = @as(c_int, 1);
        \\    _ = "hey";
        \\    _ = (@as(c_int, 1) + @as(c_int, 1));
        \\    _ = (@as(c_int, 1) - @as(c_int, 1));
        \\    a = 1;
        \\}
    });

    cases.add("function with no prototype",
        \\int foo() {
        \\    return 5;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    return 5;
        \\}
    });

    cases.add("variables",
        \\extern int extern_var;
        \\static const int int_var = 13;
        \\int foo;
    , &[_][]const u8{
        \\pub extern var extern_var: c_int;
        \\pub const int_var: c_int = 13;
        \\pub export var foo: c_int = @import("std").mem.zeroes(c_int);
    });

    cases.add("const ptr initializer",
        \\static const char *v0 = "0.0.0";
    , &[_][]const u8{
        \\pub var v0: [*c]const u8 = "0.0.0";
    });

    cases.add("static incomplete array inside function",
        \\void foo(void) {
        \\    static const char v2[] = "2.2.2";
        \\}
    , &[_][]const u8{
        \\const v2: [6]u8 = [6]u8{
        \\    '2',
        \\    '.',
        \\    '2',
        \\    '.',
        \\    '2',
        \\    0,
        \\};
        \\pub export fn foo() void {
        \\    _ = v2;
        \\}
    });

    cases.add("simple function definition",
        \\void foo(void) {}
        \\static void bar(void) {}
    , &[_][]const u8{
        \\pub export fn foo() void {}
        \\pub fn bar() callconv(.C) void {}
    });

    cases.add("typedef void",
        \\typedef void Foo;
        \\Foo fun(Foo *a);
    , &[_][]const u8{
        \\pub const Foo = c_void;
        ,
        \\pub extern fn fun(a: ?*Foo) Foo;
    });

    cases.add("duplicate typedef",
        \\typedef long foo;
        \\typedef int bar;
        \\typedef long foo;
        \\typedef int baz;
    , &[_][]const u8{
        \\pub const foo = c_long;
        \\pub const bar = c_int;
        \\pub const baz = c_int;
    });

    cases.add("casting pointers to ints and ints to pointers",
        \\void foo(void);
        \\void bar(void) {
        \\    void *func_ptr = foo;
        \\    void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr;
        \\}
    , &[_][]const u8{
        \\pub extern fn foo() void;
        \\pub export fn bar() void {
        \\    var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
        \\    var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
        \\}
    });

    cases.add("noreturn attribute",
        \\void foo(void) __attribute__((noreturn));
    , &[_][]const u8{
        \\pub extern fn foo() noreturn;
    });

    cases.add("add, sub, mul, div, rem",
        \\int s() {
        \\    int a, b, c;
        \\    c = a + b;
        \\    c = a - b;
        \\    c = a * b;
        \\    c = a / b;
        \\    c = a % b;
        \\}
        \\unsigned u() {
        \\    unsigned a, b, c;
        \\    c = a + b;
        \\    c = a - b;
        \\    c = a * b;
        \\    c = a / b;
        \\    c = a % b;
        \\}
    , &[_][]const u8{
        \\pub export fn s() c_int {
        \\    var a: c_int = undefined;
        \\    var b: c_int = undefined;
        \\    var c: c_int = undefined;
        \\    c = (a + b);
        \\    c = (a - b);
        \\    c = (a * b);
        \\    c = @divTrunc(a, b);
        \\    c = @rem(a, b);
        \\    return 0;
        \\}
        \\pub export fn u() c_uint {
        \\    var a: c_uint = undefined;
        \\    var b: c_uint = undefined;
        \\    var c: c_uint = undefined;
        \\    c = (a +% b);
        \\    c = (a -% b);
        \\    c = (a *% b);
        \\    c = (a / b);
        \\    c = (a % b);
        \\    return 0;
        \\}
    });

    cases.add("typedef of function in struct field",
        \\typedef void lws_callback_function(void);
        \\struct Foo {
        \\    void (*func)(void);
        \\    lws_callback_function *callback_http;
        \\};
    , &[_][]const u8{
        \\pub const lws_callback_function = fn () callconv(.C) void;
        \\pub const struct_Foo = extern struct {
        \\    func: ?fn () callconv(.C) void,
        \\    callback_http: ?lws_callback_function,
        \\};
    });

    cases.add("pointer to struct demoted to opaque due to bit fields",
        \\struct Foo {
        \\    unsigned int: 1;
        \\};
        \\struct Bar {
        \\    struct Foo *foo;
        \\};
    , &[_][]const u8{
        \\pub const struct_Foo = opaque {};
        ,
        \\pub const struct_Bar = extern struct {
        \\    foo: ?*struct_Foo,
        \\};
    });

    cases.add("macro with left shift",
        \\#define REDISMODULE_READ (1<<0)
    , &[_][]const u8{
        \\pub const REDISMODULE_READ = 1 << 0;
    });

    cases.add("macro with right shift",
        \\#define FLASH_SIZE         0x200000UL          /* 2 MB   */
        \\#define FLASH_BANK_SIZE    (FLASH_SIZE >> 1)   /* 1 MB   */
    , &[_][]const u8{
        \\pub const FLASH_SIZE = @as(c_ulong, 0x200000);
        ,
        \\pub const FLASH_BANK_SIZE = FLASH_SIZE >> 1;
    });

    cases.add("double define struct",
        \\typedef struct Bar Bar;
        \\typedef struct Foo Foo;
        \\
        \\struct Foo {
        \\    Foo *a;
        \\};
        \\
        \\struct Bar {
        \\    Foo *a;
        \\};
    , &[_][]const u8{
        \\pub const struct_Foo = extern struct {
        \\    a: [*c]Foo,
        \\};
        ,
        \\pub const Foo = struct_Foo;
        ,
        \\pub const struct_Bar = extern struct {
        \\    a: [*c]Foo,
        \\};
        ,
        \\pub const Bar = struct_Bar;
    });

    cases.add("simple struct",
        \\struct Foo {
        \\    int x;
        \\    char *y;
        \\};
    , &[_][]const u8{
        \\const struct_Foo = extern struct {
        \\    x: c_int,
        \\    y: [*c]u8,
        \\};
        ,
        \\pub const Foo = struct_Foo;
    });

    cases.add("self referential struct with function pointer",
        \\struct Foo {
        \\    void (*derp)(struct Foo *foo);
        \\};
    , &[_][]const u8{
        \\pub const struct_Foo = extern struct {
        \\    derp: ?fn ([*c]struct_Foo) callconv(.C) void,
        \\};
        ,
        \\pub const Foo = struct_Foo;
    });

    cases.add("struct prototype used in func",
        \\struct Foo;
        \\struct Foo *some_func(struct Foo *foo, int x);
    , &[_][]const u8{
        \\pub const struct_Foo = opaque {};
        ,
        \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
        ,
        \\pub const Foo = struct_Foo;
    });

    cases.add("#define an unsigned integer literal",
        \\#define CHANNEL_COUNT 24
    , &[_][]const u8{
        \\pub const CHANNEL_COUNT = 24;
    });

    cases.add("#define referencing another #define",
        \\#define THING2 THING1
        \\#define THING1 1234
    , &[_][]const u8{
        \\pub const THING1 = 1234;
        ,
        \\pub const THING2 = THING1;
    });

    cases.add("circular struct definitions",
        \\struct Bar;
        \\
        \\struct Foo {
        \\    struct Bar *next;
        \\};
        \\
        \\struct Bar {
        \\    struct Foo *next;
        \\};
    , &[_][]const u8{
        \\pub const struct_Bar = extern struct {
        \\    next: [*c]struct_Foo,
        \\};
        ,
        \\pub const struct_Foo = extern struct {
        \\    next: [*c]struct_Bar,
        \\};
    });

    cases.add("#define string",
        \\#define  foo  "a string"
    , &[_][]const u8{
        \\pub const foo = "a string";
    });

    cases.add("zig keywords in C code",
        \\struct comptime {
        \\    int defer;
        \\};
    , &[_][]const u8{
        \\pub const struct_comptime = extern struct {
        \\    @"defer": c_int,
        \\};
        ,
        \\pub const @"comptime" = struct_comptime;
    });

    cases.add("macro with parens around negative number",
        \\#define LUA_GLOBALSINDEX        (-10002)
    , &[_][]const u8{
        \\pub const LUA_GLOBALSINDEX = -10002;
    });

    cases.add(
        "u integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0U",
        &[_][]const u8{
            "pub const ZERO = @as(c_uint, 0);",
        },
    );

    cases.add(
        "l integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0L",
        &[_][]const u8{
            "pub const ZERO = @as(c_long, 0);",
        },
    );

    cases.add(
        "ul integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0UL",
        &[_][]const u8{
            "pub const ZERO = @as(c_ulong, 0);",
        },
    );

    cases.add(
        "lu integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0LU",
        &[_][]const u8{
            "pub const ZERO = @as(c_ulong, 0);",
        },
    );

    cases.add(
        "ll integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0LL",
        &[_][]const u8{
            "pub const ZERO = @as(c_longlong, 0);",
        },
    );

    cases.add(
        "ull integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0ULL",
        &[_][]const u8{
            "pub const ZERO = @as(c_ulonglong, 0);",
        },
    );

    cases.add(
        "llu integer suffix after 0 (zero) in macro definition",
        "#define ZERO 0LLU",
        &[_][]const u8{
            "pub const ZERO = @as(c_ulonglong, 0);",
        },
    );

    cases.add(
        "bitwise not on u-suffixed 0 (zero) in macro definition",
        "#define NOT_ZERO (~0U)",
        &[_][]const u8{
            "pub const NOT_ZERO = ~@as(c_uint, 0);",
        },
    );

    cases.add("float suffixes",
        \\#define foo 3.14f
        \\#define bar 16.e-2l
        \\#define FOO 0.12345
        \\#define BAR .12345
    , &[_][]const u8{
        "pub const foo = @as(f32, 3.14);",
        "pub const bar = @as(c_longdouble, 16.e-2);",
        "pub const FOO = 0.12345;",
        "pub const BAR = 0.12345;",
    });

    cases.add("comments",
        \\#define foo 1 //foo
        \\#define bar /* bar */ 2
    , &[_][]const u8{
        "pub const foo = 1;",
        "pub const bar = 2;",
    });

    cases.add("string prefix",
        \\#define foo L"hello"
    , &[_][]const u8{
        "pub const foo = \"hello\";",
    });

    cases.add("null statements",
        \\void foo(void) {
        \\    ;;;;;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    {}
        \\    {}
        \\    {}
        \\    {}
        \\    {}
        \\}
    });

    if (std.Target.current.os.tag != .windows) {
        // Windows treats this as an enum with type c_int
        cases.add("big negative enum init values when C ABI supports long long enums",
            \\enum EnumWithInits {
            \\    VAL01 = 0,
            \\    VAL02 = 1,
            \\    VAL03 = 2,
            \\    VAL04 = 3,
            \\    VAL05 = -1,
            \\    VAL06 = -2,
            \\    VAL07 = -3,
            \\    VAL08 = -4,
            \\    VAL09 = VAL02 + VAL08,
            \\    VAL10 = -1000012000,
            \\    VAL11 = -1000161000,
            \\    VAL12 = -1000174001,
            \\    VAL13 = VAL09,
            \\    VAL14 = VAL10,
            \\    VAL15 = VAL11,
            \\    VAL16 = VAL13,
            \\    VAL17 = (VAL16 - VAL10 + 1),
            \\    VAL18 = 0x1000000000000000L,
            \\    VAL19 = VAL18 + VAL18 + VAL18 - 1,
            \\    VAL20 = VAL19 + VAL19,
            \\    VAL21 = VAL20 + 0xFFFFFFFFFFFFFFFF,
            \\    VAL22 = 0xFFFFFFFFFFFFFFFF + 1,
            \\    VAL23 = 0xFFFFFFFFFFFFFFFF,
            \\};
        , &[_][]const u8{
            \\pub const enum_EnumWithInits = extern enum(c_longlong) {
            \\    VAL01 = 0,
            \\    VAL02 = 1,
            \\    VAL03 = 2,
            \\    VAL04 = 3,
            \\    VAL05 = -1,
            \\    VAL06 = -2,
            \\    VAL07 = -3,
            \\    VAL08 = -4,
            \\    VAL09 = -3,
            \\    VAL10 = -1000012000,
            \\    VAL11 = -1000161000,
            \\    VAL12 = -1000174001,
            \\    VAL13 = -3,
            \\    VAL14 = -1000012000,
            \\    VAL15 = -1000161000,
            \\    VAL16 = -3,
            \\    VAL17 = 1000011998,
            \\    VAL18 = 1152921504606846976,
            \\    VAL19 = 3458764513820540927,
            \\    VAL20 = 6917529027641081854,
            \\    VAL21 = 6917529027641081853,
            \\    VAL22 = 0,
            \\    VAL23 = -1,
            \\    _,
            \\};
        });
    }

    cases.add("predefined expressions",
        \\void foo(void) {
        \\    __func__;
        \\    __FUNCTION__;
        \\    __PRETTY_FUNCTION__;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    _ = "foo";
        \\    _ = "foo";
        \\    _ = "void foo(void)";
        \\}
    });

    cases.add("constant size array",
        \\void func(int array[20]);
    , &[_][]const u8{
        \\pub extern fn func(array: [*c]c_int) void;
    });

    cases.add("__cdecl doesn't mess up function pointers",
        \\void foo(void (__cdecl *fn_ptr)(void));
    , &[_][]const u8{
        \\pub extern fn foo(fn_ptr: ?fn () callconv(.C) void) void;
    });

    cases.add("void cast",
        \\void foo() {
        \\    int a;
        \\    (void) a;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = undefined;
        \\    _ = a;
        \\}
    });

    cases.add("implicit cast to void *",
        \\void *foo() {
        \\    unsigned short *x;
        \\    return x;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() ?*c_void {
        \\    var x: [*c]c_ushort = undefined;
        \\    return @ptrCast(?*c_void, x);
        \\}
    });

    cases.add("null pointer implicit cast",
        \\int* foo(void) {
        \\    return 0;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() [*c]c_int {
        \\    return null;
        \\}
    });

    cases.add("simple union",
        \\union Foo {
        \\    int x;
        \\    double y;
        \\};
    , &[_][]const u8{
        \\pub const union_Foo = extern union {
        \\    x: c_int,
        \\    y: f64,
        \\};
        ,
        \\pub const Foo = union_Foo;
    });

    cases.add("string literal",
        \\const char *foo(void) {
        \\    return "bar";
        \\}
    , &[_][]const u8{
        \\pub export fn foo() [*c]const u8 {
        \\    return "bar";
        \\}
    });

    cases.add("return void",
        \\void foo(void) {
        \\    return;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    return;
        \\}
    });

    cases.add("for loop",
        \\void foo(void) {
        \\    for (int i = 0; i; i++) { }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    {
        \\        var i: c_int = 0;
        \\        while (i != 0) : (i += 1) {}
        \\    }
        \\}
    });

    cases.add("empty for loop",
        \\void foo(void) {
        \\    for (;;) { }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    while (true) {}
        \\}
    });

    cases.add("for loop with simple init expression",
        \\void foo(void) {
        \\    int i;
        \\    for (i = 3; i; i--) { }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var i: c_int = undefined;
        \\    {
        \\        i = 3;
        \\        while (i != 0) : (i -= 1) {}
        \\    }
        \\}
    });

    cases.add("break statement",
        \\void foo(void) {
        \\    for (;;) {
        \\        break;
        \\    }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    while (true) {
        \\        break;
        \\    }
        \\}
    });

    cases.add("continue statement",
        \\void foo(void) {
        \\    for (;;) {
        \\        continue;
        \\    }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    while (true) {
        \\        continue;
        \\    }
        \\}
    });

    cases.add("pointer casting",
        \\float *ptrcast() {
        \\    int *a;
        \\    return (float *)a;
        \\}
    , &[_][]const u8{
        \\pub export fn ptrcast() [*c]f32 {
        \\    var a: [*c]c_int = undefined;
        \\    return @ptrCast([*c]f32, @alignCast(@alignOf(f32), a));
        \\}
    });

    cases.add("pointer conversion with different alignment",
        \\void test_ptr_cast() {
        \\    void *p;
        \\    {
        \\        char *to_char = (char *)p;
        \\        short *to_short = (short *)p;
        \\        int *to_int = (int *)p;
        \\        long long *to_longlong = (long long *)p;
        \\    }
        \\    {
        \\        char *to_char = p;
        \\        short *to_short = p;
        \\        int *to_int = p;
        \\        long long *to_longlong = p;
        \\    }
        \\}
    , &[_][]const u8{
        \\pub export fn test_ptr_cast() void {
        \\    var p: ?*c_void = undefined;
        \\    {
        \\        var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@alignOf(u8), p));
        \\        var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@alignOf(c_short), p));
        \\        var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@alignOf(c_int), p));
        \\        var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@alignOf(c_longlong), p));
        \\    }
        \\    {
        \\        var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@alignOf(u8), p));
        \\        var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@alignOf(c_short), p));
        \\        var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@alignOf(c_int), p));
        \\        var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@alignOf(c_longlong), p));
        \\    }
        \\}
    });

    cases.add("while on non-bool",
        \\int while_none_bool() {
        \\    int a;
        \\    float b;
        \\    void *c;
        \\    while (a) return 0;
        \\    while (b) return 1;
        \\    while (c) return 2;
        \\    return 3;
        \\}
    , &[_][]const u8{
        \\pub export fn while_none_bool() c_int {
        \\    var a: c_int = undefined;
        \\    var b: f32 = undefined;
        \\    var c: ?*c_void = undefined;
        \\    while (a != 0) return 0;
        \\    while (b != 0) return 1;
        \\    while (c != null) return 2;
        \\    return 3;
        \\}
    });

    cases.add("for on non-bool",
        \\int for_none_bool() {
        \\    int a;
        \\    float b;
        \\    void *c;
        \\    for (;a;) return 0;
        \\    for (;b;) return 1;
        \\    for (;c;) return 2;
        \\    return 3;
        \\}
    , &[_][]const u8{
        \\pub export fn for_none_bool() c_int {
        \\    var a: c_int = undefined;
        \\    var b: f32 = undefined;
        \\    var c: ?*c_void = undefined;
        \\    while (a != 0) return 0;
        \\    while (b != 0) return 1;
        \\    while (c != null) return 2;
        \\    return 3;
        \\}
    });

    cases.add("bitshift",
        \\int foo(void) {
        \\    return (1 << 2) >> 1;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    return (@as(c_int, 1) << @intCast(@import("std").math.Log2Int(c_int), 2)) >> @intCast(@import("std").math.Log2Int(c_int), 1);
        \\}
    });

    cases.add("sizeof",
        \\#include <stddef.h>
        \\size_t size_of(void) {
        \\        return sizeof(int);
        \\}
    , &[_][]const u8{
        \\pub export fn size_of() usize {
        \\    return @sizeOf(c_int);
        \\}
    });

    cases.add("normal deref",
        \\void foo() {
        \\    int *x;
        \\    *x = 1;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var x: [*c]c_int = undefined;
        \\    x.?.* = 1;
        \\}
    });

    cases.add("address of operator",
        \\int foo(void) {
        \\    int x = 1234;
        \\    int *ptr = &x;
        \\    return *ptr;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    var x: c_int = 1234;
        \\    var ptr: [*c]c_int = &x;
        \\    return ptr.?.*;
        \\}
    });

    cases.add("bin not",
        \\int foo() {
        \\    int x;
        \\    return ~x;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    var x: c_int = undefined;
        \\    return ~x;
        \\}
    });

    cases.add("bool not",
        \\int foo() {
        \\    int a;
        \\    float b;
        \\    void *c;
        \\    return !(a == 0);
        \\    return !a;
        \\    return !b;
        \\    return !c;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    var a: c_int = undefined;
        \\    var b: f32 = undefined;
        \\    var c: ?*c_void = undefined;
        \\    return @boolToInt(!(a == @as(c_int, 0)));
        \\    return @boolToInt(!(a != 0));
        \\    return @boolToInt(!(b != 0));
        \\    return @boolToInt(!(c != null));
        \\}
    });

    cases.add("__extension__ cast",
        \\int foo(void) {
        \\    return __extension__ 1;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    return 1;
        \\}
    });

    if (std.Target.current.os.tag != .windows) {
        // sysv_abi not currently supported on windows
        cases.add("Macro qualified functions",
            \\void __attribute__((sysv_abi)) foo(void);
        , &[_][]const u8{
            \\pub extern fn foo() void;
        });
    }

    cases.add("Forward-declared enum",
        \\extern enum enum_ty my_enum;
        \\enum enum_ty { FOO };
    , &[_][]const u8{
        \\pub const FOO = @enumToInt(enum_enum_ty.FOO);
        \\pub const enum_enum_ty = extern enum(c_int) {
        \\    FOO,
        \\    _,
        \\};
        \\pub extern var my_enum: enum_enum_ty;
    });

    cases.add("Parameterless function pointers",
        \\typedef void (*fn0)();
        \\typedef void (*fn1)(char);
    , &[_][]const u8{
        \\pub const fn0 = ?fn (...) callconv(.C) void;
        \\pub const fn1 = ?fn (u8) callconv(.C) void;
    });

    cases.addWithTarget("Calling convention", .{
        .cpu_arch = .i386,
        .os_tag = .linux,
        .abi = .none,
    },
        \\void __attribute__((fastcall)) foo1(float *a);
        \\void __attribute__((stdcall)) foo2(float *a);
        \\void __attribute__((vectorcall)) foo3(float *a);
        \\void __attribute__((cdecl)) foo4(float *a);
        \\void __attribute__((thiscall)) foo5(float *a);
    , &[_][]const u8{
        \\pub extern fn foo1(a: [*c]f32) callconv(.Fastcall) void;
        \\pub extern fn foo2(a: [*c]f32) callconv(.Stdcall) void;
        \\pub extern fn foo3(a: [*c]f32) callconv(.Vectorcall) void;
        \\pub extern fn foo4(a: [*c]f32) void;
        \\pub extern fn foo5(a: [*c]f32) callconv(.Thiscall) void;
    });

    cases.addWithTarget("Calling convention", CrossTarget.parse(.{
        .arch_os_abi = "arm-linux-none",
        .cpu_features = "generic+v8_5a",
    }) catch unreachable,
        \\void __attribute__((pcs("aapcs"))) foo1(float *a);
        \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
    , &[_][]const u8{
        \\pub extern fn foo1(a: [*c]f32) callconv(.AAPCS) void;
        \\pub extern fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
    });

    cases.addWithTarget("Calling convention", CrossTarget.parse(.{
        .arch_os_abi = "aarch64-linux-none",
        .cpu_features = "generic+v8_5a",
    }) catch unreachable,
        \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
    , &[_][]const u8{
        \\pub extern fn foo1(a: [*c]f32) callconv(.Vectorcall) void;
    });

    cases.add("Parameterless function prototypes",
        \\void a() {}
        \\void b(void) {}
        \\void c();
        \\void d(void);
        \\static void e() {}
        \\static void f(void) {}
        \\static void g();
        \\static void h(void);
    , &[_][]const u8{
        \\pub export fn a() void {}
        \\pub export fn b() void {}
        \\pub extern fn c(...) void;
        \\pub extern fn d() void;
        \\pub fn e() callconv(.C) void {}
        \\pub fn f() callconv(.C) void {}
        \\pub extern fn g() void;
        \\pub extern fn h() void;
    });

    cases.add("variable declarations",
        \\extern char arr0[] = "hello";
        \\static char arr1[] = "hello";
        \\char arr2[] = "hello";
    , &[_][]const u8{
        \\pub export var arr0: [6]u8 = [6]u8{
        \\    'h',
        \\    'e',
        \\    'l',
        \\    'l',
        \\    'o',
        \\    0,
        \\};
        \\pub var arr1: [6]u8 = [6]u8{
        \\    'h',
        \\    'e',
        \\    'l',
        \\    'l',
        \\    'o',
        \\    0,
        \\};
        \\pub export var arr2: [6]u8 = [6]u8{
        \\    'h',
        \\    'e',
        \\    'l',
        \\    'l',
        \\    'o',
        \\    0,
        \\};
    });

    cases.add("array initializer expr",
        \\static void foo(void){
        \\    char arr[10] ={1};
        \\    char *arr1[10] ={0};
        \\}
    , &[_][]const u8{
        \\pub fn foo() callconv(.C) void {
        \\    var arr: [10]u8 = [1]u8{
        \\        @bitCast(u8, @truncate(i8, @as(c_int, 1))),
        \\    } ++ [1]u8{0} ** 9;
        \\    var arr1: [10][*c]u8 = [1][*c]u8{
        \\        null,
        \\    } ++ [1][*c]u8{null} ** 9;
        \\}
    });

    cases.add("enums",
        \\typedef enum {
        \\    a,
        \\    b,
        \\    c,
        \\} d;
        \\enum {
        \\    e,
        \\    f = 4,
        \\    g,
        \\} h = e;
        \\struct Baz {
        \\    enum {
        \\        i,
        \\        j,
        \\        k,
        \\    } l;
        \\    d m;
        \\};
        \\enum i {
        \\    n,
        \\    o,
        \\    p,
        \\};
    , &[_][]const u8{
        \\pub const a = @enumToInt(enum_unnamed_1.a);
        \\pub const b = @enumToInt(enum_unnamed_1.b);
        \\pub const c = @enumToInt(enum_unnamed_1.c);
        \\const enum_unnamed_1 = extern enum(c_int) {
        \\    a,
        \\    b,
        \\    c,
        \\    _,
        \\};
        \\pub const d = enum_unnamed_1;
        \\pub const e = @enumToInt(enum_unnamed_2.e);
        \\pub const f = @enumToInt(enum_unnamed_2.f);
        \\pub const g = @enumToInt(enum_unnamed_2.g);
        \\const enum_unnamed_2 = extern enum(c_int) {
        \\    e = 0,
        \\    f = 4,
        \\    g = 5,
        \\    _,
        \\};
        \\pub export var h: enum_unnamed_2 = @intToEnum(enum_unnamed_2, e);
        \\pub const i = @enumToInt(enum_unnamed_3.i);
        \\pub const j = @enumToInt(enum_unnamed_3.j);
        \\pub const k = @enumToInt(enum_unnamed_3.k);
        \\const enum_unnamed_3 = extern enum(c_int) {
        \\    i,
        \\    j,
        \\    k,
        \\    _,
        \\};
        \\pub const struct_Baz = extern struct {
        \\    l: enum_unnamed_3,
        \\    m: d,
        \\};
        \\pub const n = @enumToInt(enum_i.n);
        \\pub const o = @enumToInt(enum_i.o);
        \\pub const p = @enumToInt(enum_i.p);
        \\pub const enum_i = extern enum(c_int) {
        \\    n,
        \\    o,
        \\    p,
        \\    _,
        \\};
        ,
        \\pub const Baz = struct_Baz;
    });

    cases.add("#define a char literal",
        \\#define A_CHAR  'a'
    , &[_][]const u8{
        \\pub const A_CHAR = 'a';
    });

    cases.add("comment after integer literal",
        \\#define SDL_INIT_VIDEO 0x00000020  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = 0x00000020;
    });

    cases.add("u integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020u  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_uint, 0x00000020);
    });

    cases.add("l integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020l  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_long, 0x00000020);
    });

    cases.add("ul integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020ul  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_ulong, 0x00000020);
    });

    cases.add("lu integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020lu  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_ulong, 0x00000020);
    });

    cases.add("ll integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020ll  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_longlong, 0x00000020);
    });

    cases.add("ull integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020ull  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 0x00000020);
    });

    cases.add("llu integer suffix after hex literal",
        \\#define SDL_INIT_VIDEO 0x00000020llu  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    , &[_][]const u8{
        \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 0x00000020);
    });

    cases.add("generate inline func for #define global extern fn",
        \\extern void (*fn_ptr)(void);
        \\#define foo fn_ptr
        \\
        \\extern char (*fn_ptr2)(int, float);
        \\#define bar fn_ptr2
    , &[_][]const u8{
        \\pub extern var fn_ptr: ?fn () callconv(.C) void;
        ,
        \\pub inline fn foo() void {
        \\    return fn_ptr.?();
        \\}
        ,
        \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;
        ,
        \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
        \\    return fn_ptr2.?(arg_1, arg_2);
        \\}
    });

    cases.add("macros with field targets",
        \\typedef unsigned int GLbitfield;
        \\typedef void (*PFNGLCLEARPROC) (GLbitfield mask);
        \\typedef void(*OpenGLProc)(void);
        \\union OpenGLProcs {
        \\    OpenGLProc ptr[1];
        \\    struct {
        \\        PFNGLCLEARPROC Clear;
        \\    } gl;
        \\};
        \\extern union OpenGLProcs glProcs;
        \\#define glClearUnion glProcs.gl.Clear
        \\#define glClearPFN PFNGLCLEARPROC
    , &[_][]const u8{
        \\pub const GLbitfield = c_uint;
        \\pub const PFNGLCLEARPROC = ?fn (GLbitfield) callconv(.C) void;
        \\pub const OpenGLProc = ?fn () callconv(.C) void;
        \\const struct_unnamed_1 = extern struct {
        \\    Clear: PFNGLCLEARPROC,
        \\};
        \\pub const union_OpenGLProcs = extern union {
        \\    ptr: [1]OpenGLProc,
        \\    gl: struct_unnamed_1,
        \\};
        \\pub extern var glProcs: union_OpenGLProcs;
        ,
        \\pub const glClearPFN = PFNGLCLEARPROC;
        ,
        \\pub inline fn glClearUnion(arg_2: GLbitfield) void {
        \\    return glProcs.gl.Clear.?(arg_2);
        \\}
        ,
        \\pub const OpenGLProcs = union_OpenGLProcs;
    });

    cases.add("macro pointer cast",
        \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
    , &[_][]const u8{
        \\pub const NRF_GPIO = (@import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE));
    });

    cases.add("basic macro function",
        \\extern int c;
        \\#define BASIC(c) (c*2)
        \\#define FOO(L,b) (L + b)
        \\#define BAR() (c*c)
    , &[_][]const u8{
        \\pub extern var c: c_int;
        ,
        \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * 2) {
        \\    return c_1 * 2;
        \\}
        ,
        \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) {
        \\    return L + b;
        \\}
        ,
        \\pub inline fn BAR() @TypeOf(c * c) {
        \\    return c * c;
        \\}
    });

    cases.add("macro defines string literal with hex",
        \\#define FOO "aoeu\xab derp"
        \\#define FOO2 "aoeu\x0007a derp"
        \\#define FOO_CHAR '\xfF'
    , &[_][]const u8{
        \\pub const FOO = "aoeu\xab derp";
        ,
        \\pub const FOO2 = "aoeu\x7a derp";
        ,
        \\pub const FOO_CHAR = '\xff';
    });

    cases.add("macro add",
        \\#define PERIPH_BASE               (0x40000000UL) /*!< Base address of : AHB/APB Peripherals                                                   */
        \\#define D3_APB1PERIPH_BASE       (PERIPH_BASE + 0x18000000UL)
        \\#define RCC_BASE              (D3_AHB1PERIPH_BASE + 0x4400UL)
    , &[_][]const u8{
        \\pub const PERIPH_BASE = @as(c_ulong, 0x40000000);
        ,
        \\pub const D3_APB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18000000);
        ,
        \\pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400);
    });

    cases.add("variable aliasing",
        \\static long a = 2;
        \\static long b = 2;
        \\static int c = 4;
        \\void foo(char c) {
        \\    int a;
        \\    char b = 123;
        \\    b = (char) a;
        \\    {
        \\        int d = 5;
        \\    }
        \\    unsigned d = 440;
        \\}
    , &[_][]const u8{
        \\pub var a: c_long = @bitCast(c_long, @as(c_long, @as(c_int, 2)));
        \\pub var b: c_long = @bitCast(c_long, @as(c_long, @as(c_int, 2)));
        \\pub var c: c_int = 4;
        \\pub export fn foo(arg_c_1: u8) void {
        \\    var c_1 = arg_c_1;
        \\    var a_2: c_int = undefined;
        \\    var b_3: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 123)));
        \\    b_3 = @bitCast(u8, @truncate(i8, a_2));
        \\    {
        \\        var d: c_int = 5;
        \\    }
        \\    var d: c_uint = @bitCast(c_uint, @as(c_int, 440));
        \\}
    });

    cases.add("comma operator",
        \\int foo() {
        \\    2, 4;
        \\    return 2, 4, 6;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    _ = (blk: {
        \\        _ = @as(c_int, 2);
        \\        break :blk @as(c_int, 4);
        \\    });
        \\    return (blk: {
        \\        _ = (blk_1: {
        \\            _ = @as(c_int, 2);
        \\            break :blk_1 @as(c_int, 4);
        \\        });
        \\        break :blk @as(c_int, 6);
        \\    });
        \\}
    });

    cases.add("worst-case assign",
        \\void foo() {
        \\    int a;
        \\    int b;
        \\    a = b = 2;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = undefined;
        \\    var b: c_int = undefined;
        \\    a = blk: {
        \\        const tmp = @as(c_int, 2);
        \\        b = tmp;
        \\        break :blk tmp;
        \\    };
        \\}
    });

    cases.add("while loops",
        \\int foo() {
        \\    int a = 5;
        \\    while (2)
        \\        a = 2;
        \\    while (4) {
        \\        int a = 4;
        \\        a = 9;
        \\        return 6, a;
        \\    }
        \\    do {
        \\        int a = 2;
        \\        a = 12;
        \\    } while (4);
        \\    do
        \\        a = 7;
        \\    while (4);
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    var a: c_int = 5;
        \\    while (true) a = 2;
        \\    while (true) {
        \\        var a_1: c_int = 4;
        \\        a_1 = 9;
        \\        return (blk: {
        \\            _ = @as(c_int, 6);
        \\            break :blk a_1;
        \\        });
        \\    }
        \\    while (true) {
        \\        var a_1: c_int = 2;
        \\        a_1 = 12;
        \\        if (!true) break;
        \\    }
        \\    while (true) {
        \\        a = 7;
        \\        if (!true) break;
        \\    }
        \\    return 0;
        \\}
    });

    cases.add("for loops",
        \\void foo() {
        \\    for (int i = 2, b = 4; i + 2; i = 2) {
        \\        int a = 2;
        \\        a = 6, 5, 7;
        \\    }
        \\    char i = 2;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    {
        \\        var i: c_int = 2;
        \\        var b: c_int = 4;
        \\        while ((i + @as(c_int, 2)) != 0) : (i = 2) {
        \\            var a: c_int = 2;
        \\            _ = (blk: {
        \\                _ = (blk_1: {
        \\                    a = 6;
        \\                    break :blk_1 @as(c_int, 5);
        \\                });
        \\                break :blk @as(c_int, 7);
        \\            });
        \\        }
        \\    }
        \\    var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2)));
        \\}
    });

    cases.add("shadowing primitive types",
        \\unsigned anyerror = 2;
        \\#define noreturn _Noreturn
    , &[_][]const u8{
        \\pub export var anyerror_1: c_uint = @bitCast(c_uint, @as(c_int, 2));
        ,
        \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");
    });

    cases.add("floats",
        \\float a = 3.1415;
        \\double b = 3.1415;
        \\int c = 3.1415;
        \\double d = 3;
    , &[_][]const u8{
        \\pub export var a: f32 = @floatCast(f32, 3.1415);
        \\pub export var b: f64 = 3.1415;
        \\pub export var c: c_int = @floatToInt(c_int, 3.1415);
        \\pub export var d: f64 = @intToFloat(f64, @as(c_int, 3));
    });

    cases.add("conditional operator",
        \\int bar(void) {
        \\    if (2 ? 5 : 5 ? 4 : 6) 2;
        \\    return  2 ? 5 : 5 ? 4 : 6;
        \\}
    , &[_][]const u8{
        \\pub export fn bar() c_int {
        \\    if ((if (true) @as(c_int, 5) else (if (true) @as(c_int, 4) else @as(c_int, 6))) != 0) _ = @as(c_int, 2);
        \\    return if (true) @as(c_int, 5) else if (true) @as(c_int, 4) else @as(c_int, 6);
        \\}
    });

    cases.add("switch on int",
        \\void switch_fn(int i) {
        \\    int res = 0;
        \\    switch (i) {
        \\        case 0:
        \\            res = 1;
        \\        case 1 ... 3:
        \\            res = 2;
        \\        default:
        \\            res = 3 * i;
        \\            break;
        \\        case 4:
        \\            res = 5;
        \\    }
        \\}
    , &[_][]const u8{
        \\pub export fn switch_fn(arg_i: c_int) void {
        \\    var i = arg_i;
        \\    var res: c_int = 0;
        \\    @"switch": {
        \\        case_2: {
        \\            default: {
        \\                case_1: {
        \\                    case: {
        \\                        switch (i) {
        \\                            @as(c_int, 0) => break :case,
        \\                            @as(c_int, 1)...@as(c_int, 3) => break :case_1,
        \\                            else => break :default,
        \\                            @as(c_int, 4) => break :case_2,
        \\                        }
        \\                    }
        \\                    res = 1;
        \\                }
        \\                res = 2;
        \\            }
        \\            res = (@as(c_int, 3) * i);
        \\            break :@"switch";
        \\        }
        \\        res = 5;
        \\    }
        \\}
    });

    if (std.Target.current.os.tag != .windows) {
        // When clang uses the <arch>-windows-none triple it behaves as MSVC and
        // interprets the inner `struct Bar` as an anonymous structure
        cases.add("type referenced struct",
            \\struct Foo {
            \\    struct Bar{
            \\        int b;
            \\    };
            \\    struct Bar c;
            \\};
        , &[_][]const u8{
            \\pub const struct_Bar = extern struct {
            \\    b: c_int,
            \\};
            \\pub const struct_Foo = extern struct {
            \\    c: struct_Bar,
            \\};
        });
    }

    cases.add("undefined array global",
        \\int array[100] = {};
    , &[_][]const u8{
        \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
    });

    cases.add("restrict -> noalias",
        \\void foo(void *restrict bar, void *restrict);
    , &[_][]const u8{
        \\pub extern fn foo(noalias bar: ?*c_void, noalias ?*c_void) void;
    });

    cases.add("assign",
        \\void max(int a) {
        \\    int tmp;
        \\    tmp = a;
        \\    a = tmp;
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int) void {
        \\    var a = arg_a;
        \\    var tmp: c_int = undefined;
        \\    tmp = a;
        \\    a = tmp;
        \\}
    });

    cases.add("chaining assign",
        \\void max(int a) {
        \\    int b, c;
        \\    c = b = a;
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int) void {
        \\    var a = arg_a;
        \\    var b: c_int = undefined;
        \\    var c: c_int = undefined;
        \\    c = blk: {
        \\        const tmp = a;
        \\        b = tmp;
        \\        break :blk tmp;
        \\    };
        \\}
    });

    cases.add("anonymous enum",
        \\enum {
        \\    One,
        \\    Two,
        \\};
    , &[_][]const u8{
        \\pub const One = @enumToInt(enum_unnamed_1.One);
        \\pub const Two = @enumToInt(enum_unnamed_1.Two);
        \\const enum_unnamed_1 = extern enum(c_int) {
        \\    One,
        \\    Two,
        \\    _,
        \\};
    });

    cases.add("c style cast",
        \\int float_to_int(float a) {
        \\    return (int)a;
        \\}
    , &[_][]const u8{
        \\pub export fn float_to_int(arg_a: f32) c_int {
        \\    var a = arg_a;
        \\    return @floatToInt(c_int, a);
        \\}
    });

    // TODO translate-c should in theory be able to figure out to drop all these casts
    cases.add("escape sequences",
        \\const char *escapes() {
        \\char a = '\'',
        \\    b = '\\',
        \\    c = '\a',
        \\    d = '\b',
        \\    e = '\f',
        \\    f = '\n',
        \\    g = '\r',
        \\    h = '\t',
        \\    i = '\v',
        \\    j = '\0',
        \\    k = '\"';
        \\    return "\'\\\a\b\f\n\r\t\v\0\"";
        \\}
        \\
    , &[_][]const u8{
        \\pub export fn escapes() [*c]const u8 {
        \\    var a: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\'')));
        \\    var b: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\\')));
        \\    var c: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x07')));
        \\    var d: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x08')));
        \\    var e: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x0c')));
        \\    var f: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\n')));
        \\    var g: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\r')));
        \\    var h: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\t')));
        \\    var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x0b')));
        \\    var j: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x00')));
        \\    var k: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\"')));
        \\    return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
        \\}
    });

    cases.add("do loop",
        \\void foo(void) {
        \\    int a = 2;
        \\    do {
        \\        a = a - 1;
        \\    } while (a);
        \\
        \\    int b = 2;
        \\    do
        \\        b = b -1;
        \\    while (b);
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = 2;
        \\    while (true) {
        \\        a = (a - @as(c_int, 1));
        \\        if (!(a != 0)) break;
        \\    }
        \\    var b: c_int = 2;
        \\    while (true) {
        \\        b = (b - @as(c_int, 1));
        \\        if (!(b != 0)) break;
        \\    }
        \\}
    });

    cases.add("logical and, logical or, on non-bool values, extra parens",
        \\enum Foo {
        \\    FooA,
        \\    FooB,
        \\    FooC,
        \\};
        \\typedef int SomeTypedef;
        \\int and_or_non_bool(int a, float b, void *c) {
        \\    enum Foo d = FooA;
        \\    int e = (a && b);
        \\    int f = (b && c);
        \\    int g = (a && c);
        \\    int h = (a || b);
        \\    int i = (b || c);
        \\    int j = (a || c);
        \\    int k = (a || (int)d);
        \\    int l = ((int)d && b);
        \\    int m = (c || (unsigned int)d);
        \\    SomeTypedef td = 44;
        \\    int o = (td || b);
        \\    int p = (c && td);
        \\    return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
        \\}
    , &[_][]const u8{
        \\pub const enum_Foo = extern enum(c_int) {
        \\    A,
        \\    B,
        \\    C,
        \\    _,
        \\};
        \\pub const SomeTypedef = c_int;
        \\pub export fn and_or_non_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    var c = arg_c;
        \\    var d: enum_Foo = @intToEnum(enum_Foo, FooA);
        \\    var e: c_int = @boolToInt(((a != 0) and (b != 0)));
        \\    var f: c_int = @boolToInt(((b != 0) and (c != null)));
        \\    var g: c_int = @boolToInt(((a != 0) and (c != null)));
        \\    var h: c_int = @boolToInt(((a != 0) or (b != 0)));
        \\    var i: c_int = @boolToInt(((b != 0) or (c != null)));
        \\    var j: c_int = @boolToInt(((a != 0) or (c != null)));
        \\    var k: c_int = @boolToInt(((a != 0) or (@bitCast(c_int, @enumToInt(d)) != 0)));
        \\    var l: c_int = @boolToInt(((@bitCast(c_int, @enumToInt(d)) != 0) and (b != 0)));
        \\    var m: c_int = @boolToInt(((c != null) or (@bitCast(c_uint, @enumToInt(d)) != 0)));
        \\    var td: SomeTypedef = 44;
        \\    var o: c_int = @boolToInt(((td != 0) or (b != 0)));
        \\    var p: c_int = @boolToInt(((c != null) and (td != 0)));
        \\    return ((((((((((e + f) + g) + h) + i) + j) + k) + l) + m) + o) + p);
        \\}
        ,
        \\pub const Foo = enum_Foo;
    });

    cases.add("qualified struct and enum",
        \\struct Foo {
        \\    int x;
        \\    int y;
        \\};
        \\enum Bar {
        \\    BarA,
        \\    BarB,
        \\};
        \\void func(struct Foo *a, enum Bar **b);
    , &[_][]const u8{
        \\pub const struct_Foo = extern struct {
        \\    x: c_int,
        \\    y: c_int,
        \\};
        ,
        \\pub const enum_Bar = extern enum(c_int) {
        \\    A,
        \\    B,
        \\    _,
        \\};
        \\pub extern fn func(a: [*c]struct_Foo, b: [*c][*c]enum_Bar) void;
        ,
        \\pub const Foo = struct_Foo;
        \\pub const Bar = enum_Bar;
    });

    cases.add("bitwise binary operators, simpler parens",
        \\int max(int a, int b) {
        \\    return (a & b) ^ (a | b);
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    return ((a & b) ^ (a | b));
        \\}
    });

    cases.add("comparison operators (no if)", // TODO Come up with less contrived tests? Make sure to cover all these comparisons.
        \\int test_comparisons(int a, int b) {
        \\    int c = (a < b);
        \\    int d = (a > b);
        \\    int e = (a <= b);
        \\    int f = (a >= b);
        \\    int g = (c < d);
        \\    int h = (e < f);
        \\    int i = (g < h);
        \\    return i;
        \\}
    , &[_][]const u8{
        \\pub export fn test_comparisons(arg_a: c_int, arg_b: c_int) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    var c: c_int = @boolToInt((a < b));
        \\    var d: c_int = @boolToInt((a > b));
        \\    var e: c_int = @boolToInt((a <= b));
        \\    var f: c_int = @boolToInt((a >= b));
        \\    var g: c_int = @boolToInt((c < d));
        \\    var h: c_int = @boolToInt((e < f));
        \\    var i: c_int = @boolToInt((g < h));
        \\    return i;
        \\}
    });

    cases.add("==, !=",
        \\int max(int a, int b) {
        \\    if (a == b)
        \\        return a;
        \\    if (a != b)
        \\        return b;
        \\    return a;
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    if (a == b) return a;
        \\    if (a != b) return b;
        \\    return a;
        \\}
    });

    cases.add("typedeffed bool expression",
        \\typedef char* yes;
        \\void foo(void) {
        \\    yes a;
        \\    if (a) 2;
        \\}
    , &[_][]const u8{
        \\pub const yes = [*c]u8;
        \\pub export fn foo() void {
        \\    var a: yes = undefined;
        \\    if (a != null) _ = @as(c_int, 2);
        \\}
    });

    cases.add("statement expression",
        \\int foo(void) {
        \\    return ({
        \\        int a = 1;
        \\        a;
        \\        a;
        \\    });
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_int {
        \\    return (blk: {
        \\        var a: c_int = 1;
        \\        _ = a;
        \\        break :blk a;
        \\    });
        \\}
    });

    cases.add("field access expression",
        \\#define ARROW a->b
        \\#define DOT a.b
        \\extern struct Foo {
        \\    int b;
        \\}a;
        \\float b = 2.0f;
        \\void foo(void) {
        \\    struct Foo *c;
        \\    a.b;
        \\    c->b;
        \\}
    , &[_][]const u8{
        \\pub const struct_Foo = extern struct {
        \\    b: c_int,
        \\};
        \\pub extern var a: struct_Foo;
        \\pub export var b: f32 = 2;
        \\pub export fn foo() void {
        \\    var c: [*c]struct_Foo = undefined;
        \\    _ = a.b;
        \\    _ = c.*.b;
        \\}
        ,
        \\pub const DOT = a.b;
        ,
        \\pub const ARROW = a.*.b;
    });

    cases.add("array access",
        \\#define ACCESS array[2]
        \\int array[100] = {};
        \\int foo(int index) {
        \\    return array[index];
        \\}
    , &[_][]const u8{
        \\pub export var array: [100]c_int = [1]c_int{0} ** 100;
        \\pub export fn foo(arg_index: c_int) c_int {
        \\    var index = arg_index;
        \\    return array[@intCast(c_uint, index)];
        \\}
        ,
        \\pub const ACCESS = array[2];
    });

    cases.add("cast signed array index to unsigned",
        \\void foo() {
        \\  int a[10], i = 0;
        \\  a[i] = 0;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: [10]c_int = undefined;
        \\    var i: c_int = 0;
        \\    a[@intCast(c_uint, i)] = 0;
        \\}
    });

    cases.add("long long array index cast to usize",
        \\void foo() {
        \\  long long a[10], i = 0;
        \\  a[i] = 0;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: [10]c_longlong = undefined;
        \\    var i: c_longlong = @bitCast(c_longlong, @as(c_longlong, @as(c_int, 0)));
        \\    a[@intCast(usize, i)] = @bitCast(c_longlong, @as(c_longlong, @as(c_int, 0)));
        \\}
    });

    cases.add("unsigned array index skips cast",
        \\void foo() {
        \\  unsigned int a[10], i = 0;
        \\  a[i] = 0;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: [10]c_uint = undefined;
        \\    var i: c_uint = @bitCast(c_uint, @as(c_int, 0));
        \\    a[i] = @bitCast(c_uint, @as(c_int, 0));
        \\}
    });

    cases.add("macro call",
        \\#define CALL(arg) bar(arg)
    , &[_][]const u8{
        \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) {
        \\    return bar(arg);
        \\}
    });

    cases.add("logical and, logical or",
        \\int max(int a, int b) {
        \\    if (a < b || a == b)
        \\        return b;
        \\    if (a >= b && a == b)
        \\        return a;
        \\    return a;
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    if ((a < b) or (a == b)) return b;
        \\    if ((a >= b) and (a == b)) return a;
        \\    return a;
        \\}
    });

    cases.add("simple if statement",
        \\int max(int a, int b) {
        \\    if (a < b)
        \\        return b;
        \\
        \\    if (a < b)
        \\        return b;
        \\    else
        \\        return a;
        \\
        \\    if (a < b) ; else ;
        \\}
    , &[_][]const u8{
        \\pub export fn max(arg_a: c_int, arg_b: c_int) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    if (a < b) return b;
        \\    if (a < b) return b else return a;
        \\    if (a < b) {} else {}
        \\    return 0;
        \\}
    });

    cases.add("if statements",
        \\void foo() {
        \\    if (2) {
        \\        int a = 2;
        \\    }
        \\    if (2, 5) {
        \\        int a = 2;
        \\    }
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    if (true) {
        \\        var a: c_int = 2;
        \\    }
        \\    if ((blk: {
        \\        _ = @as(c_int, 2);
        \\        break :blk @as(c_int, 5);
        \\    }) != 0) {
        \\        var a: c_int = 2;
        \\    }
        \\}
    });

    cases.add("if on non-bool",
        \\enum SomeEnum { A, B, C };
        \\int if_none_bool(int a, float b, void *c, enum SomeEnum d) {
        \\    if (a) return 0;
        \\    if (b) return 1;
        \\    if (c) return 2;
        \\    if (d) return 3;
        \\    return 4;
        \\}
    , &[_][]const u8{
        \\pub const enum_SomeEnum = extern enum(c_int) {
        \\    A,
        \\    B,
        \\    C,
        \\    _,
        \\};
        \\pub export fn if_none_bool(arg_a: c_int, arg_b: f32, arg_c: ?*c_void, arg_d: enum_SomeEnum) c_int {
        \\    var a = arg_a;
        \\    var b = arg_b;
        \\    var c = arg_c;
        \\    var d = arg_d;
        \\    if (a != 0) return 0;
        \\    if (b != 0) return 1;
        \\    if (c != null) return 2;
        \\    if (d != 0) return 3;
        \\    return 4;
        \\}
    });

    cases.add("simple data types",
        \\#include <stdint.h>
        \\int foo(char a, unsigned char b, signed char c);
        \\int foo(char a, unsigned char b, signed char c); // test a duplicate prototype
        \\void bar(uint8_t a, uint16_t b, uint32_t c, uint64_t d);
        \\void baz(int8_t a, int16_t b, int32_t c, int64_t d);
    , &[_][]const u8{
        \\pub extern fn foo(a: u8, b: u8, c: i8) c_int;
        \\pub extern fn bar(a: u8, b: u16, c: u32, d: u64) void;
        \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64) void;
    });

    cases.add("simple function",
        \\int abs(int a) {
        \\    return a < 0 ? -a : a;
        \\}
    , &[_][]const u8{
        \\pub export fn abs(arg_a: c_int) c_int {
        \\    var a = arg_a;
        \\    return if (a < @as(c_int, 0)) -a else a;
        \\}
    });

    cases.add("post increment",
        \\unsigned foo1(unsigned a) {
        \\    a++;
        \\    return a;
        \\}
        \\int foo2(int a) {
        \\    a++;
        \\    return a;
        \\}
        \\int *foo3(int *a) {
        \\    a++;
        \\    return a;
        \\}
    , &[_][]const u8{
        \\pub export fn foo1(arg_a: c_uint) c_uint {
        \\    var a = arg_a;
        \\    a +%= 1;
        \\    return a;
        \\}
        \\pub export fn foo2(arg_a: c_int) c_int {
        \\    var a = arg_a;
        \\    a += 1;
        \\    return a;
        \\}
        \\pub export fn foo3(arg_a: [*c]c_int) [*c]c_int {
        \\    var a = arg_a;
        \\    a += 1;
        \\    return a;
        \\}
    });

    cases.add("deref function pointer",
        \\void foo(void) {}
        \\int baz(void) { return 0; }
        \\void bar(void) {
        \\    void(*f)(void) = foo;
        \\    int(*b)(void) = baz;
        \\    f();
        \\    (*(f))();
        \\    foo();
        \\    b();
        \\    (*(b))();
        \\    baz();
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {}
        \\pub export fn baz() c_int {
        \\    return 0;
        \\}
        \\pub export fn bar() void {
        \\    var f: ?fn () callconv(.C) void = foo;
        \\    var b: ?fn () callconv(.C) c_int = baz;
        \\    f.?();
        \\    (f).?();
        \\    foo();
        \\    _ = b.?();
        \\    _ = (b).?();
        \\    _ = baz();
        \\}
    });

    cases.add("pre increment/decrement",
        \\void foo(void) {
        \\    int i = 0;
        \\    unsigned u = 0;
        \\    ++i;
        \\    --i;
        \\    ++u;
        \\    --u;
        \\    i = ++i;
        \\    i = --i;
        \\    u = ++u;
        \\    u = --u;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var i: c_int = 0;
        \\    var u: c_uint = @bitCast(c_uint, @as(c_int, 0));
        \\    i += 1;
        \\    i -= 1;
        \\    u +%= 1;
        \\    u -%= 1;
        \\    i = (blk: {
        \\        const ref = &i;
        \\        ref.* += 1;
        \\        break :blk ref.*;
        \\    });
        \\    i = (blk: {
        \\        const ref = &i;
        \\        ref.* -= 1;
        \\        break :blk ref.*;
        \\    });
        \\    u = (blk: {
        \\        const ref = &u;
        \\        ref.* +%= 1;
        \\        break :blk ref.*;
        \\    });
        \\    u = (blk: {
        \\        const ref = &u;
        \\        ref.* -%= 1;
        \\        break :blk ref.*;
        \\    });
        \\}
    });

    cases.add("shift right assign",
        \\int log2(unsigned a) {
        \\    int i = 0;
        \\    while (a > 0) {
        \\        a >>= 1;
        \\    }
        \\    return i;
        \\}
    , &[_][]const u8{
        \\pub export fn log2(arg_a: c_uint) c_int {
        \\    var a = arg_a;
        \\    var i: c_int = 0;
        \\    while (a > @bitCast(c_uint, @as(c_int, 0))) {
        \\        a >>= @intCast(@import("std").math.Log2Int(c_int), 1);
        \\    }
        \\    return i;
        \\}
    });

    cases.add("shift right assign with a fixed size type",
        \\#include <stdint.h>
        \\int log2(uint32_t a) {
        \\    int i = 0;
        \\    while (a > 0) {
        \\        a >>= 1;
        \\    }
        \\    return i;
        \\}
    , &[_][]const u8{
        \\pub export fn log2(arg_a: u32) c_int {
        \\    var a = arg_a;
        \\    var i: c_int = 0;
        \\    while (a > @bitCast(c_uint, @as(c_int, 0))) {
        \\        a >>= @intCast(@import("std").math.Log2Int(c_int), 1);
        \\    }
        \\    return i;
        \\}
    });

    cases.add("compound assignment operators",
        \\void foo(void) {
        \\    int a = 0;
        \\    unsigned b = 0;
        \\    a += (a += 1);
        \\    a -= (a -= 1);
        \\    a *= (a *= 1);
        \\    a &= (a &= 1);
        \\    a |= (a |= 1);
        \\    a ^= (a ^= 1);
        \\    a >>= (a >>= 1);
        \\    a <<= (a <<= 1);
        \\    a /= (a /= 1);
        \\    a %= (a %= 1);
        \\    b /= (b /= 1);
        \\    b %= (b %= 1);
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_int = 0;
        \\    var b: c_uint = @bitCast(c_uint, @as(c_int, 0));
        \\    a += (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* + @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a -= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* - @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a *= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* * @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a &= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* & @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a |= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* | @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a ^= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* ^ @as(c_int, 1);
        \\        break :blk ref.*;
        \\    });
        \\    a >>= @intCast(@import("std").math.Log2Int(c_int), (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\    a <<= @intCast(@import("std").math.Log2Int(c_int), (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\    a = @divTrunc(a, (blk: {
        \\        const ref = &a;
        \\        ref.* = @divTrunc(ref.*, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\    a = @rem(a, (blk: {
        \\        const ref = &a;
        \\        ref.* = @rem(ref.*, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\    b /= (blk: {
        \\        const ref = &b;
        \\        ref.* = ref.* / @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    b %= (blk: {
        \\        const ref = &b;
        \\        ref.* = ref.* % @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\}
    });

    cases.add("compound assignment operators unsigned",
        \\void foo(void) {
        \\    unsigned a = 0;
        \\    a += (a += 1);
        \\    a -= (a -= 1);
        \\    a *= (a *= 1);
        \\    a &= (a &= 1);
        \\    a |= (a |= 1);
        \\    a ^= (a ^= 1);
        \\    a >>= (a >>= 1);
        \\    a <<= (a <<= 1);
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var a: c_uint = @bitCast(c_uint, @as(c_int, 0));
        \\    a +%= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* +% @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a -%= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* -% @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a *%= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* *% @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a &= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* & @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a |= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* | @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a ^= (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* ^ @bitCast(c_uint, @as(c_int, 1));
        \\        break :blk ref.*;
        \\    });
        \\    a >>= @intCast(@import("std").math.Log2Int(c_uint), (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* >> @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\    a <<= @intCast(@import("std").math.Log2Int(c_uint), (blk: {
        \\        const ref = &a;
        \\        ref.* = ref.* << @intCast(@import("std").math.Log2Int(c_int), @as(c_int, 1));
        \\        break :blk ref.*;
        \\    }));
        \\}
    });

    cases.add("post increment/decrement",
        \\void foo(void) {
        \\    int i = 0;
        \\    unsigned u = 0;
        \\    i++;
        \\    i--;
        \\    u++;
        \\    u--;
        \\    i = i++;
        \\    i = i--;
        \\    u = u++;
        \\    u = u--;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() void {
        \\    var i: c_int = 0;
        \\    var u: c_uint = @bitCast(c_uint, @as(c_int, 0));
        \\    i += 1;
        \\    i -= 1;
        \\    u +%= 1;
        \\    u -%= 1;
        \\    i = (blk: {
        \\        const ref = &i;
        \\        const tmp = ref.*;
        \\        ref.* += 1;
        \\        break :blk tmp;
        \\    });
        \\    i = (blk: {
        \\        const ref = &i;
        \\        const tmp = ref.*;
        \\        ref.* -= 1;
        \\        break :blk tmp;
        \\    });
        \\    u = (blk: {
        \\        const ref = &u;
        \\        const tmp = ref.*;
        \\        ref.* +%= 1;
        \\        break :blk tmp;
        \\    });
        \\    u = (blk: {
        \\        const ref = &u;
        \\        const tmp = ref.*;
        \\        ref.* -%= 1;
        \\        break :blk tmp;
        \\    });
        \\}
    });

    cases.add("implicit casts",
        \\#include <stdbool.h>
        \\
        \\void fn_int(int x);
        \\void fn_f32(float x);
        \\void fn_f64(double x);
        \\void fn_char(char x);
        \\void fn_bool(bool x);
        \\void fn_ptr(void *x);
        \\
        \\void call() {
        \\    fn_int(3.0f);
        \\    fn_int(3.0);
        \\    fn_int(3.0L);
        \\    fn_int('ABCD');
        \\    fn_f32(3);
        \\    fn_f64(3);
        \\    fn_char('3');
        \\    fn_char('\x1');
        \\    fn_char(0);
        \\    fn_f32(3.0f);
        \\    fn_f64(3.0);
        \\    fn_bool(123);
        \\    fn_bool(0);
        \\    fn_bool(&fn_int);
        \\    fn_int(&fn_int);
        \\    fn_ptr(42);
        \\}
    , &[_][]const u8{
        \\pub extern fn fn_int(x: c_int) void;
        \\pub extern fn fn_f32(x: f32) void;
        \\pub extern fn fn_f64(x: f64) void;
        \\pub extern fn fn_char(x: u8) void;
        \\pub extern fn fn_bool(x: bool) void;
        \\pub extern fn fn_ptr(x: ?*c_void) void;
        \\pub export fn call() void {
        \\    fn_int(@floatToInt(c_int, 3));
        \\    fn_int(@floatToInt(c_int, 3));
        \\    fn_int(@floatToInt(c_int, 3));
        \\    fn_int(@as(c_int, 1094861636));
        \\    fn_f32(@intToFloat(f32, @as(c_int, 3)));
        \\    fn_f64(@intToFloat(f64, @as(c_int, 3)));
        \\    fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '3'))));
        \\    fn_char(@bitCast(u8, @truncate(i8, @as(c_int, '\x01'))));
        \\    fn_char(@bitCast(u8, @truncate(i8, @as(c_int, 0))));
        \\    fn_f32(3);
        \\    fn_f64(3);
        \\    fn_bool(@as(c_int, 123) != 0);
        \\    fn_bool(@as(c_int, 0) != 0);
        \\    fn_bool(@ptrToInt(fn_int) != 0);
        \\    fn_int(@intCast(c_int, @ptrToInt(fn_int)));
        \\    fn_ptr(@intToPtr(?*c_void, @as(c_int, 42)));
        \\}
    });

    cases.add("function call",
        \\static void bar(void) { }
        \\void foo(int *(baz)(void)) {
        \\    bar();
        \\    baz();
        \\}
    , &[_][]const u8{
        \\pub fn bar() callconv(.C) void {}
        \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void {
        \\    var baz = arg_baz;
        \\    bar();
        \\    _ = baz.?();
        \\}
    });

    cases.add("macro defines string literal with octal",
        \\#define FOO "aoeu\023 derp"
        \\#define FOO2 "aoeu\0234 derp"
        \\#define FOO_CHAR '\077'
    , &[_][]const u8{
        \\pub const FOO = "aoeu\x13 derp";
        ,
        \\pub const FOO2 = "aoeu\x134 derp";
        ,
        \\pub const FOO_CHAR = '\x3f';
    });

    cases.add("enums",
        \\enum Foo {
        \\    FooA = 2,
        \\    FooB = 5,
        \\    Foo1,
        \\};
    , &[_][]const u8{
        \\pub const FooA = @enumToInt(enum_Foo.A);
        \\pub const FooB = @enumToInt(enum_Foo.B);
        \\pub const Foo1 = @enumToInt(enum_Foo.@"1");
        \\pub const enum_Foo = extern enum(c_int) {
        \\    A = 2,
        \\    B = 5,
        \\    @"1" = 6,
        \\    _,
        \\};
        ,
        \\pub const Foo = enum_Foo;
    });

    cases.add("macro cast",
        \\#define FOO(bar) baz((void *)(baz))
        \\#define BAR (void*) a
        \\#define BAZ (uint32_t)(2)
    , &[_][]const u8{
        \\pub inline fn FOO(bar: anytype) @TypeOf(baz((@import("std").meta.cast(?*c_void, baz)))) {
        \\    return baz((@import("std").meta.cast(?*c_void, baz)));
        \\}
        ,
        \\pub const BAR = (@import("std").meta.cast(?*c_void, a));
        ,
        \\pub const BAZ = (@import("std").meta.cast(u32, 2));
    });

    cases.add("macro with cast to unsigned short, long, and long long",
        \\#define CURLAUTH_BASIC_BUT_USHORT ((unsigned short) 1)
        \\#define CURLAUTH_BASIC ((unsigned long) 1)
        \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)
    , &[_][]const u8{
        \\pub const CURLAUTH_BASIC_BUT_USHORT = (@import("std").meta.cast(c_ushort, 1));
        \\pub const CURLAUTH_BASIC = (@import("std").meta.cast(c_ulong, 1));
        \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = (@import("std").meta.cast(c_ulonglong, 1));
    });

    cases.add("macro conditional operator",
        \\#define FOO a ? b : c
    , &[_][]const u8{
        \\pub const FOO = if (a) b else c;
    });

    cases.add("do while as expr",
        \\static void foo(void) {
        \\    if (1)
        \\        do {} while (0);
        \\}
    , &[_][]const u8{
        \\pub fn foo() callconv(.C) void {
        \\    if (true) while (true) {
        \\        if (!false) break;
        \\    };
        \\}
    });

    cases.add("macro comparisions",
        \\#define MIN(a, b) ((b) < (a) ? (b) : (a))
        \\#define MAX(a, b) ((b) > (a) ? (b) : (a))
    , &[_][]const u8{
        \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) {
        \\    return if (b < a) b else a;
        \\}
        ,
        \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) {
        \\    return if (b > a) b else a;
        \\}
    });

    // TODO: detect to use different block labels here
    cases.add("nested assignment",
        \\int foo(int *p, int x) {
        \\    return *p++ = x;
        \\}
    , &[_][]const u8{
        \\pub export fn foo(arg_p: [*c]c_int, arg_x: c_int) c_int {
        \\    var p = arg_p;
        \\    var x = arg_x;
        \\    return blk: {
        \\        const tmp = x;
        \\        (blk_1: {
        \\            const ref = &p;
        \\            const tmp_2 = ref.*;
        \\            ref.* += 1;
        \\            break :blk_1 tmp_2;
        \\        }).?.* = tmp;
        \\        break :blk tmp;
        \\    };
        \\}
    });

    cases.add("widening and truncating integer casting to different signedness",
        \\unsigned long foo(void) {
        \\    return -1;
        \\}
        \\unsigned short bar(long x) {
        \\    return x;
        \\}
    , &[_][]const u8{
        \\pub export fn foo() c_ulong {
        \\    return @bitCast(c_ulong, @as(c_long, -@as(c_int, 1)));
        \\}
        \\pub export fn bar(arg_x: c_long) c_ushort {
        \\    var x = arg_x;
        \\    return @bitCast(c_ushort, @truncate(c_short, x));
        \\}
    });

    cases.add("arg name aliasing decl which comes after",
        \\void foo(int bar) {
        \\    bar = 2;
        \\}
        \\int bar = 4;
    , &[_][]const u8{
        \\pub export fn foo(arg_bar_1: c_int) void {
        \\    var bar_1 = arg_bar_1;
        \\    bar_1 = 2;
        \\}
        \\pub export var bar: c_int = 4;
    });

    cases.add("arg name aliasing macro which comes after",
        \\void foo(int bar) {
        \\    bar = 2;
        \\}
        \\#define bar 4
    , &[_][]const u8{
        \\pub export fn foo(arg_bar_1: c_int) void {
        \\    var bar_1 = arg_bar_1;
        \\    bar_1 = 2;
        \\}
        ,
        \\pub const bar = 4;
    });

    cases.add("don't export inline functions",
        \\inline void a(void) {}
        \\static void b(void) {}
        \\void c(void) {}
        \\static void foo() {}
    , &[_][]const u8{
        \\pub fn a() callconv(.C) void {}
        \\pub fn b() callconv(.C) void {}
        \\pub export fn c() void {}
        \\pub fn foo() callconv(.C) void {}
    });

    cases.add("casting away const and volatile",
        \\void foo(int *a) {}
        \\void bar(const int *a) {
        \\    foo((int *)a);
        \\}
        \\void baz(volatile int *a) {
        \\    foo((int *)a);
        \\}
    , &[_][]const u8{
        \\pub export fn foo(arg_a: [*c]c_int) void {
        \\    var a = arg_a;
        \\}
        \\pub export fn bar(arg_a: [*c]const c_int) void {
        \\    var a = arg_a;
        \\    foo(@intToPtr([*c]c_int, @ptrToInt(a)));
        \\}
        \\pub export fn baz(arg_a: [*c]volatile c_int) void {
        \\    var a = arg_a;
        \\    foo(@intToPtr([*c]c_int, @ptrToInt(a)));
        \\}
    });

    cases.add("handling of _Bool type",
        \\_Bool foo(_Bool x) {
        \\    _Bool a = x != 1;
        \\    _Bool b = a != 0;
        \\    _Bool c = foo;
        \\    return foo(c != b);
        \\}
    , &[_][]const u8{
        \\pub export fn foo(arg_x: bool) bool {
        \\    var x = arg_x;
        \\    var a: bool = (@as(c_int, @boolToInt(x)) != @as(c_int, 1));
        \\    var b: bool = (@as(c_int, @boolToInt(a)) != @as(c_int, 0));
        \\    var c: bool = @ptrToInt(foo) != 0;
        \\    return foo((@as(c_int, @boolToInt(c)) != @as(c_int, @boolToInt(b))));
        \\}
    });

    cases.add("Don't make const parameters mutable",
        \\int max(const int x, int y) {
        \\    return (x > y) ? x : y;
        \\}
    , &[_][]const u8{
        \\pub export fn max(x: c_int, arg_y: c_int) c_int {
        \\    var y = arg_y;
        \\    return if (x > y) x else y;
        \\}
    });

    cases.add("string concatenation in macros",
        \\#define FOO "hello"
        \\#define BAR FOO " world"
        \\#define BAZ "oh, " FOO
    , &[_][]const u8{
        \\pub const FOO = "hello";
        ,
        \\pub const BAR = FOO ++ " world";
        ,
        \\pub const BAZ = "oh, " ++ FOO;
    });

    cases.add("string concatenation in macros: two defines",
        \\#define FOO "hello"
        \\#define BAZ " world"
        \\#define BAR FOO BAZ
    , &[_][]const u8{
        \\pub const FOO = "hello";
        ,
        \\pub const BAZ = " world";
        ,
        \\pub const BAR = FOO ++ BAZ;
    });

    cases.add("string concatenation in macros: two strings",
        \\#define FOO "a" "b"
        \\#define BAR FOO "c"
    , &[_][]const u8{
        \\pub const FOO = "a" ++ "b";
        ,
        \\pub const BAR = FOO ++ "c";
    });

    cases.add("string concatenation in macros: three strings",
        \\#define FOO "a" "b" "c"
    , &[_][]const u8{
        \\pub const FOO = "a" ++ "b" ++ "c";
    });

    cases.add("multibyte character literals",
        \\#define FOO 'abcd'
    , &[_][]const u8{
        \\pub const FOO = 0x61626364;
    });

    cases.add("Make sure casts are grouped",
        \\typedef struct
        \\{
        \\    int i;
        \\}
        \\*_XPrivDisplay;
        \\typedef struct _XDisplay Display;
        \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen)
        \\
    , &[_][]const u8{
        \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf((@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen) {
        \\    return (@import("std").meta.cast(_XPrivDisplay, dpy)).*.default_screen;
        \\}
    });

    cases.add("macro integer literal casts",
        \\#define NULL ((void*)0)
        \\#define FOO ((int)0x8000)
    , &[_][]const u8{
        \\pub const NULL = (@import("std").meta.cast(?*c_void, 0));
        ,
        \\pub const FOO = (@import("std").meta.cast(c_int, 0x8000));
    });

    if (std.Target.current.abi == .msvc) {
        cases.add("nameless struct fields",
            \\typedef struct NAMED
            \\{
            \\    long name;
            \\} NAMED;
            \\
            \\typedef struct ONENAMEWITHSTRUCT
            \\{
            \\    NAMED;
            \\    long b;
            \\} ONENAMEWITHSTRUCT;
        , &[_][]const u8{
            \\pub const struct_NAMED = extern struct {
            \\    name: c_long,
            \\};
            \\pub const NAMED = struct_NAMED;
            \\pub const struct_ONENAMEWITHSTRUCT = extern struct {
            \\    unnamed_0: struct_NAMED,
            \\    b: c_long,
            \\};
        });
    } else {
        cases.add("nameless struct fields",
            \\typedef struct NAMED
            \\{
            \\    long name;
            \\} NAMED;
            \\
            \\typedef struct ONENAMEWITHSTRUCT
            \\{
            \\    NAMED;
            \\    long b;
            \\} ONENAMEWITHSTRUCT;
        , &[_][]const u8{
            \\pub const struct_NAMED = extern struct {
            \\    name: c_long,
            \\};
            \\pub const NAMED = struct_NAMED;
            \\pub const struct_ONENAMEWITHSTRUCT = extern struct {
            \\    b: c_long,
            \\};
        });
    }

    cases.add("unnamed fields have predictabile names",
        \\struct a {
        \\    struct {};
        \\};
        \\struct b {
        \\    struct {};
        \\};
    , &[_][]const u8{
        \\const struct_unnamed_1 = extern struct {};
        \\pub const struct_a = extern struct {
        \\    unnamed_0: struct_unnamed_1,
        \\};
        \\const struct_unnamed_2 = extern struct {};
        \\pub const struct_b = extern struct {
        \\    unnamed_0: struct_unnamed_2,
        \\};
    });
}