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