| ... | ... | @@ -1,148 +0,0 @@ |
| 1 | | const tests = @import("tests.zig"); |
| 2 | | |
| 3 | | pub fn addCases(cases: *tests.GenHContext) void { |
| 4 | | cases.add("declare enum", |
| 5 | | \\const Foo = extern enum { A, B, C }; |
| 6 | | \\export fn entry(foo: Foo) void { } |
| 7 | | , &[_][]const u8{ |
| 8 | | \\enum Foo { |
| 9 | | \\ A = 0, |
| 10 | | \\ B = 1, |
| 11 | | \\ C = 2 |
| 12 | | \\}; |
| 13 | | , |
| 14 | | \\void entry(enum Foo foo); |
| 15 | | }); |
| 16 | | |
| 17 | | cases.add("declare struct", |
| 18 | | \\const Foo = extern struct { |
| 19 | | \\ A: i32, |
| 20 | | \\ B: f32, |
| 21 | | \\ C: bool, |
| 22 | | \\ D: u64, |
| 23 | | \\ E: u64, |
| 24 | | \\ F: u64, |
| 25 | | \\}; |
| 26 | | \\export fn entry(foo: Foo) void { } |
| 27 | | , &[_][]const u8{ |
| 28 | | \\struct Foo { |
| 29 | | \\ int32_t A; |
| 30 | | \\ float B; |
| 31 | | \\ bool C; |
| 32 | | \\ uint64_t D; |
| 33 | | \\ uint64_t E; |
| 34 | | \\ uint64_t F; |
| 35 | | \\}; |
| 36 | | , |
| 37 | | \\void entry(struct Foo foo); |
| 38 | | \\ |
| 39 | | }); |
| 40 | | |
| 41 | | cases.add("declare union", |
| 42 | | \\const Big = extern struct { |
| 43 | | \\ A: u64, |
| 44 | | \\ B: u64, |
| 45 | | \\ C: u64, |
| 46 | | \\ D: u64, |
| 47 | | \\ E: u64, |
| 48 | | \\}; |
| 49 | | \\const Foo = extern union { |
| 50 | | \\ A: i32, |
| 51 | | \\ B: f32, |
| 52 | | \\ C: bool, |
| 53 | | \\ D: Big, |
| 54 | | \\}; |
| 55 | | \\export fn entry(foo: Foo) void {} |
| 56 | | , &[_][]const u8{ |
| 57 | | \\struct Big { |
| 58 | | \\ uint64_t A; |
| 59 | | \\ uint64_t B; |
| 60 | | \\ uint64_t C; |
| 61 | | \\ uint64_t D; |
| 62 | | \\ uint64_t E; |
| 63 | | \\}; |
| 64 | | \\ |
| 65 | | \\union Foo { |
| 66 | | \\ int32_t A; |
| 67 | | \\ float B; |
| 68 | | \\ bool C; |
| 69 | | \\ struct Big D; |
| 70 | | \\}; |
| 71 | | , |
| 72 | | \\void entry(union Foo foo); |
| 73 | | \\ |
| 74 | | }); |
| 75 | | |
| 76 | | cases.add("declare opaque type", |
| 77 | | \\const Foo = opaque {}; |
| 78 | | \\ |
| 79 | | \\export fn entry(foo: ?*Foo) void { } |
| 80 | | , &[_][]const u8{ |
| 81 | | \\struct Foo; |
| 82 | | , |
| 83 | | \\void entry(struct Foo * foo); |
| 84 | | }); |
| 85 | | |
| 86 | | cases.add("array field-type", |
| 87 | | \\const Foo = extern struct { |
| 88 | | \\ A: [2]i32, |
| 89 | | \\ B: [4]*u32, |
| 90 | | \\}; |
| 91 | | \\export fn entry(foo: Foo, bar: [3]u8) void { } |
| 92 | | , &[_][]const u8{ |
| 93 | | \\struct Foo { |
| 94 | | \\ int32_t A[2]; |
| 95 | | \\ uint32_t * B[4]; |
| 96 | | \\}; |
| 97 | | , |
| 98 | | \\void entry(struct Foo foo, uint8_t bar[]); |
| 99 | | \\ |
| 100 | | }); |
| 101 | | |
| 102 | | cases.add("ptr to zig struct", |
| 103 | | \\const S = struct { |
| 104 | | \\ a: u8, |
| 105 | | \\}; |
| 106 | | \\ |
| 107 | | \\export fn a(s: *S) u8 { |
| 108 | | \\ return s.a; |
| 109 | | \\} |
| 110 | | , &[_][]const u8{ |
| 111 | | \\struct S; |
| 112 | | , |
| 113 | | \\uint8_t a(struct S * s); |
| 114 | | \\ |
| 115 | | }); |
| 116 | | |
| 117 | | cases.add("ptr to zig union", |
| 118 | | \\const U = union(enum) { |
| 119 | | \\ A: u8, |
| 120 | | \\ B: u16, |
| 121 | | \\}; |
| 122 | | \\ |
| 123 | | \\export fn a(s: *U) u8 { |
| 124 | | \\ return s.A; |
| 125 | | \\} |
| 126 | | , &[_][]const u8{ |
| 127 | | \\union U; |
| 128 | | , |
| 129 | | \\uint8_t a(union U * s); |
| 130 | | \\ |
| 131 | | }); |
| 132 | | |
| 133 | | cases.add("ptr to zig enum", |
| 134 | | \\const E = enum(u8) { |
| 135 | | \\ A, |
| 136 | | \\ B, |
| 137 | | \\}; |
| 138 | | \\ |
| 139 | | \\export fn a(s: *E) u8 { |
| 140 | | \\ return @intFromEnum(s.*); |
| 141 | | \\} |
| 142 | | , &[_][]const u8{ |
| 143 | | \\enum E; |
| 144 | | , |
| 145 | | \\uint8_t a(enum E * s); |
| 146 | | \\ |
| 147 | | }); |
| 148 | | } |