| author | |
| committer | |
| log | f6d83ba9185dd81106c731e12ab361685fa226c4 |
| tree | a2b3876e81fefaa17b3a3e6b9df2a3da5e621167 |
| parent | 24400d5882aa2b83a4aed3e4c1503d0393e1c541 |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 42 insertions(+), 4 deletions(-)
std/zig/parser_test.zig+38| ... | ... | @@ -2234,6 +2234,44 @@ test "zig fmt: multiline string in array" { |
| 2234 | 2234 | ); |
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | test "zig fmt: line comment in array" { | |
| 2238 | try testTransform( | |
| 2239 | \\test "a" { | |
| 2240 | \\ var arr = [_]u32{ | |
| 2241 | \\ 0 | |
| 2242 | \\ // 1, | |
| 2243 | \\ // 2, | |
| 2244 | \\ }; | |
| 2245 | \\} | |
| 2246 | \\ | |
| 2247 | , | |
| 2248 | \\test "a" { | |
| 2249 | \\ var arr = [_]u32{ | |
| 2250 | \\ 0, // 1, | |
| 2251 | \\ // 2, | |
| 2252 | \\ }; | |
| 2253 | \\} | |
| 2254 | \\ | |
| 2255 | ); | |
| 2256 | } | |
| 2257 | ||
| 2258 | test "zig fmt: comment after params" { | |
| 2259 | try testTransform( | |
| 2260 | \\fn a( | |
| 2261 | \\ b: u32 | |
| 2262 | \\ // c: u32, | |
| 2263 | \\ // d: u32, | |
| 2264 | \\) void {} | |
| 2265 | \\ | |
| 2266 | , | |
| 2267 | \\fn a( | |
| 2268 | \\ b: u32, // c: u32, | |
| 2269 | \\ // d: u32, | |
| 2270 | \\) void {} | |
| 2271 | \\ | |
| 2272 | ); | |
| 2273 | } | |
| 2274 | ||
| 2237 | 2275 | const std = @import("std"); |
| 2238 | 2276 | const mem = std.mem; |
| 2239 | 2277 | const warn = std.debug.warn; |
std/zig/render.zig+4-4| ... | ... | @@ -658,7 +658,7 @@ fn renderExpression( |
| 658 | 658 | try renderToken(tree, stream, lbrace, indent, start_col, Space.None); |
| 659 | 659 | return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space); |
| 660 | 660 | } |
| 661 | if (exprs.len == 1) { | |
| 661 | if (exprs.len == 1 and tree.tokens.at(exprs.at(0).*.lastToken() + 1).id == .RBrace) { | |
| 662 | 662 | const expr = exprs.at(0).*; |
| 663 | 663 | |
| 664 | 664 | try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None); |
| ... | ... | @@ -719,7 +719,7 @@ fn renderExpression( |
| 719 | 719 | while (it.next()) |expr| : (i += 1) { |
| 720 | 720 | counting_stream.bytes_written = 0; |
| 721 | 721 | var dummy_col: usize = 0; |
| 722 | try renderExpression(allocator, &counting_stream.stream, tree, 0, &dummy_col, expr.*, Space.None); | |
| 722 | try renderExpression(allocator, &counting_stream.stream, tree, indent, &dummy_col, expr.*, Space.None); | |
| 723 | 723 | const width = @intCast(usize, counting_stream.bytes_written); |
| 724 | 724 | const col = i % row_size; |
| 725 | 725 | column_widths[col] = std.math.max(column_widths[col], width); |
| ... | ... | @@ -1139,8 +1139,8 @@ fn renderExpression( |
| 1139 | 1139 | }); |
| 1140 | 1140 | |
| 1141 | 1141 | const src_params_trailing_comma = blk: { |
| 1142 | const maybe_comma = tree.prevToken(rparen); | |
| 1143 | break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma; | |
| 1142 | const maybe_comma = tree.tokens.at(rparen - 1).id; | |
| 1143 | break :blk maybe_comma == .Comma or maybe_comma == .LineComment; | |
| 1144 | 1144 | }; |
| 1145 | 1145 | |
| 1146 | 1146 | if (!src_params_trailing_comma) { |