| author | |
| committer | |
| log | 00664dbdcea9d17617ec78c6933f627f0661f81e |
| tree | d53959843d2d1a042b965da6bd32d1f79be4d1f8 |
| parent | c9bc8b9d0cf1ca7d21ddb60d08a4cdd0730a253d |
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 | 286 | \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^ |
| 287 | 287 | \\ lookup_tables[7][@truncate(u8, self.crc >> 0)]; |
| 288 | 288 | \\ |
| 289 | ); | |
| 289 | ); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | test "zig fmt: multiline string mixed with comments" { |
| ... | ... | @@ -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 | 584 | test "zig fmt: anon struct literal syntax" { |
| 567 | 585 | try testCanonical( |
| 568 | 586 | \\const x = .{ |
lib/std/zig/render.zig+6-6| ... | ... | @@ -813,12 +813,10 @@ fn renderExpression( |
| 813 | 813 | const expr_last_token = expr.*.lastToken() + 1; |
| 814 | 814 | const next_expr = section_exprs[i + 1]; |
| 815 | 815 | const loc = tree.tokenLocation(tree.token_locs[expr_last_token].start, next_expr.*.firstToken()); |
| 816 | if (loc.line == 0) { | |
| 817 | column_counter += 1; | |
| 818 | } else { | |
| 819 | single_line = false; | |
| 820 | column_counter = 0; | |
| 821 | } | |
| 816 | ||
| 817 | column_counter += 1; | |
| 818 | ||
| 819 | if (loc.line != 0) single_line = false; | |
| 822 | 820 | } else { |
| 823 | 821 | single_line = false; |
| 824 | 822 | column_counter = 0; |
| ... | ... | @@ -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 | 2658 | fn rowSize(tree: *ast.Tree, exprs: []*ast.Node, rtoken: ast.TokenIndex) ?usize { |
| 2659 | 2659 | const first_token = exprs[0].firstToken(); |
| 2660 | 2660 | const first_loc = tree.tokenLocation(tree.token_locs[first_token].start, rtoken); |