authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-29 18:22:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-29 18:22:39-04:00
log3fa0bed985b8de950859d4c482efe9cb30fdaf27
tree290017fef7a955b7e9a5ab2ea38abf650023a0ed
parent9543c0a7cc0bbdccc405370e224b546c56b76a0f

zig fmt: array literal with 1 item on 1 line


1 files changed, 17 insertions(+), 0 deletions(-)

std/zig/parser.zig+17
...@@ -3730,6 +3730,16 @@ pub const Parser = struct {...@@ -3730,6 +3730,16 @@ pub const Parser = struct {
3730 try stack.append(RenderState { .Expression = suffix_op.lhs });3730 try stack.append(RenderState { .Expression = suffix_op.lhs });
3731 continue;3731 continue;
3732 }3732 }
3733 if (exprs.len == 1) {
3734 const expr = exprs.at(0);
3735
3736 try stack.append(RenderState { .Text = "}" });
3737 try stack.append(RenderState { .Expression = expr });
3738 try stack.append(RenderState { .Text = " {" });
3739 try stack.append(RenderState { .Expression = suffix_op.lhs });
3740 continue;
3741 }
3742
3733 try stack.append(RenderState { .Text = "}"});3743 try stack.append(RenderState { .Text = "}"});
3734 try stack.append(RenderState.PrintIndent);3744 try stack.append(RenderState.PrintIndent);
3735 try stack.append(RenderState { .Indent = indent });3745 try stack.append(RenderState { .Indent = indent });
...@@ -4513,6 +4523,13 @@ fn testCanonical(source: []const u8) !void {...@@ -4513,6 +4523,13 @@ fn testCanonical(source: []const u8) !void {
4513 }4523 }
4514}4524}
45154525
4526test "zig fmt: array literal with 1 item on 1 line" {
4527 try testCanonical(
4528 \\var s = []const u64 {0} ** 25;
4529 \\
4530 );
4531}
4532
4516test "zig fmt: preserve same-line comment after a statement" {4533test "zig fmt: preserve same-line comment after a statement" {
4517 try testCanonical(4534 try testCanonical(
4518 \\test "" {4535 \\test "" {