mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
80 lines
2.4 KiB
Zig
80 lines
2.4 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.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
|
|
if (builtin.cpu.arch.isWasm()) {
|
|
// https://github.com/ziglang/zig/issues/4866
|
|
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 with internal linkage" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
|
|
const S = struct {
|
|
fn foo() callconv(.c) void {}
|
|
comptime {
|
|
@export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal });
|
|
}
|
|
};
|
|
S.foo();
|
|
}
|
|
|
|
test "exporting using namespace access" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
|
|
if (builtin.cpu.arch.isWasm()) {
|
|
// https://github.com/ziglang/zig/issues/4866
|
|
return error.SkipZigTest;
|
|
}
|
|
|
|
const S = struct {
|
|
const Inner = struct {
|
|
const x: u32 = 5;
|
|
};
|
|
comptime {
|
|
@export(&Inner.x, .{ .name = "foo", .linkage = .internal });
|
|
}
|
|
};
|
|
|
|
_ = S.Inner.x;
|
|
}
|
|
|
|
test "exporting comptime-known value" {
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_x86_64 and
|
|
(builtin.target.ofmt != .elf and
|
|
builtin.target.ofmt != .macho and
|
|
builtin.target.ofmt != .coff)) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
|
|
|
if (builtin.cpu.arch.isWasm()) {
|
|
// https://github.com/ziglang/zig/issues/4866
|
|
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);
|
|
}
|