| author | |
| committer | |
| log | 9f4d44bc491b907dbe11fbc8cd70749606b2236c |
| tree | f66e78d87e9e620dcc41d9e6a5955d4c0a5c6c70 |
| parent | 10541c8fc88875cb51df0a5fdeda20847133e676 |
2 files changed, 25 insertions(+), 1 deletions(-)
std/zig/parser_test.zig+21| ... | @@ -482,6 +482,27 @@ test "zig fmt: if-else with comment before else" { | ... | @@ -482,6 +482,27 @@ test "zig fmt: if-else with comment before else" { |
| 482 | ); | 482 | ); |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | test "zig fmt: if nested" { | ||
| 486 | try testCanonical( | ||
| 487 | \\pub fn foo() void { | ||
| 488 | \\ return if ((aInt & bInt) >= 0) | ||
| 489 | \\ if (aInt < bInt) | ||
| 490 | \\ GE_LESS | ||
| 491 | \\ else if (aInt == bInt) | ||
| 492 | \\ GE_EQUAL | ||
| 493 | \\ else | ||
| 494 | \\ GE_GREATER | ||
| 495 | \\ else if (aInt > bInt) | ||
| 496 | \\ GE_LESS | ||
| 497 | \\ else if (aInt == bInt) | ||
| 498 | \\ GE_EQUAL | ||
| 499 | \\ else | ||
| 500 | \\ GE_GREATER; | ||
| 501 | \\} | ||
| 502 | \\ | ||
| 503 | ); | ||
| 504 | } | ||
| 505 | |||
| 485 | test "zig fmt: respect line breaks in if-else" { | 506 | test "zig fmt: respect line breaks in if-else" { |
| 486 | try testCanonical( | 507 | try testCanonical( |
| 487 | \\comptime { | 508 | \\comptime { |
std/zig/render.zig+4-1| ... | @@ -1521,9 +1521,12 @@ fn renderExpression( | ... | @@ -1521,9 +1521,12 @@ fn renderExpression( |
| 1521 | 1521 | ||
| 1522 | try renderExpression(allocator, stream, tree, indent, start_col, if_node.condition, Space.None); // condition | 1522 | try renderExpression(allocator, stream, tree, indent, start_col, if_node.condition, Space.None); // condition |
| 1523 | 1523 | ||
| 1524 | const body_is_if_block = if_node.body.id == ast.Node.Id.If; | ||
| 1524 | const body_is_block = nodeIsBlock(if_node.body); | 1525 | const body_is_block = nodeIsBlock(if_node.body); |
| 1525 | 1526 | ||
| 1526 | if (body_is_block) { | 1527 | if (body_is_if_block) { |
| 1528 | try renderExtraNewline(tree, stream, start_col, if_node.body); | ||
| 1529 | } else if (body_is_block) { | ||
| 1527 | const after_rparen_space = if (if_node.payload == null) Space.BlockStart else Space.Space; | 1530 | const after_rparen_space = if (if_node.payload == null) Space.BlockStart else Space.Space; |
| 1528 | try renderToken(tree, stream, rparen, indent, start_col, after_rparen_space); // ) | 1531 | try renderToken(tree, stream, rparen, indent, start_col, after_rparen_space); // ) |
| 1529 | 1532 |