zig fmt: Respect line breaks in struct default value decls

Bring this in line with how variable declarations are handled.

Open a new indentation level for the initialization expression to handle
nested expressions like blocks.

Closes #7618
This commit is contained in:
LemonBoy
2021-03-16 09:22:16 +01:00
committed by GitHub
parent f16f25047c
commit 5ecf8bddae
2 changed files with 48 additions and 2 deletions

View File

@@ -4,6 +4,31 @@
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
test "zig fmt: respect line breaks in struct field value declaration" {
try testCanonical(
\\const Foo = struct {
\\ bar: u32 =
\\ 42,
\\ bar: u32 =
\\ // a comment
\\ 42,
\\ bar: u32 =
\\ 42,
\\ // a comment
\\ bar: []const u8 =
\\ \\ foo
\\ \\ bar
\\ \\ baz
\\ ,
\\ bar: u32 =
\\ blk: {
\\ break :blk 42;
\\ },
\\};
\\
);
}
// TODO Remove this after zig 0.9.0 is released.
test "zig fmt: rewrite inline functions as callconv(.Inline)" {
try testTransform(