2017-01-05 16:57:48 +08:00
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2018-09-14 04:34:33 +08:00
|
|
|
const module = @This();
|
2016-09-27 11:47:30 +08:00
|
|
|
|
2018-01-25 17:10:11 +08:00
|
|
|
fn Point(comptime T: type) type {
|
2018-10-15 21:51:15 +08:00
|
|
|
return struct.{
|
2018-09-14 04:34:33 +08:00
|
|
|
const Self = @This();
|
2016-12-22 14:20:08 +08:00
|
|
|
x: T,
|
|
|
|
y: T,
|
2016-09-27 11:47:30 +08:00
|
|
|
|
2018-05-31 22:56:59 +08:00
|
|
|
fn addOne(self: *Self) void {
|
2016-12-22 14:20:08 +08:00
|
|
|
self.x += 1;
|
|
|
|
self.y += 1;
|
|
|
|
}
|
2017-12-22 13:50:30 +08:00
|
|
|
};
|
2016-09-27 11:47:30 +08:00
|
|
|
}
|
|
|
|
|
2018-01-25 17:10:11 +08:00
|
|
|
fn add(x: i32, y: i32) i32 {
|
2017-12-22 13:50:30 +08:00
|
|
|
return x + y;
|
2016-09-27 11:47:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-24 09:38:31 +08:00
|
|
|
test "this refer to module call private fn" {
|
2016-09-27 11:47:30 +08:00
|
|
|
assert(module.add(1, 2) == 3);
|
|
|
|
}
|
|
|
|
|
2017-05-24 09:38:31 +08:00
|
|
|
test "this refer to container" {
|
2018-10-15 21:51:15 +08:00
|
|
|
var pt = Point(i32).{
|
2016-09-27 11:47:30 +08:00
|
|
|
.x = 12,
|
|
|
|
.y = 34,
|
|
|
|
};
|
|
|
|
pt.addOne();
|
|
|
|
assert(pt.x == 13);
|
|
|
|
assert(pt.y == 35);
|
|
|
|
}
|