authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 21:33:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 21:33:21-07:00
log1253903fef07d7fd0435310f474bfe2745b41405
treef2a6bf81f0ef826d9e5f4bcd1f36aef6cba03b78
parent8379fff80455f89f9673638642cf506cb73c4241

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.

1 files changed, 61 insertions(+), 44 deletions(-)

lib/std/zig/parser_test.zig+61-44
......@@ -1594,50 +1594,67 @@ test "zig fmt: struct literal no trailing comma" {
15941594 );
15951595}
15961596
1597//test "zig fmt: struct literal containing a multiline expression" {
1598// try testTransform(
1599// \\const a = A{ .x = if (f1()) 10 else 20 };
1600// \\const a = A{ .x = if (f1()) 10 else 20, };
1601// \\const a = A{ .x = if (f1())
1602// \\ 10 else 20 };
1603// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1604// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100, };
1605// \\const a = A{ .x = if (f1())
1606// \\ 10 else 20};
1607// \\const a = A{ .x = switch(g) {0 => "ok", else => "no"} };
1608// \\
1609// ,
1610// \\const a = A{ .x = if (f1()) 10 else 20 };
1611// \\const a = A{
1612// \\ .x = if (f1()) 10 else 20,
1613// \\};
1614// \\const a = A{
1615// \\ .x = if (f1())
1616// \\ 10
1617// \\ else
1618// \\ 20,
1619// \\};
1620// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1621// \\const a = A{
1622// \\ .x = if (f1()) 10 else 20,
1623// \\ .y = f2() + 100,
1624// \\};
1625// \\const a = A{
1626// \\ .x = if (f1())
1627// \\ 10
1628// \\ else
1629// \\ 20,
1630// \\};
1631// \\const a = A{
1632// \\ .x = switch (g) {
1633// \\ 0 => "ok",
1634// \\ else => "no",
1635// \\ },
1636// \\};
1637// \\
1638// );
1639//}
1640//
1597test "zig fmt: struct literal containing a multiline expression" {
1598 try testTransform(
1599 \\const a = A{ .x = if (f1()) 10 else 20 };
1600 \\const a = A{ .x = if (f1()) 10 else 20, };
1601 \\const a = A{ .x = if (f1())
1602 \\ 10 else 20 };
1603 \\const a = A{ .x = if (f1())
1604 \\ 10 else 20,};
1605 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1606 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100, };
1607 \\const a = A{ .x = if (f1())
1608 \\ 10 else 20};
1609 \\const a = A{ .x = if (f1())
1610 \\ 10 else 20,};
1611 \\const a = A{ .x = switch(g) {0 => "ok", else => "no"} };
1612 \\const a = A{ .x = switch(g) {0 => "ok", else => "no"}, };
1613 \\
1614 ,
1615 \\const a = A{ .x = if (f1()) 10 else 20 };
1616 \\const a = A{
1617 \\ .x = if (f1()) 10 else 20,
1618 \\};
1619 \\const a = A{ .x = if (f1())
1620 \\ 10
1621 \\else
1622 \\ 20 };
1623 \\const a = A{
1624 \\ .x = if (f1())
1625 \\ 10
1626 \\ else
1627 \\ 20,
1628 \\};
1629 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1630 \\const a = A{
1631 \\ .x = if (f1()) 10 else 20,
1632 \\ .y = f2() + 100,
1633 \\};
1634 \\const a = A{ .x = if (f1())
1635 \\ 10
1636 \\else
1637 \\ 20 };
1638 \\const a = A{
1639 \\ .x = if (f1())
1640 \\ 10
1641 \\ else
1642 \\ 20,
1643 \\};
1644 \\const a = A{ .x = switch (g) {
1645 \\ 0 => "ok",
1646 \\ else => "no",
1647 \\} };
1648 \\const a = A{
1649 \\ .x = switch (g) {
1650 \\ 0 => "ok",
1651 \\ else => "no",
1652 \\ },
1653 \\};
1654 \\
1655 );
1656}
1657
16411658//test "zig fmt: array literal with hint" {
16421659// try testTransform(
16431660// \\const a = []u8{