mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
zig fmt: fix nested if
This commit is contained in:
parent
10541c8fc8
commit
9f4d44bc49
@ -482,6 +482,27 @@ test "zig fmt: if-else with comment before else" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: if nested" {
|
||||
try testCanonical(
|
||||
\\pub fn foo() void {
|
||||
\\ return if ((aInt & bInt) >= 0)
|
||||
\\ if (aInt < bInt)
|
||||
\\ GE_LESS
|
||||
\\ else if (aInt == bInt)
|
||||
\\ GE_EQUAL
|
||||
\\ else
|
||||
\\ GE_GREATER
|
||||
\\ else if (aInt > bInt)
|
||||
\\ GE_LESS
|
||||
\\ else if (aInt == bInt)
|
||||
\\ GE_EQUAL
|
||||
\\ else
|
||||
\\ GE_GREATER;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: respect line breaks in if-else" {
|
||||
try testCanonical(
|
||||
\\comptime {
|
||||
|
||||
@ -1521,9 +1521,12 @@ fn renderExpression(
|
||||
|
||||
try renderExpression(allocator, stream, tree, indent, start_col, if_node.condition, Space.None); // condition
|
||||
|
||||
const body_is_if_block = if_node.body.id == ast.Node.Id.If;
|
||||
const body_is_block = nodeIsBlock(if_node.body);
|
||||
|
||||
if (body_is_block) {
|
||||
if (body_is_if_block) {
|
||||
try renderExtraNewline(tree, stream, start_col, if_node.body);
|
||||
} else if (body_is_block) {
|
||||
const after_rparen_space = if (if_node.payload == null) Space.BlockStart else Space.Space;
|
||||
try renderToken(tree, stream, rparen, indent, start_col, after_rparen_space); // )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user