diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-01 23:46:57 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-01 23:46:57 -0700 |
| commit | ed2364a1480f99a7380285cec15ff1962d9df519 (patch) | |
| tree | da488724987e43e11a5938589a9df5b92c79d8c4 /test/behavior/export.zig | |
| parent | 6f303c01f3e06fe8203563065ea32537f6eff456 (diff) | |
| download | zig-ed2364a1480f99a7380285cec15ff1962d9df519.tar.gz zig-ed2364a1480f99a7380285cec15ff1962d9df519.zip | |
stage2: introduce anonymous struct literals
Diffstat (limited to 'test/behavior/export.zig')
| -rw-r--r-- | test/behavior/export.zig | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/behavior/export.zig b/test/behavior/export.zig new file mode 100644 index 0000000000..9521c7cadb --- /dev/null +++ b/test/behavior/export.zig @@ -0,0 +1,50 @@ +const std = @import("std"); +const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; +const expectEqualStrings = std.testing.expectEqualStrings; +const mem = std.mem; +const builtin = @import("builtin"); + +// can't really run this test but we can make sure it has no compile error +// and generates code +const vram = @intToPtr([*]volatile u8, 0x20000000)[0..0x8000]; +export fn writeToVRam() void { + vram[0] = 'X'; +} + +const PackedStruct = packed struct { + a: u8, + b: u8, +}; +const PackedUnion = packed union { + a: u8, + b: u32, +}; + +test "packed struct, enum, union parameters in extern function" { + testPackedStuff(&(PackedStruct{ + .a = 1, + .b = 2, + }), &(PackedUnion{ .a = 1 })); +} + +export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void { + if (false) { + a; + b; + } +} + +test "exporting enum type and value" { + const S = struct { + const E = enum(c_int) { one, two }; + comptime { + @export(E, .{ .name = "E" }); + } + const e: E = .two; + comptime { + @export(e, .{ .name = "e" }); + } + }; + try expect(S.e == .two); +} |
