zig fmt: fix lastToken() for container_decl_arg

This commit is contained in:
Isaac Freund
2021-03-05 12:29:02 +01:00
parent 9cd038d73a
commit ef3adbdb36
2 changed files with 22 additions and 1 deletions

View File

@@ -766,7 +766,7 @@ pub const Tree = struct {
.container_decl_arg => {
const members = tree.extraData(datas[n].rhs, Node.SubRange);
if (members.end - members.start == 0) {
end_offset += 1; // for the rparen
end_offset += 3; // for the rparen + lbrace + rbrace
n = datas[n].lhs;
} else {
end_offset += 1; // for the rbrace

View File

@@ -963,6 +963,27 @@ test "zig fmt: allowzero pointer" {
);
}
test "zig fmt: empty enum decls" {
try testCanonical(
\\const A = enum {};
\\const B = enum(u32) {};
\\const C = extern enum(c_int) {};
\\const D = packed enum(u8) {};
\\
);
}
test "zig fmt: empty union decls" {
try testCanonical(
\\const A = union {};
\\const B = union(enum) {};
\\const C = union(Foo) {};
\\const D = extern union {};
\\const E = packed union {};
\\
);
}
test "zig fmt: enum literal" {
try testCanonical(
\\const x = .hi;