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" {...@@ -1594,50 +1594,67 @@ test "zig fmt: struct literal no trailing comma" {
1594 );1594 );
1595}1595}
15961596
1597//test "zig fmt: struct literal containing a multiline expression" {1597test "zig fmt: struct literal containing a multiline expression" {
1598// try testTransform(1598 try testTransform(
1599// \\const a = A{ .x = if (f1()) 10 else 20 };1599 \\const a = A{ .x = if (f1()) 10 else 20 };
1600// \\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())1601 \\const a = A{ .x = if (f1())
1602// \\ 10 else 20 };1602 \\ 10 else 20 };
1603// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };1603 \\const a = A{ .x = if (f1())
1604// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100, };1604 \\ 10 else 20,};
1605// \\const a = A{ .x = if (f1())1605 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1606// \\ 10 else 20};1606 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100, };
1607// \\const a = A{ .x = switch(g) {0 => "ok", else => "no"} };1607 \\const a = A{ .x = if (f1())
1608// \\1608 \\ 10 else 20};
1609// ,1609 \\const a = A{ .x = if (f1())
1610// \\const a = A{ .x = if (f1()) 10 else 20 };1610 \\ 10 else 20,};
1611// \\const a = A{1611 \\const a = A{ .x = switch(g) {0 => "ok", else => "no"} };
1612// \\ .x = if (f1()) 10 else 20,1612 \\const a = A{ .x = switch(g) {0 => "ok", else => "no"}, };
1613// \\};1613 \\
1614// \\const a = A{1614 ,
1615// \\ .x = if (f1())1615 \\const a = A{ .x = if (f1()) 10 else 20 };
1616// \\ 101616 \\const a = A{
1617// \\ else1617 \\ .x = if (f1()) 10 else 20,
1618// \\ 20,1618 \\};
1619// \\};1619 \\const a = A{ .x = if (f1())
1620// \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };1620 \\ 10
1621// \\const a = A{1621 \\else
1622// \\ .x = if (f1()) 10 else 20,1622 \\ 20 };
1623// \\ .y = f2() + 100,1623 \\const a = A{
1624// \\};1624 \\ .x = if (f1())
1625// \\const a = A{1625 \\ 10
1626// \\ .x = if (f1())1626 \\ else
1627// \\ 101627 \\ 20,
1628// \\ else1628 \\};
1629// \\ 20,1629 \\const a = A{ .x = if (f1()) 10 else 20, .y = f2() + 100 };
1630// \\};1630 \\const a = A{
1631// \\const a = A{1631 \\ .x = if (f1()) 10 else 20,
1632// \\ .x = switch (g) {1632 \\ .y = f2() + 100,
1633// \\ 0 => "ok",1633 \\};
1634// \\ else => "no",1634 \\const a = A{ .x = if (f1())
1635// \\ },1635 \\ 10
1636// \\};1636 \\else
1637// \\1637 \\ 20 };
1638// );1638 \\const a = A{
1639//}1639 \\ .x = if (f1())
1640//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
1641//test "zig fmt: array literal with hint" {1658//test "zig fmt: array literal with hint" {
1642// try testTransform(1659// try testTransform(
1643// \\const a = []u8{1660// \\const a = []u8{