mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
zig fmt: if nested
This commit is contained in:
parent
a17a5ca3a8
commit
621ad241d6
@ -1449,26 +1449,26 @@ 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: 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(
|
||||
|
||||
@ -984,7 +984,8 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa
|
||||
try renderToken(ais, tree, while_node.ast.while_token + 1, .none); // (
|
||||
try renderExpression(ais, tree, while_node.ast.cond_expr, .none); // condition
|
||||
|
||||
if (nodeIsBlock(node_tags[while_node.ast.then_expr])) {
|
||||
const then_tag = node_tags[while_node.ast.then_expr];
|
||||
if (nodeIsBlock(then_tag) and !nodeIsIf(then_tag)) {
|
||||
if (while_node.payload_token) |payload_token| {
|
||||
try renderToken(ais, tree, payload_token - 2, .space); // )
|
||||
try renderToken(ais, tree, payload_token - 1, .none); // |
|
||||
@ -2128,6 +2129,13 @@ fn nodeIsBlock(tag: ast.Node.Tag) bool {
|
||||
};
|
||||
}
|
||||
|
||||
fn nodeIsIf(tag: ast.Node.Tag) bool {
|
||||
return switch (tag) {
|
||||
.@"if", .if_simple => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
fn nodeCausesSliceOpSpace(tag: ast.Node.Tag) bool {
|
||||
return switch (tag) {
|
||||
.@"catch",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user