aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-02-22 21:33:21 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-02-22 21:33:21 -0700
commit1253903fef07d7fd0435310f474bfe2745b41405 (patch)
treef2a6bf81f0ef826d9e5f4bcd1f36aef6cba03b78 /lib/std
parent8379fff80455f89f9673638642cf506cb73c4241 (diff)
downloadzig-1253903fef07d7fd0435310f474bfe2745b41405.tar.gz
zig-1253903fef07d7fd0435310f474bfe2745b41405.zip
zig fmt: struct literal containing a multiline expression
I modified this test case to expect different results. Now, the trailing comma on a list of struct fields is the only deciding factor, not whether or not the field init expressions contain a newline.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/zig/parser_test.zig105
1 files changed, 61 insertions, 44 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index dd2755b8ab..4aa6d95b30 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -1594,50 +1594,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, .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 = 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, .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 = switch (g) {
-// \\ 0 => "ok",
-// \\ else => "no",
-// \\ },
-// \\};
-// \\
-// );
-//}
-//
+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: array literal with hint" {
// try testTransform(
// \\const a = []u8{