| author | |
| committer | |
| log | fa6449dac06435175bee6113a0676ef2d43d777c |
| tree | 5daa08b68b8294a108cfa1edb8e997524cade8f1 |
| parent | 64a590a31194a778b494937e2f91642b80e3f4d0 |
Resetting `column_counter` is not needed as the effective column number
is calculated by taking that value modulo `row_size`.
Closes #72892 files changed, 25 insertions(+), 7 deletions(-)
lib/std/zig/parser_test.zig+19-1| ... | @@ -286,7 +286,7 @@ test "zig fmt: respect line breaks after var declarations" { | ... | @@ -286,7 +286,7 @@ test "zig fmt: respect line breaks after var declarations" { |
| 286 | \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^ | 286 | \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^ |
| 287 | \\ lookup_tables[7][@truncate(u8, self.crc >> 0)]; | 287 | \\ lookup_tables[7][@truncate(u8, self.crc >> 0)]; |
| 288 | \\ | 288 | \\ |
| 289 | ); | 289 | ); |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | test "zig fmt: multiline string mixed with comments" { | 292 | test "zig fmt: multiline string mixed with comments" { |
| ... | @@ -563,6 +563,24 @@ test "zig fmt: anon literal in array" { | ... | @@ -563,6 +563,24 @@ test "zig fmt: anon literal in array" { |
| 563 | ); | 563 | ); |
| 564 | } | 564 | } |
| 565 | 565 | ||
| 566 | test "zig fmt: alignment in anonymous literal" { | ||
| 567 | try testTransform( | ||
| 568 | \\const a = .{ | ||
| 569 | \\ "U", "L", "F", | ||
| 570 | \\ "U'", | ||
| 571 | \\ "L'", | ||
| 572 | \\ "F'", | ||
| 573 | \\}; | ||
| 574 | \\ | ||
| 575 | , | ||
| 576 | \\const a = .{ | ||
| 577 | \\ "U", "L", "F", | ||
| 578 | \\ "U'", "L'", "F'", | ||
| 579 | \\}; | ||
| 580 | \\ | ||
| 581 | ); | ||
| 582 | } | ||
| 583 | |||
| 566 | test "zig fmt: anon struct literal syntax" { | 584 | test "zig fmt: anon struct literal syntax" { |
| 567 | try testCanonical( | 585 | try testCanonical( |
| 568 | \\const x = .{ | 586 | \\const x = .{ |
lib/std/zig/render.zig+6-6| ... | @@ -813,12 +813,10 @@ fn renderExpression( | ... | @@ -813,12 +813,10 @@ fn renderExpression( |
| 813 | const expr_last_token = expr.*.lastToken() + 1; | 813 | const expr_last_token = expr.*.lastToken() + 1; |
| 814 | const next_expr = section_exprs[i + 1]; | 814 | const next_expr = section_exprs[i + 1]; |
| 815 | const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, next_expr.*.firstToken()); | 815 | const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, next_expr.*.firstToken()); |
| 816 | if (loc.line == 0) { | 816 | |
| 817 | column_counter += 1; | 817 | column_counter += 1; |
| 818 | } else { | 818 | |
| 819 | single_line = false; | 819 | if (loc.line != 0) single_line = false; |
| 820 | column_counter = 0; | ||
| 821 | } | ||
| 822 | } else { | 820 | } else { |
| 823 | single_line = false; | 821 | single_line = false; |
| 824 | column_counter = 0; | 822 | column_counter = 0; |
| ... | @@ -2655,6 +2653,8 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo | ... | @@ -2655,6 +2653,8 @@ fn copyFixingWhitespace(ais: anytype, slice: []const u8) @TypeOf(ais.*).Error!vo |
| 2655 | }; | 2653 | }; |
| 2656 | } | 2654 | } |
| 2657 | 2655 | ||
| 2656 | // Returns the number of nodes in `expr` that are on the same line as `rtoken`, | ||
| 2657 | // or null if they all are on the same line. | ||
| 2658 | fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize { | 2658 | fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize { |
| 2659 | const first_token = exprs[0].firstToken(); | 2659 | const first_token = exprs[0].firstToken(); |
| 2660 | const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken); | 2660 | const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken); |