commit aedca7da745e3cf425dc47e8077a6bee694122d8 (tree)
parent 1c139bf217c8c219cda75a154f1bc605cc17fa4b
Author: Motiejus Jakštys <motiejus.jakstys@chronosphere.io>
Date: Tue, 10 Feb 2026 18:49:55 +0000
parser: port test "struct literal containing a multiline expression"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
| M | parser_test.zig | | | 61 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 61 insertions(+), 0 deletions(-)
diff --git a/parser_test.zig b/parser_test.zig
@@ -2278,6 +2278,67 @@ test "zig fmt: struct literal no trailing comma" {
);
}
+test "zig fmt: struct literal containing a multiline expression" {
+ try testTransform(
+ \\const a = A{ .x = if (f1()) 10 else 20 };
+ \\const a = A{ .x = if (f1()) 10 else 20, };
+ \\const a = A{ .x = if (f1())
+ \\ 10 else 20 };
+ \\const a = A{ .x = if (f1())
+ \\ 10 else 20,};
+ \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
+ \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100, };
+ \\const a = A{ .x = if (f1())
+ \\ 10 else 20};
+ \\const a = A{ .x = if (f1())
+ \\ 10 else 20,};
+ \\const a = A{ .x = switch(g) {0 => "ok", else => "no"} };
+ \\const a = A{ .x = switch(g) {0 => "ok", else => "no"}, };
+ \\
+ ,
+ \\const a = A{ .x = if (f1()) 10 else 20 };
+ \\const a = A{
+ \\ .x = if (f1()) 10 else 20,
+ \\};
+ \\const a = A{ .x = if (f1())
+ \\ 10
+ \\else
+ \\ 20 };
+ \\const a = A{
+ \\ .x = if (f1())
+ \\ 10
+ \\ else
+ \\ 20,
+ \\};
+ \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
+ \\const a = A{
+ \\ .x = if (f1()) 10 else 20,
+ \\ .y = f2() + 100,
+ \\};
+ \\const a = A{ .x = if (f1())
+ \\ 10
+ \\else
+ \\ 20 };
+ \\const a = A{
+ \\ .x = if (f1())
+ \\ 10
+ \\ else
+ \\ 20,
+ \\};
+ \\const a = A{ .x = switch (g) {
+ \\ 0 => "ok",
+ \\ else => "no",
+ \\} };
+ \\const a = A{
+ \\ .x = switch (g) {
+ \\ 0 => "ok",
+ \\ else => "no",
+ \\ },
+ \\};
+ \\
+ );
+}
+
test "zig fmt: multiline string with backslash at end of line" {
try testCanonical(
\\comptime {