mirror of
https://github.com/ziglang/zig.git
synced 2024-11-28 08:02:32 +00:00
1e0addcf73
This mostly reverts commit 692c254336
.
The test "for loop over pointers to struct, getting field from struct
pointer" is still failing on the CI so that one is not moved over.
54 lines
1.1 KiB
Zig
54 lines
1.1 KiB
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
const A = struct {
|
|
pub const B = bool;
|
|
};
|
|
|
|
const C = struct {
|
|
usingnamespace A;
|
|
};
|
|
|
|
test "basic usingnamespace" {
|
|
try std.testing.expect(C.B == bool);
|
|
}
|
|
|
|
fn Foo(comptime T: type) type {
|
|
return struct {
|
|
usingnamespace T;
|
|
};
|
|
}
|
|
|
|
test "usingnamespace inside a generic struct" {
|
|
const std2 = Foo(std);
|
|
const testing2 = Foo(std.testing);
|
|
try std2.testing.expect(true);
|
|
try testing2.expect(true);
|
|
}
|
|
|
|
usingnamespace struct {
|
|
pub const foo = 42;
|
|
};
|
|
|
|
test "usingnamespace does not redeclare an imported variable" {
|
|
comptime try std.testing.expect(@This().foo == 42);
|
|
}
|
|
|
|
usingnamespace @import("usingnamespace/foo.zig");
|
|
test "usingnamespace omits mixing in private functions" {
|
|
try expect(@This().privateFunction());
|
|
try expect(!@This().printText());
|
|
}
|
|
fn privateFunction() bool {
|
|
return true;
|
|
}
|
|
|
|
test {
|
|
_ = @import("usingnamespace/import_segregation.zig");
|
|
}
|
|
|
|
usingnamespace @import("usingnamespace/a.zig");
|
|
test "two files usingnamespace import each other" {
|
|
try expect(@This().ok());
|
|
}
|