zig fmt: fix rendering of struct with no trailing comma on last field

master
Andrew Kelley 2018-05-26 16:43:33 -04:00
parent 0ab888c639
commit 0bef1f9824
2 changed files with 16 additions and 2 deletions

View File

@ -1,3 +1,18 @@
test "zig fmt: no trailing comma on struct decl" {
try testTransform(
\\const RoundParam = struct {
\\ k: usize, s: u32, t: u32
\\};
,
\\const RoundParam = struct {
\\ k: usize,
\\ s: u32,
\\ t: u32,
\\};
\\
);
}
test "zig fmt: simple asm" {
try testTransform(
\\comptime {

View File

@ -102,8 +102,7 @@ fn renderTopLevelDecl(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, i
}
try renderToken(tree, stream, field.name_token, indent, Space.None); // name
try renderToken(tree, stream, tree.nextToken(field.name_token), indent, Space.Space); // :
try renderExpression(allocator, stream, tree, indent, field.type_expr, Space.None); // type
try renderToken(tree, stream, tree.nextToken(field.lastToken()), indent, Space.Newline); // ,
try renderTrailingComma(allocator, stream, tree, indent, field.type_expr, Space.Newline); // type,
},
ast.Node.Id.UnionTag => {