authorgravatar for hong@hspak.comHong Shick Pak <hong@hspak.com> 2019-08-29 21:10:26-07:00
committergravatar for hong@hspak.comHong Shick Pak <hong@hspak.com> 2019-08-29 21:10:26-07:00
log9f4d44bc491b907dbe11fbc8cd70749606b2236c
treef66e78d87e9e620dcc41d9e6a5955d4c0a5c6c70
parent10541c8fc88875cb51df0a5fdeda20847133e676

zig fmt: fix nested if


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" {
482482 );
483483}
484484
485test "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
485506test "zig fmt: respect line breaks in if-else" {
486507 try testCanonical(
487508 \\comptime {
std/zig/render.zig+4-1
......@@ -1521,9 +1521,12 @@ fn renderExpression(
15211521
15221522 try renderExpression(allocator, stream, tree, indent, start_col, if_node.condition, Space.None); // condition
15231523
1524 const body_is_if_block = if_node.body.id == ast.Node.Id.If;
15241525 const body_is_block = nodeIsBlock(if_node.body);
15251526
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) {
15271530 const after_rparen_space = if (if_node.payload == null) Space.BlockStart else Space.Space;
15281531 try renderToken(tree, stream, rparen, indent, start_col, after_rparen_space); // )
15291532