@@ -1140,3 +1140,22 @@ test "tagName on enum literals" {
|
||||
expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
|
||||
comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
|
||||
}
|
||||
|
||||
test "method call on an enum" {
|
||||
const S = struct {
|
||||
const E = enum {
|
||||
one,
|
||||
two,
|
||||
|
||||
fn method(self: *E) bool {
|
||||
return self.* == .two;
|
||||
}
|
||||
};
|
||||
fn doTheTest() void {
|
||||
var e = E.two;
|
||||
expect(e.method());
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
@@ -669,3 +669,24 @@ test "cast from anonymous struct to union" {
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
test "method call on an empty union" {
|
||||
const S = struct {
|
||||
const MyUnion = union(Tag) {
|
||||
pub const Tag = enum { X1, X2 };
|
||||
X1: [0]u8,
|
||||
X2: [0]u8,
|
||||
|
||||
pub fn useIt(self: *@This()) bool {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
fn doTheTest() void {
|
||||
var u = MyUnion{ .X1 = [0]u8{} };
|
||||
expect(u.useIt());
|
||||
}
|
||||
};
|
||||
S.doTheTest();
|
||||
comptime S.doTheTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user