2019-07-19 21:56:44 +01:00
|
|
|
const std = @import("std");
|
2021-11-30 23:14:18 +00:00
|
|
|
const expect = std.testing.expect;
|
2019-07-19 21:56:44 +01:00
|
|
|
|
2021-08-28 23:35:59 +01:00
|
|
|
const A = struct {
|
|
|
|
pub const B = bool;
|
|
|
|
};
|
2019-09-26 16:54:45 +01:00
|
|
|
|
2021-08-28 23:35:59 +01:00
|
|
|
const C = struct {
|
|
|
|
usingnamespace A;
|
2019-09-26 16:54:45 +01:00
|
|
|
};
|
|
|
|
|
2021-08-28 23:35:59 +01:00
|
|
|
test "basic usingnamespace" {
|
|
|
|
try std.testing.expect(C.B == bool);
|
2019-09-26 16:54:45 +01:00
|
|
|
}
|
2021-11-30 23:14:18 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|