authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 16:39:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 16:39:50-07:00
logec987a7a4652a0dbbd214e0252f35214532a9493
tree88b03afe39db736ff08e3608e84c23960902397e
parentb301999cd3e3d070f5d62a9d3da2a736b7026b30

zig fmt: if condition has line break but must not wrap


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

lib/std/zig/parser_test.zig+25-25
......@@ -1410,31 +1410,31 @@ test "zig fmt: if condition wraps" {
14101410 \\
14111411 );
14121412}
1413//
1414//test "zig fmt: if condition has line break but must not wrap" {
1415// try testCanonical(
1416// \\comptime {
1417// \\ if (self.user_input_options.put(
1418// \\ name,
1419// \\ UserInputOption{
1420// \\ .name = name,
1421// \\ .used = false,
1422// \\ },
1423// \\ ) catch unreachable) |*prev_value| {
1424// \\ foo();
1425// \\ bar();
1426// \\ }
1427// \\ if (put(
1428// \\ a,
1429// \\ b,
1430// \\ )) {
1431// \\ foo();
1432// \\ }
1433// \\}
1434// \\
1435// );
1436//}
1437//
1413
1414test "zig fmt: if condition has line break but must not wrap" {
1415 try testCanonical(
1416 \\comptime {
1417 \\ if (self.user_input_options.put(
1418 \\ name,
1419 \\ UserInputOption{
1420 \\ .name = name,
1421 \\ .used = false,
1422 \\ },
1423 \\ ) catch unreachable) |*prev_value| {
1424 \\ foo();
1425 \\ bar();
1426 \\ }
1427 \\ if (put(
1428 \\ a,
1429 \\ b,
1430 \\ )) {
1431 \\ foo();
1432 \\ }
1433 \\}
1434 \\
1435 );
1436}
1437
14381438//test "zig fmt: if condition has line break but must not wrap" {
14391439// try testCanonical(
14401440// \\comptime {
lib/std/zig/render.zig+2-4
......@@ -1006,13 +1006,11 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa
10061006 break :blk ident + 1;
10071007 }
10081008 };
1009 const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, pipe);
1010 const brace_space: Space = if (cond_has_newline) .newline else .space;
1009 const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
10111010 try renderToken(ais, tree, pipe, brace_space); // |
10121011 } else {
10131012 const rparen = tree.lastToken(while_node.ast.cond_expr) + 1;
1014 const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, rparen);
1015 const brace_space: Space = if (cond_has_newline) .newline else .space;
1013 const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
10161014 try renderToken(ais, tree, rparen, brace_space); // rparen
10171015 }
10181016 if (while_node.ast.cont_expr != 0) {