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" {...@@ -1410,31 +1410,31 @@ test "zig fmt: if condition wraps" {
1410 \\1410 \\
1411 );1411 );
1412}1412}
1413//1413
1414//test "zig fmt: if condition has line break but must not wrap" {1414test "zig fmt: if condition has line break but must not wrap" {
1415// try testCanonical(1415 try testCanonical(
1416// \\comptime {1416 \\comptime {
1417// \\ if (self.user_input_options.put(1417 \\ if (self.user_input_options.put(
1418// \\ name,1418 \\ name,
1419// \\ UserInputOption{1419 \\ UserInputOption{
1420// \\ .name = name,1420 \\ .name = name,
1421// \\ .used = false,1421 \\ .used = false,
1422// \\ },1422 \\ },
1423// \\ ) catch unreachable) |*prev_value| {1423 \\ ) catch unreachable) |*prev_value| {
1424// \\ foo();1424 \\ foo();
1425// \\ bar();1425 \\ bar();
1426// \\ }1426 \\ }
1427// \\ if (put(1427 \\ if (put(
1428// \\ a,1428 \\ a,
1429// \\ b,1429 \\ b,
1430// \\ )) {1430 \\ )) {
1431// \\ foo();1431 \\ foo();
1432// \\ }1432 \\ }
1433// \\}1433 \\}
1434// \\1434 \\
1435// );1435 );
1436//}1436}
1437//1437
1438//test "zig fmt: if condition has line break but must not wrap" {1438//test "zig fmt: if condition has line break but must not wrap" {
1439// try testCanonical(1439// try testCanonical(
1440// \\comptime {1440// \\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...@@ -1006,13 +1006,11 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa
1006 break :blk ident + 1;1006 break :blk ident + 1;
1007 }1007 }
1008 };1008 };
1009 const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, pipe);1009 const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
1010 const brace_space: Space = if (cond_has_newline) .newline else .space;
1011 try renderToken(ais, tree, pipe, brace_space); // |1010 try renderToken(ais, tree, pipe, brace_space); // |
1012 } else {1011 } else {
1013 const rparen = tree.lastToken(while_node.ast.cond_expr) + 1;1012 const rparen = tree.lastToken(while_node.ast.cond_expr) + 1;
1014 const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, rparen);1013 const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space;
1015 const brace_space: Space = if (cond_has_newline) .newline else .space;
1016 try renderToken(ais, tree, rparen, brace_space); // rparen1014 try renderToken(ais, tree, rparen, brace_space); // rparen
1017 }1015 }
1018 if (while_node.ast.cont_expr != 0) {1016 if (while_node.ast.cont_expr != 0) {