diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-22 16:39:50 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-22 16:39:50 -0700 |
| commit | ec987a7a4652a0dbbd214e0252f35214532a9493 (patch) | |
| tree | 88b03afe39db736ff08e3608e84c23960902397e /lib/std | |
| parent | b301999cd3e3d070f5d62a9d3da2a736b7026b30 (diff) | |
| download | zig-ec987a7a4652a0dbbd214e0252f35214532a9493.tar.gz zig-ec987a7a4652a0dbbd214e0252f35214532a9493.zip | |
zig fmt: if condition has line break but must not wrap
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 50 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 6 |
2 files changed, 27 insertions, 29 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index ee18fc6c9a..0df9a16bc2 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1410,31 +1410,31 @@ test "zig fmt: if condition wraps" { \\ ); } -// -//test "zig fmt: if condition has line break but must not wrap" { -// try testCanonical( -// \\comptime { -// \\ if (self.user_input_options.put( -// \\ name, -// \\ UserInputOption{ -// \\ .name = name, -// \\ .used = false, -// \\ }, -// \\ ) catch unreachable) |*prev_value| { -// \\ foo(); -// \\ bar(); -// \\ } -// \\ if (put( -// \\ a, -// \\ b, -// \\ )) { -// \\ foo(); -// \\ } -// \\} -// \\ -// ); -//} -// + +test "zig fmt: if condition has line break but must not wrap" { + try testCanonical( + \\comptime { + \\ if (self.user_input_options.put( + \\ name, + \\ UserInputOption{ + \\ .name = name, + \\ .used = false, + \\ }, + \\ ) catch unreachable) |*prev_value| { + \\ foo(); + \\ bar(); + \\ } + \\ if (put( + \\ a, + \\ b, + \\ )) { + \\ foo(); + \\ } + \\} + \\ + ); +} + //test "zig fmt: if condition has line break but must not wrap" { // try testCanonical( // \\comptime { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 06b5052fd5..a3974d7204 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1006,13 +1006,11 @@ fn renderWhile(ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Spa break :blk ident + 1; } }; - const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, pipe); - const brace_space: Space = if (cond_has_newline) .newline else .space; + const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space; try renderToken(ais, tree, pipe, brace_space); // | } else { const rparen = tree.lastToken(while_node.ast.cond_expr) + 1; - const cond_has_newline = !tree.tokensOnSameLine(while_node.ast.while_token, rparen); - const brace_space: Space = if (cond_has_newline) .newline else .space; + const brace_space: Space = if (ais.isLineOverIndented()) .newline else .space; try renderToken(ais, tree, rparen, brace_space); // rparen } if (while_node.ast.cont_expr != 0) { |
