authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 20:25:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-21 20:25:31-07:00
log621ad241d6dfbde60ee8a5b1d0dcd7d9cf29f8f3
tree9d3f70712ae2fb7a1205acc14db2f72bde03383b
parenta17a5ca3a85c92aa933a8eaac66198b31b8b294c

zig fmt: if nested


2 files changed, 29 insertions(+), 21 deletions(-)

lib/std/zig/parser_test.zig+20-20
...@@ -1449,26 +1449,26 @@ test "zig fmt: if-else with comment before else" {...@@ -1449,26 +1449,26 @@ test "zig fmt: if-else with comment before else" {
1449 );1449 );
1450}1450}
14511451
1452//test "zig fmt: if nested" {1452test "zig fmt: if nested" {
1453// try testCanonical(1453 try testCanonical(
1454// \\pub fn foo() void {1454 \\pub fn foo() void {
1455// \\ return if ((aInt & bInt) >= 0)1455 \\ return if ((aInt & bInt) >= 0)
1456// \\ if (aInt < bInt)1456 \\ if (aInt < bInt)
1457// \\ GE_LESS1457 \\ GE_LESS
1458// \\ else if (aInt == bInt)1458 \\ else if (aInt == bInt)
1459// \\ GE_EQUAL1459 \\ GE_EQUAL
1460// \\ else1460 \\ else
1461// \\ GE_GREATER1461 \\ GE_GREATER
1462// \\ else if (aInt > bInt)1462 \\ else if (aInt > bInt)
1463// \\ GE_LESS1463 \\ GE_LESS
1464// \\ else if (aInt == bInt)1464 \\ else if (aInt == bInt)
1465// \\ GE_EQUAL1465 \\ GE_EQUAL
1466// \\ else1466 \\ else
1467// \\ GE_GREATER;1467 \\ GE_GREATER;
1468// \\}1468 \\}
1469// \\1469 \\
1470// );1470 );
1471//}1471}
14721472
1473test "zig fmt: respect line breaks in if-else" {1473test "zig fmt: respect line breaks in if-else" {
1474 try testCanonical(1474 try testCanonical(
lib/std/zig/render.zig+9-1
...@@ -984,7 +984,8 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa...@@ -984,7 +984,8 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa
984 try renderToken(ais, tree, while_node.ast.while_token + 1, .none); // (984 try renderToken(ais, tree, while_node.ast.while_token + 1, .none); // (
985 try renderExpression(ais, tree, while_node.ast.cond_expr, .none); // condition985 try renderExpression(ais, tree, while_node.ast.cond_expr, .none); // condition
986986
987 if (nodeIsBlock(node_tags[while_node.ast.then_expr])) {987 const then_tag = node_tags[while_node.ast.then_expr];
988 if (nodeIsBlock(then_tag) and !nodeIsIf(then_tag)) {
988 if (while_node.payload_token) |payload_token| {989 if (while_node.payload_token) |payload_token| {
989 try renderToken(ais, tree, payload_token - 2, .space); // )990 try renderToken(ais, tree, payload_token - 2, .space); // )
990 try renderToken(ais, tree, payload_token - 1, .none); // |991 try renderToken(ais, tree, payload_token - 1, .none); // |
...@@ -2128,6 +2129,13 @@ fn nodeIsBlock(tag: ast.Node.Tag) bool {...@@ -2128,6 +2129,13 @@ fn nodeIsBlock(tag: ast.Node.Tag) bool {
2128 };2129 };
2129}2130}
21302131
2132fn nodeIsIf(tag: ast.Node.Tag) bool {
2133 return switch (tag) {
2134 .@"if", .if_simple => true,
2135 else => false,
2136 };
2137}
2138
2131fn nodeCausesSliceOpSpace(tag: ast.Node.Tag) bool {2139fn nodeCausesSliceOpSpace(tag: ast.Node.Tag) bool {
2132 return switch (tag) {2140 return switch (tag) {
2133 .@"catch",2141 .@"catch",