mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-10-28 10:45:48 +08:00
47 lines
1.3 KiB
Zig
47 lines
1.3 KiB
Zig
const builtin = @import("builtin");
|
|
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
test "exporting enum value" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.cpu.arch.isSpirv()) return error.SkipZigTest;
|
|
|
|
const S = struct {
|
|
const E = enum(c_int) { one, two };
|
|
const e: E = .two;
|
|
comptime {
|
|
@export(&e, .{ .name = "e" });
|
|
}
|
|
};
|
|
try expect(S.e == .two);
|
|
}
|
|
|
|
test "exporting using namespace access" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.cpu.arch.isSpirv()) return error.SkipZigTest;
|
|
|
|
const S = struct {
|
|
const Inner = struct {
|
|
const x: u32 = 5;
|
|
};
|
|
comptime {
|
|
@export(&Inner.x, .{ .name = "foo", .linkage = .strong });
|
|
}
|
|
};
|
|
|
|
_ = S.Inner.x;
|
|
}
|
|
|
|
test "exporting comptime-known value" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
|
if (builtin.cpu.arch.isSpirv()) return error.SkipZigTest;
|
|
|
|
const x: u32 = 10;
|
|
@export(&x, .{ .name = "exporting_comptime_known_value_foo" });
|
|
const S = struct {
|
|
extern const exporting_comptime_known_value_foo: u32;
|
|
};
|
|
try expect(S.exporting_comptime_known_value_foo == 10);
|
|
}
|